llvm-project/clang-tools-extra/clang-tidy/cppcoreguidelines
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
..
AvoidGotoCheck.cpp [clang-tidy] Use new mapping matchers 2021-02-03 23:21:17 +00:00
AvoidGotoCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
AvoidNonConstGlobalVariablesCheck.cpp Remove false positive in AvoidNonConstGlobalVariables. 2020-04-15 14:48:06 -04:00
AvoidNonConstGlobalVariablesCheck.h Add CppCoreGuidelines I.2 "Avoid non-const global variables" check 2020-03-13 10:05:13 -04:00
CMakeLists.txt [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check 2021-09-09 13:23:38 +02:00
CppCoreGuidelinesTidyModule.cpp Remove 'IgnoreDestructors = true' from cppcoreguidelines-explicit-virtual-functions 2021-10-12 10:08:08 -04:00
InitVariablesCheck.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
InitVariablesCheck.h [clang-tidy] Refactor IncludeInserter 2020-07-27 12:48:55 +01:00
InterfacesGlobalInitCheck.cpp Remove references to the ast_type_traits namespace 2020-12-11 00:58:46 +01:00
InterfacesGlobalInitCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
MacroUsageCheck.cpp [clang-tidy] Narrow cppguidelines-macro-usage to actual constants 2022-01-19 12:28:22 -07:00
MacroUsageCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
NarrowingConversionsCheck.cpp Allow disabling integer to floating-point narrowing conversions for cppcoreguidelines-narrowing-conversions 2021-12-16 08:24:09 -05:00
NarrowingConversionsCheck.h Allow disabling integer to floating-point narrowing conversions for cppcoreguidelines-narrowing-conversions 2021-12-16 08:24:09 -05:00
NoMallocCheck.cpp [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
NoMallocCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
OwningMemoryCheck.cpp [clang] retain type sugar in auto / template argument deduction 2021-11-15 23:07:45 +01:00
OwningMemoryCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
PreferMemberInitializerCheck.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
PreferMemberInitializerCheck.h [clang-tidy] New check cppcoreguidelines-prefer-member-initializer 2020-09-21 14:42:58 +02:00
ProBoundsArrayToPointerDecayCheck.cpp Accept string literal decay in conditional operator 2022-01-11 15:05:30 -05:00
ProBoundsArrayToPointerDecayCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ProBoundsConstantArrayIndexCheck.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
ProBoundsConstantArrayIndexCheck.h [clang-tidy] Refactor IncludeInserter 2020-07-27 12:48:55 +01:00
ProBoundsPointerArithmeticCheck.cpp [clang] retain type sugar in auto / template argument deduction 2021-11-15 23:07:45 +01:00
ProBoundsPointerArithmeticCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ProTypeConstCastCheck.cpp [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
ProTypeConstCastCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ProTypeCstyleCastCheck.cpp [clang-tidy] Applied clang-tidy fixes. NFC 2021-01-29 01:01:19 +01:00
ProTypeCstyleCastCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ProTypeMemberInitCheck.cpp [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
ProTypeMemberInitCheck.h [clang-tidy] fix duplicate '{}' in cppcoreguidelines-pro-type-member-init 2021-08-14 10:48:04 +08:00
ProTypeReinterpretCastCheck.cpp [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
ProTypeReinterpretCastCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ProTypeStaticCastDowncastCheck.cpp [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
ProTypeStaticCastDowncastCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ProTypeUnionAccessCheck.cpp [clang-tidy] Change checks to use new isLanguageVersionSupported restriction 2020-03-03 16:43:45 +00:00
ProTypeUnionAccessCheck.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ProTypeVarargCheck.cpp Disable clang-tidy warnings from system macros 2022-01-06 20:27:28 +00:00
ProTypeVarargCheck.h Disable clang-tidy warnings from system macros 2022-01-06 20:27:28 +00:00
SlicingCheck.cpp [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
SlicingCheck.h [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
SpecialMemberFunctionsCheck.cpp [clang-tidy] Simplify special member functions check 2021-02-27 12:13:24 +00:00
SpecialMemberFunctionsCheck.h [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
VirtualClassDestructorCheck.cpp Fix bugprone argument comments. 2022-01-09 12:21:02 -08:00
VirtualClassDestructorCheck.h [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check 2021-09-09 13:23:38 +02:00