[clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores
authorAlexander Kornienko <alexfh@google.com>
Wed, 26 Apr 2017 16:39:11 +0000 (16:39 +0000)
committerAlexander Kornienko <alexfh@google.com>
Wed, 26 Apr 2017 16:39:11 +0000 (16:39 +0000)
commiteec01adde3ac789fe5e032ce34da3b2266830308
treed9e2475dc9619d34105abb8207187793965bf2ae
parenta84ae0b943bacec50f952a30461bdfa9d482ead1
[clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing underscores

Summary:
The goal of this change is to fix the following suboptimal replacements currently suggested by clang-tidy:
```
// with MemberPrefix == "_"
int __foo;  // accepted without complaint
```
```
// with MemberPrefix == "m_"
int _foo;
    ^~~~~~
    m__foo
```

I fixed this by
- updating `matchesStyle()` to reject names which have a leading underscore after a prefix has already been stripped, or a trailing underscore if a suffix has already been stripped;
- updating `fixupWithStyle()` to strip leading & trailing underscores before adding the user-defined prefix and suffix.

The replacements are now:
```
// MemberPrefix == "_"
int __foo;
    ^~~~~~
    _foo
```
```
// MemberPrefix == "m_"
int _foo;
    ^~~~~
    m_foo
```

Future improvements might elect to add .clang-tidy flags to improve what is being stripped. For instance, stripping `m_` could allow `m_foo` to be automatically replaced with `_foo`.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Patch by Jacob Bandes-Storch!

Differential Revision: https://reviews.llvm.org/D32333

llvm-svn: 301431
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/test/clang-tidy/readability-identifier-naming.cpp