llvm-project/clang-tools-extra/clang-tidy/misc
Nathan James b859c39c40
[clang-tidy] Add a Standalone diagnostics mode to clang-tidy
Adds a flag to `ClangTidyContext` that is used to indicate to checks that fixes will only be applied one at a time.
This is to indicate to checks that each fix emitted should not depend on any other fixes emitted across the translation unit.
I've currently implemented the `IncludeInserter`, `LoopConvertCheck` and `PreferMemberInitializerCheck` to use these support these modes.

Reasoning behind this is in use cases like `clangd` it's only possible to apply one fix at a time.
For include inserter checks, the include is only added once for the first diagnostic that requires it, this will result in subsequent fixes not having the included needed.

A similar issue is seen in the `PreferMemberInitializerCheck` where the `:` will only be added for the first member that needs fixing.

Fixes emitted in `StandaloneDiagsMode` will likely result in malformed code if they are applied all together, conversely fixes currently emitted may result in malformed code if they are applied one at a time.
For this reason invoking `clang-tidy` from the binary will always with `StandaloneDiagsMode` disabled, However using it as a library its possible to select the mode you wish to use, `clangd` always selects `StandaloneDiagsMode`.

This is an example of the current behaviour failing
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) {
    A = D;
    B = E; // Fix Here
  }
};
```
Incorrectly transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E), B(E) {
    A = D;
     // Fix Here
  }
};
```
In `StandaloneDiagsMode`, it gets transformed to:
```lang=c++
struct Foo {
  int A, B;
  Foo(int D, int E) : B(E) {
    A = D;
     // Fix Here
  }
};
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D97121
2022-04-16 09:53:35 +01:00
..
CMakeLists.txt Misleading bidirectional detection 2022-01-12 11:38:36 +01:00
DefinitionsInHeadersCheck.cpp [clang-tidy] Ignore variable template partial specializations in `misc-definitions-in-headers` 2022-02-14 11:38:27 +01:00
DefinitionsInHeadersCheck.h [clang-tidy] Use ; as separator for HeaderFileExtensions 2020-03-09 11:32:44 -06:00
MiscTidyModule.cpp Misleading bidirectional detection 2022-01-12 11:38:36 +01:00
MisleadingBidirectional.cpp Misleading bidirectional detection 2022-01-12 11:38:36 +01:00
MisleadingBidirectional.h Misleading bidirectional detection 2022-01-12 11:38:36 +01:00
MisleadingIdentifier.cpp Misleading unicode identifier detection pass 2021-11-10 10:21:27 +01:00
MisleadingIdentifier.h Misleading unicode identifier detection pass 2021-11-10 10:21:27 +01:00
MisplacedConstCheck.cpp Extend misc-misplaced-const to detect using declarations as well as typedef 2020-01-22 15:26:11 -05:00
MisplacedConstCheck.h
NewDeleteOverloadsCheck.cpp [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
NewDeleteOverloadsCheck.h [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
NoRecursionCheck.cpp [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
NoRecursionCheck.h [clang-tidy] misc-no-recursion: a new check 2020-02-13 23:37:53 +03:00
NonCopyableObjects.cpp
NonCopyableObjects.h
NonPrivateMemberVariablesInClassesCheck.cpp [clang-tidy] Implement storeOptions for checks missing it. 2020-06-21 19:01:11 +01:00
NonPrivateMemberVariablesInClassesCheck.h [clang-tidy] Implement storeOptions for checks missing it. 2020-06-21 19:01:11 +01:00
RedundantExpressionCheck.cpp [clang-tidy] Never consider assignments as equivalent in `misc-redundant-expression` check 2022-04-12 16:03:14 +02:00
RedundantExpressionCheck.h
StaticAssertCheck.cpp [clang-tools-extra] Rename StringRef _lower() method calls to _insensitive() 2021-06-25 00:22:01 +03:00
StaticAssertCheck.h Revert "[clang-tidy] Simplify static assert check" 2021-05-30 16:44:31 +03:00
ThrowByValueCatchByReferenceCheck.cpp [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
ThrowByValueCatchByReferenceCheck.h [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
UnconventionalAssignOperatorCheck.cpp [clang-tidy] Fix false positives involving type aliases in `misc-unconventional-assign-operator` check 2022-01-17 21:16:17 +01:00
UnconventionalAssignOperatorCheck.h [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
UniqueptrResetReleaseCheck.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
UniqueptrResetReleaseCheck.h [clang-tidy] Add <utility> include to misc-uniqueptr-reset-release 2021-04-12 23:32:15 +01:00
UnusedAliasDeclsCheck.cpp [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
UnusedAliasDeclsCheck.h [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
UnusedParametersCheck.cpp Don't trigger unused-parameter warnings on naked functions 2022-01-27 11:40:08 -05:00
UnusedParametersCheck.h
UnusedUsingDeclsCheck.cpp Reland "[AST] Add UsingType: a sugar type for types found via UsingDecl" 2021-12-20 18:03:15 +01:00
UnusedUsingDeclsCheck.h