summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Fix readability-identifier-naming missing member variablesNathan James2020-01-131-6/+26
| | | | | Fixes PR41122 (missing fixes for member variables in a destructor) and PR29005 (does not rename class members in all locations).
* [NFC] Fixes -Wrange-loop-analysis warningsMark de Wever2020-01-011-1/+1
| | | | | | This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71857
* [clang-tidy] Use early returns to make the code easier to read and ↵Alexander Kornienko2019-12-121-6/+5
| | | | potentially run faster
* Fix readability-identifier-naming to prevent variables becoming keywords.Daniel2019-10-301-20/+42
| | | | | Do not provide a fix-it when clang-tidy encounters a name that would become a keyword.
* Use std::unique_ptr in ClangTidyCheckFactoriesDmitri Gribenko2019-09-261-0/+2
| | | | | | | I had to explicitly define some destructors that could only be defined in the corresponding .cpp files. llvm-svn: 372978
* [clang-tidy] readability-identifier-naming shouldn't complain about CRTP ↵Sam McCall2019-08-281-0/+10
| | | | | | | | | | | | | | pseudo-overrides Reviewers: ilya-biryukov Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66864 llvm-svn: 370193
* [clang-tools-extra] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-141-1/+1
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368944
* [clang-tidy] Fix null pointer dereference in readability-identifier-namingHaojian Wu2019-05-281-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | Summary: readability-identifier-naming causes a null pointer dereference when checking an identifier introduced by a structured binding whose right hand side is an undeclared identifier. Running the check on a file that is just the following results in a crash: ``` auto [left] = right; ``` Patch by Mark Stegeman! Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: hokein, aaron.ballman Subscribers: madsravn, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D62404 llvm-svn: 361809
* [clang-tidy] Expand modular headers for PPCallbacksAlexander Kornienko2019-03-221-4/+5
| | | | | | | | | | | | | | | | | | | | | | Summary: Add a way to expand modular headers for PPCallbacks. Checks can opt-in for this expansion by overriding the new registerPPCallbacks virtual method and registering their PPCallbacks in the preprocessor created for this specific purpose. Use module expansion in the readability-identifier-naming check Reviewers: gribozavr, usaxena95, sammccall Reviewed By: gribozavr Subscribers: nemanjai, mgorny, xazax.hun, kbarton, jdoerfert, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59528 llvm-svn: 356750
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [clang-tidy] Re-commit: Add new 'readability-uppercase-literal-suffix' check ↵Roman Lebedev2018-10-261-19/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (CERT DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4) Summary: Detects when the integral literal or floating point (decimal or hexadecimal) literal has non-uppercase suffix, and suggests to make the suffix uppercase, with fix-it. All valid combinations of suffixes are supported. ``` auto x = 1; // OK, no suffix. auto x = 1u; // warning: integer literal suffix 'u' is not upper-case auto x = 1U; // OK, suffix is uppercase. ... ``` This is a re-commit, the original was reverted by me in rL345305 due to discovered bugs. (implicit code, template instantiation) Tests were added, and the bugs were fixed. I'm unable to find any further bugs, hopefully there aren't any.. References: * [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]] * MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix * MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52670 llvm-svn: 345381
* [clang-tidy] Revert my readability-uppercase-literal-suffix check.Roman Lebedev2018-10-251-2/+19
| | | | | | | | | | There are some lurking issues with the handling of the SourceManager. Somehow sometimes we end up extracting completely wrong portions of the source buffer. Reverts r344772, r44760, r344758, r344755. llvm-svn: 345305
* [clang-tidy] Add new 'readability-uppercase-literal-suffix' check (CERT ↵Roman Lebedev2018-10-181-19/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | DCL16-C, MISRA C:2012, 7.3, MISRA C++:2008, 2-13-4) Summary: Detects when the integral literal or floating point (decimal or hexadecimal) literal has non-uppercase suffix, and suggests to make the suffix uppercase, with fix-it. All valid combinations of suffixes are supported. ``` auto x = 1; // OK, no suffix. auto x = 1u; // warning: integer literal suffix 'u' is not upper-case auto x = 1U; // OK, suffix is uppercase. ... ``` References: * [[ https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152241 | CERT DCL16-C ]] * MISRA C:2012, 7.3 - The lowercase character "l" shall not be used in a literal suffix * MISRA C++:2008, 2-13-4 - Literal suffixes shall be upper case Reviewers: JonasToth, aaron.ballman, alexfh, hokein, xazax.hun Reviewed By: aaron.ballman Subscribers: Eugene.Zelenko, mgorny, rnkovacs, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D52670 llvm-svn: 344755
* [clang-tidy] Added pointer types to clang-tidy readability-identifier-naming ↵Jonas Toth2018-10-041-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | check. Summary: Option to check for different naming conventions on the following types: - GlobalConstantPointer - GlobalPointer - LocalConstantPointer - LocalPointer - PointerParameter - ConstantPointerParameter When not specified, the conventions for the non pointer types will be applied (GlobalConstant, GlobalVariable, LocalConstant, ...). Patch by ffigueras! Reviewers: alexfh, kbobyrev Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D52882 llvm-svn: 343788
* [clang-tidy] Replace redundant checks with an assert().Artem Belevich2018-09-181-2/+3
| | | | | | | | | | findStyleKind is only called if D is an explicit identifier with a name, so the checks for operators will never return true. The explicit assert() enforces this invariant. Differential Revision: https://reviews.llvm.org/D52179 llvm-svn: 342514
* Port getLocStart -> getBeginLocStephen Kelly2018-08-091-1/+1
| | | | | | | | | | Reviewers: javed.absar Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50354 llvm-svn: 339400
* [clang-tools-extra] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen2018-05-151-8/+8
| | | | | | | | | | | The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Differential Revision: https://reviews.llvm.org/D44976 llvm-svn: 332371
* update test to use ivar in implementation instead of class extensionYan Zhang2018-04-231-0/+4
| | | | | | | | | | | | | | Summary: using ivar in class extension is not supported in 32-bit architecture of MacOS. Reviewers: alexfh, hokein Reviewed By: alexfh Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D45912 llvm-svn: 330559
* Revert r330492: [clang-tidy] add new check to find out objc ivars which do ↵Chandler Carruth2018-04-211-4/+0
| | | | | | | | | | not have prefix '_' This commit has been breaking most bots for a day now. There is a fix proposed in https://reviews.llvm.org/D45912 but when I applied that I just got different errors. Reverting to get our bots back to green. llvm-svn: 330528
* [clang-tidy] add new check to find out objc ivars which do not have prefix '_'Yan Zhang2018-04-201-0/+4
| | | | | | | | | | | | | | | | | | | | | | | Summary: For code of ivar declaration: int barWithoutPrefix; The fix will be: int _barWithoutPrefix; Reviewers: benhamilton, hokein, alexfh, aaron.ballman, ilya-biryukov Reviewed By: alexfh Subscribers: Eugene.Zelenko, xazax.hun, klimek, mgorny, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D45392 llvm-svn: 330492
* [clang-tidy] Correctly classify constant arrays and constant strings as ↵Alexander Kornienko2017-12-111-33/+31
| | | | | | | | | | | | | | | | | | | | constants when checking identifiers naming Summary: They are not locally const qualified so they weren't classified as constants by the readability-identifier-naming check. Reviewers: alexfh Reviewed By: alexfh Subscribers: klimek, cfe-commits, xazax.hun Patch by Beren Minor! Differential Revision: https://reviews.llvm.org/D39363 llvm-svn: 320406
* [clang-tidy] Update IdentifierNamingCheck to remove extra leading/trailing ↵Alexander Kornienko2017-04-261-4/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-tidy] clang-format the last patch. NFCAlexander Kornienko2017-03-221-21/+13
| | | | llvm-svn: 298500
* [clang-tidy] modified identifier naming case to use CT_AnyCase for ignoring ↵Alexander Kornienko2017-03-221-74/+98
| | | | | | | | | | | | | | | | | | | | | case style Summary: Using CaseType::CT_AnyCase for selected identifier results in inheriting case style setting from more basic identifier type. This patch changes CT_AnyCase behavior to ignore case style of specified identifier. If case style was not set, llvm::Optional will be used for keeping this information (llvm::Optional<>::hasVal), thus CT_AnyCase will no longer mean more general identifier style should be used. This eliminates false-positives when naming convention is not clear for specific areas of code (legacy, third party) or for selected types. Reviewers: berenm, alexfh Reviewed By: alexfh Subscribers: cfe-commits, JDevlieghere Differential Revision: https://reviews.llvm.org/D30931 llvm-svn: 298499
* Apply clang-tidy's performance-unnecessary-value-param to clang-tidy.Benjamin Kramer2017-03-211-1/+1
| | | | | | No functionality change intended. llvm-svn: 298442
* [clang-tidy] Fix identifier naming for initializer list member initializers.Eric Fiselier2016-11-161-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch adds handling for member initializers in a constructors initializer list. Previously we only handled base-class and delegating initializers, which are transformed by the `TypeLoc` matcher. For Example: ``` // Style options: All identifiers should start with an upper case letter. struct base { ... }; struct der : base { int field; // FIXES: int Field; der() : der(42) {} // FIXES: Der() : Der(42) {} der(int X) : base(), field(X) {} // FIXES: Der(int X) : Base(), field(X) // Note that `field` doesn't get replaced }; ``` Reviewers: alexfh, hokein, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26744 llvm-svn: 287153
* [clang-tools-extra] Format sources with clang-format. NFC.Mandeep Singh Grang2016-11-081-5/+7
| | | | | | | | | | | | | | | | Summary: Ran clang-format on all .c/.cpp/.h files in clang-tools-extra. Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories. Reviewers: klimek, alexfh Subscribers: nemanjai Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D26329 llvm-svn: 286221
* [clang-tidy] Ignore forward declarations without definitions in the same ↵Jonathan Coe2016-11-031-0/+3
| | | | | | | | | | | | | | translation unit in readability-identifier-naming Summary: This change ensures that forward declarations of classes are not considered for identifier naming checks within a translation unit. Reviewers: alexfh, aaron.ballman Subscribers: mgehre Differential Revision: https://reviews.llvm.org/D22571 llvm-svn: 285907
* [clang-tidy] Fix identifier naming in macro args.Jason Henline2016-10-241-7/+37
| | | | | | | | | | | | | | | | | | | | | | Summary: clang-tidy should fix identifier naming even when the identifier is referenced inside a macro expansion, provided that the identifier enters the macro expansion completely within a macro argument. For example, this will allow fixes to the naming of the identifier 'global' when it is declared and used as follows: int global; #define USE_IN_MACRO(m) auto use_##m = m USE_IN_MACRO(global); Reviewers: alexfh Subscribers: jlebar, cfe-commits Differential Revision: https://reviews.llvm.org/D25450 llvm-svn: 284992
* Revert "Revert "Add a static_assert to enforce that parameters to ↵Mehdi Amini2016-10-071-2/+2
| | | | | | | | | llvm::format() are not totally unsafe"" This reverts commit r283510 and reapply r283509, with updates to clang-tools-extra as well. llvm-svn: 283525
* Sorting includes; NFC.Aaron Ballman2016-07-291-1/+1
| | | | llvm-svn: 277217
* [clang-tidy] readability-identifier-naming - support for other case typesKirill Bobyrev2016-07-201-0/+29
| | | | | | | | | | | | | | | | | | | Added Camel_Snake_Case and camel_Snake_Back class Camel_Snake_Case_Class_Name { void private_Camel_Snake_Back_Method_Name(); } Patch by James Reynolds! Reviewers: alexfh Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21472 llvm-svn: 276110
* clang-tidy/readability-identifier-naming: crash on ↵Matthias Gehre2016-07-091-3/+4
| | | | | | | | | | | | | | | | DependentTemplateSpecializationType Summary: Previously, the added test cases crashed because the passed a null Decl to addUsage(). Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D22188 llvm-svn: 274985
* [clang-tidy] readability-identifier-naming - Support for MacrosAlexander Kornienko2016-06-171-20/+171
| | | | | | | | | | | | | | | | | | | | | Summary: Added support for macro definitions. -- 1. Added a pre-processor callback to catch macro definitions 2. Changed the type of the failure map so that macros and declarations can share the same map 3. Added extra tests to ensure fix-ups work using the new map 4. Added fix-ups for type aliases in variable and function declarations as part of adding the new tests Reviewers: alexfh Subscribers: Eugene.Zelenko, cfe-commits Patch by James Reynolds! Differential Revision: http://reviews.llvm.org/D21020 llvm-svn: 272993
* [clang-tidy] readability-identifier-naming - Support for Type AliasesAlexander Kornienko2016-06-071-0/+4
| | | | | | | | | | | | | | Summary: Added support for Type Alias declarations. Reviewers: alexfh Subscribers: cfe-commits Patch by James Reynolds! Differential Revision: http://reviews.llvm.org/D20856 llvm-svn: 271992
* IdentifierNamingCheck.cpp: try to fix MSVC buildHans Wennborg2016-02-291-4/+4
| | | | | | | | | It was failing to build with: clang-tidy\readability\IdentifierNamingCheck.cpp(640): error C2882: 'format' : illegal use of namespace identifier in expression llvm-svn: 262257
* Test commit. Fix typo in comment.Jonathan Coe2016-01-261-1/+1
| | | | llvm-svn: 258835
* clang-tidy readability identifiers: better diagnostic locationMike Aizatsky2015-12-041-1/+1
| | | | | | | | | | | | Summary: With this change the error reported is on the identifier location itself. It was declaration location before. Reviewers: alexfh Differential Revision: http://reviews.llvm.org/D15203 llvm-svn: 254766
* [clang-tidy] Implement FixitHints for identifier references in ↵Alexander Kornienko2015-10-011-14/+116
| | | | | | | | | | | | | | IdentifierNamingCheck This diff requires http://reviews.llvm.org/D13079 to be applied first. I wasn't sure about how to make patch series in Phabricator, and I wanted to keep the two separate for clarity. It looks like that most cases can be supported with this patch. I'm not totally sure about the actual coverage though. I think that the matchers are very generic, but I'm still not totally fluent with the AST. Patch by Beren Minor! Differential revision: http://reviews.llvm.org/D13081 llvm-svn: 248996
* [clang-tidy] Code factorization and cleanup in IdentifierNamingCheckAlexander Kornienko2015-09-281-32/+31
| | | | | | | | | | | | | | | This is to level the ground a little bit, in preparation for the changes in http://reviews.llvm.org/D13081. Code factorization replaces all insertions to NamingCheckFailures map with a unique addUsage function that does the job. There is also no more difference between the declaration and the references to a given identifier, both cases are treated as ranges in the Usage vector. There is also a check to avoid duplicated ranges to be inserted, which sometimes triggered erroneous replacements. References can now also be added before the declaration of the identifier is actually found; this looks to be the case for example when a templated class uses its parameters to specialize its templated base class. Patch by Beren Minor! Differential revision: http://reviews.llvm.org/D13079 llvm-svn: 248700
* [clang-tidy] Add new IdentifierNaming checkAlexander Kornienko2015-08-191-0/+587
This check will try to enforce coding guidelines on the identifiers naming. It supports lower_case, UPPER_CASE, camelBack and CamelCase casing and tries to convert from one to another if a mismatch is detected. It also supports a fixed prefix and suffix that will be prepended or appended to the identifiers, regardless of the casing. Many configuration options are available, in order to be able to create different rules for different kind of identifier. In general, the rules are falling back to a more generic rule if the specific case is not configured. http://reviews.llvm.org/D10933 Patch by Beren Minor! llvm-svn: 245429
OpenPOWER on IntegriCloud