llvm-project/clang-tools-extra/clang-tidy
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
..
abseil [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
altera [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
android Use StringRef::contains (NFC) 2021-12-24 22:05:34 -08:00
boost [openmp] Add missing dependencies for OMP.h.inc after d90443b 2020-06-23 11:48:04 -04:00
bugprone [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
cert [clang-tidy][docs] Fix wrong url in DontModifyStdNamespaceCheck 2022-03-13 17:51:00 +01:00
concurrency [clang-tidy] Add new check 'concurrency-thread-canceltype-asynchronous' and alias 'cert-pos47-c'. 2021-02-22 12:42:20 +01:00
cppcoreguidelines [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
darwin [openmp] Add missing dependencies for OMP.h.inc after d90443b 2020-06-23 11:48:04 -04:00
fuchsia Fix false positives in `fuchsia-trailing-return` check involving deduction guides 2021-12-01 15:28:01 -05:00
google Reland "[AST] Add UsingType: a sugar type for types found via UsingDecl" 2021-12-20 18:03:15 +01:00
hicpp [clang-tidy] Applied clang-tidy fixes. NFC 2021-01-29 01:01:19 +01:00
linuxkernel [openmp] Add missing dependencies for OMP.h.inc after d90443b 2020-06-23 11:48:04 -04:00
llvm [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
llvmlibc [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
misc [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
modernize [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
mpi [clang-tidy][NFC] replace some redundant std::string creations 2022-01-19 18:36:35 +00:00
objc [clang-tidy][objc] Finds and fixes improper usages of XCTAssertEquals and XCTAssertNotEquals. 2021-12-02 18:32:16 -05:00
openmp [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
performance [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
plugin [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
portability [clang-tidy] Add portability-std-allocator-const check 2022-04-14 11:13:41 -07:00
readability [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
tool Fix typo in new -config-file option 2022-04-05 16:28:49 -04:00
utils [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
zircon Remove references to the ast_type_traits namespace 2020-12-11 00:58:46 +01:00
CMakeLists.txt Re-land "Cache the locations of NOLINTBEGIN/END blocks" with fix for build bot 2022-01-27 01:03:27 +13:00
ClangTidy.cpp [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
ClangTidy.h [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
ClangTidyCheck.cpp [clang-tidy] Add new case type to check variables with Hungarian notation 2021-08-01 15:22:17 -07:00
ClangTidyCheck.h [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
ClangTidyDiagnosticConsumer.cpp [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
ClangTidyDiagnosticConsumer.h [clang-tidy] Add a Standalone diagnostics mode to clang-tidy 2022-04-16 09:53:35 +01:00
ClangTidyForceLinker.h [clang-tidy] add concurrency module 2020-11-30 12:27:17 +03:00
ClangTidyModule.cpp [clang-tidy][NFC] Use StringMap for ClangTidyCheckFactories::FacoryMap 2020-07-30 22:57:33 +01:00
ClangTidyModule.h [clang-tidy][NFC] Remove unnecessary headers 2020-12-28 15:01:51 +00:00
ClangTidyModuleRegistry.h
ClangTidyOptions.cpp [clang-tidy] Applied clang-tidy fixes. NFC 2021-01-29 01:01:19 +01:00
ClangTidyOptions.h [clang-tidy] Fix lint warnings in clang-tidy source code (NFC) 2021-11-02 20:14:25 +13:00
ClangTidyProfiling.cpp [clang-tidy][NFC] Remove unnecessary headers 2020-12-28 15:01:51 +00:00
ClangTidyProfiling.h [clang-tidy][NFC] Remove unnecessary includes throughout clang-tidy header files 2020-06-29 16:05:52 +01:00
ExpandModularHeadersPPCallbacks.cpp [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
ExpandModularHeadersPPCallbacks.h [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
GlobList.cpp Allow newline characters as separators for checks in Clang-Tidy configurations 2022-03-15 14:30:13 -04:00
GlobList.h [clang-tidy][NFC] Remove Tristate from CachedGlobList 2022-02-23 08:35:31 +00:00
NoLintDirectiveHandler.cpp Re-land "Cache the locations of NOLINTBEGIN/END blocks" with fix for build bot 2022-01-27 01:03:27 +13:00
NoLintDirectiveHandler.h Re-land "Cache the locations of NOLINTBEGIN/END blocks" with fix for build bot 2022-01-27 01:03:27 +13:00
add_new_check.py [clang-tidy] Refactor: Prefer single quoted strings over double quoted strings [NFC] 2022-03-11 15:08:24 -07:00
clang-tidy-config.h.cmake Add an explicit toggle for the static analyzer in clang-tidy 2020-09-10 10:48:17 -04:00
rename_check.py Fix python 2-vs-3 issues in add_new_check.py and rename_check.py 2021-09-11 09:52:50 +02:00