clang-tools  11.0.0
ClangTidyMain.cpp
Go to the documentation of this file.
1 //===--- tools/extra/clang-tidy/ClangTidyMain.cpp - Clang tidy tool -------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file This file implements a clang-tidy tool.
10 ///
11 /// This tool uses the Clang Tooling infrastructure, see
12 /// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
13 /// for details on setting it up with LLVM source tree.
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #include "ClangTidyMain.h"
18 #include "../ClangTidy.h"
19 #include "../ClangTidyForceLinker.h"
20 #include "../GlobList.h"
21 #include "clang/Tooling/CommonOptionsParser.h"
22 #include "llvm/Support/InitLLVM.h"
23 #include "llvm/Support/Process.h"
24 #include "llvm/Support/Signals.h"
25 #include "llvm/Support/TargetSelect.h"
26 #include "llvm/Support/WithColor.h"
27 
28 using namespace clang::tooling;
29 using namespace llvm;
30 
31 static cl::OptionCategory ClangTidyCategory("clang-tidy options");
32 
33 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
34 static cl::extrahelp ClangTidyHelp(R"(
35 Configuration files:
36  clang-tidy attempts to read configuration for each source file from a
37  .clang-tidy file located in the closest parent directory of the source
38  file. If InheritParentConfig is true in a config file, the configuration file
39  in the parent directory (if any exists) will be taken and current config file
40  will be applied on top of the parent one. If any configuration options have
41  a corresponding command-line option, command-line option takes precedence.
42  The effective configuration can be inspected using -dump-config:
43 
44  $ clang-tidy -dump-config
45  ---
46  Checks: '-*,some-check'
47  WarningsAsErrors: ''
48  HeaderFilterRegex: ''
49  FormatStyle: none
50  InheritParentConfig: true
51  User: user
52  CheckOptions:
53  - key: some-check.SomeOption
54  value: 'some value'
55  ...
56 
57 )");
58 
59 const char DefaultChecks[] = // Enable these checks by default:
60  "clang-diagnostic-*," // * compiler diagnostics
61  "clang-analyzer-*"; // * Static Analyzer checks
62 
63 static cl::opt<std::string> Checks("checks", cl::desc(R"(
64 Comma-separated list of globs with optional '-'
65 prefix. Globs are processed in order of
66 appearance in the list. Globs without '-'
67 prefix add checks with matching names to the
68 set, globs with the '-' prefix remove checks
69 with matching names from the set of enabled
70 checks. This option's value is appended to the
71 value of the 'Checks' option in .clang-tidy
72 file, if any.
73 )"),
74  cl::init(""), cl::cat(ClangTidyCategory));
75 
76 static cl::opt<std::string> WarningsAsErrors("warnings-as-errors", cl::desc(R"(
77 Upgrades warnings to errors. Same format as
78 '-checks'.
79 This option's value is appended to the value of
80 the 'WarningsAsErrors' option in .clang-tidy
81 file, if any.
82 )"),
83  cl::init(""),
84  cl::cat(ClangTidyCategory));
85 
86 static cl::opt<std::string> HeaderFilter("header-filter", cl::desc(R"(
87 Regular expression matching the names of the
88 headers to output diagnostics from. Diagnostics
89 from the main file of each translation unit are
90 always displayed.
91 Can be used together with -line-filter.
92 This option overrides the 'HeaderFilterRegex'
93 option in .clang-tidy file, if any.
94 )"),
95  cl::init(""),
96  cl::cat(ClangTidyCategory));
97 
98 static cl::opt<bool>
99  SystemHeaders("system-headers",
100  cl::desc("Display the errors from system headers."),
101  cl::init(false), cl::cat(ClangTidyCategory));
102 static cl::opt<std::string> LineFilter("line-filter", cl::desc(R"(
103 List of files with line ranges to filter the
104 warnings. Can be used together with
105 -header-filter. The format of the list is a
106 JSON array of objects:
107  [
108  {"name":"file1.cpp","lines":[[1,3],[5,7]]},
109  {"name":"file2.h"}
110  ]
111 )"),
112  cl::init(""),
113  cl::cat(ClangTidyCategory));
114 
115 static cl::opt<bool> Fix("fix", cl::desc(R"(
116 Apply suggested fixes. Without -fix-errors
117 clang-tidy will bail out if any compilation
118 errors were found.
119 )"),
120  cl::init(false), cl::cat(ClangTidyCategory));
121 
122 static cl::opt<bool> FixErrors("fix-errors", cl::desc(R"(
123 Apply suggested fixes even if compilation
124 errors were found. If compiler errors have
125 attached fix-its, clang-tidy will apply them as
126 well.
127 )"),
128  cl::init(false), cl::cat(ClangTidyCategory));
129 
130 static cl::opt<std::string> FormatStyle("format-style", cl::desc(R"(
131 Style for formatting code around applied fixes:
132  - 'none' (default) turns off formatting
133  - 'file' (literally 'file', not a placeholder)
134  uses .clang-format file in the closest parent
135  directory
136  - '{ <json> }' specifies options inline, e.g.
137  -format-style='{BasedOnStyle: llvm, IndentWidth: 8}'
138  - 'llvm', 'google', 'webkit', 'mozilla'
139 See clang-format documentation for the up-to-date
140 information about formatting styles and options.
141 This option overrides the 'FormatStyle` option in
142 .clang-tidy file, if any.
143 )"),
144  cl::init("none"),
145  cl::cat(ClangTidyCategory));
146 
147 static cl::opt<bool> ListChecks("list-checks", cl::desc(R"(
148 List all enabled checks and exit. Use with
149 -checks=* to list all available checks.
150 )"),
151  cl::init(false), cl::cat(ClangTidyCategory));
152 
153 static cl::opt<bool> ExplainConfig("explain-config", cl::desc(R"(
154 For each enabled check explains, where it is
155 enabled, i.e. in clang-tidy binary, command
156 line or a specific configuration file.
157 )"),
158  cl::init(false), cl::cat(ClangTidyCategory));
159 
160 static cl::opt<std::string> Config("config", cl::desc(R"(
161 Specifies a configuration in YAML/JSON format:
162  -config="{Checks: '*',
163  CheckOptions: [{key: x,
164  value: y}]}"
165 When the value is empty, clang-tidy will
166 attempt to find a file named .clang-tidy for
167 each source file in its parent directories.
168 )"),
169  cl::init(""), cl::cat(ClangTidyCategory));
170 
171 static cl::opt<bool> DumpConfig("dump-config", cl::desc(R"(
172 Dumps configuration in the YAML format to
173 stdout. This option can be used along with a
174 file name (and '--' if the file is outside of a
175 project with configured compilation database).
176 The configuration used for this file will be
177 printed.
178 Use along with -checks=* to include
179 configuration of all checks.
180 )"),
181  cl::init(false), cl::cat(ClangTidyCategory));
182 
183 static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"(
184 Enable per-check timing profiles, and print a
185 report to stderr.
186 )"),
187  cl::init(false),
188  cl::cat(ClangTidyCategory));
189 
190 static cl::opt<std::string> StoreCheckProfile("store-check-profile",
191  cl::desc(R"(
192 By default reports are printed in tabulated
193 format to stderr. When this option is passed,
194 these per-TU profiles are instead stored as JSON.
195 )"),
196  cl::value_desc("prefix"),
197  cl::cat(ClangTidyCategory));
198 
199 /// This option allows enabling the experimental alpha checkers from the static
200 /// analyzer. This option is set to false and not visible in help, because it is
201 /// highly not recommended for users.
202 static cl::opt<bool>
203  AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers",
204  cl::init(false), cl::Hidden,
205  cl::cat(ClangTidyCategory));
206 
207 static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
208 YAML file to store suggested fixes in. The
209 stored fixes can be applied to the input source
210 code with clang-apply-replacements.
211 )"),
212  cl::value_desc("filename"),
213  cl::cat(ClangTidyCategory));
214 
215 static cl::opt<bool> Quiet("quiet", cl::desc(R"(
216 Run clang-tidy in quiet mode. This suppresses
217 printing statistics about ignored warnings and
218 warnings treated as errors if the respective
219 options are specified.
220 )"),
221  cl::init(false),
222  cl::cat(ClangTidyCategory));
223 
224 static cl::opt<std::string> VfsOverlay("vfsoverlay", cl::desc(R"(
225 Overlay the virtual filesystem described by file
226 over the real file system.
227 )"),
228  cl::value_desc("filename"),
229  cl::cat(ClangTidyCategory));
230 
231 static cl::opt<bool> UseColor("use-color", cl::desc(R"(
232 Use colors in diagnostics. If not set, colors
233 will be used if the terminal connected to
234 standard output supports colors.
235 This option overrides the 'UseColor' option in
236 .clang-tidy file, if any.
237 )"),
238  cl::init(false), cl::cat(ClangTidyCategory));
239 
240 namespace clang {
241 namespace tidy {
242 
243 static void printStats(const ClangTidyStats &Stats) {
244  if (Stats.errorsIgnored()) {
245  llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
246  StringRef Separator = "";
247  if (Stats.ErrorsIgnoredNonUserCode) {
248  llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
249  Separator = ", ";
250  }
251  if (Stats.ErrorsIgnoredLineFilter) {
252  llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
253  << " due to line filter";
254  Separator = ", ";
255  }
256  if (Stats.ErrorsIgnoredNOLINT) {
257  llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
258  Separator = ", ";
259  }
260  if (Stats.ErrorsIgnoredCheckFilter)
261  llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
262  << " with check filters";
263  llvm::errs() << ").\n";
264  if (Stats.ErrorsIgnoredNonUserCode)
265  llvm::errs() << "Use -header-filter=.* to display errors from all "
266  "non-system headers. Use -system-headers to display "
267  "errors from system headers as well.\n";
268  }
269 }
270 
271 static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider(
272  llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
273  ClangTidyGlobalOptions GlobalOptions;
274  if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
275  llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
276  llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
277  return nullptr;
278  }
279 
280  ClangTidyOptions DefaultOptions;
281  DefaultOptions.Checks = DefaultChecks;
282  DefaultOptions.WarningsAsErrors = "";
283  DefaultOptions.HeaderFilterRegex = HeaderFilter;
284  DefaultOptions.SystemHeaders = SystemHeaders;
285  DefaultOptions.FormatStyle = FormatStyle;
286  DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
287  // USERNAME is used on Windows.
288  if (!DefaultOptions.User)
289  DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
290 
291  ClangTidyOptions OverrideOptions;
292  if (Checks.getNumOccurrences() > 0)
293  OverrideOptions.Checks = Checks;
294  if (WarningsAsErrors.getNumOccurrences() > 0)
295  OverrideOptions.WarningsAsErrors = WarningsAsErrors;
296  if (HeaderFilter.getNumOccurrences() > 0)
297  OverrideOptions.HeaderFilterRegex = HeaderFilter;
298  if (SystemHeaders.getNumOccurrences() > 0)
299  OverrideOptions.SystemHeaders = SystemHeaders;
300  if (FormatStyle.getNumOccurrences() > 0)
301  OverrideOptions.FormatStyle = FormatStyle;
302  if (UseColor.getNumOccurrences() > 0)
303  OverrideOptions.UseColor = UseColor;
304 
305  if (!Config.empty()) {
306  if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig =
308  return std::make_unique<ConfigOptionsProvider>(
309  GlobalOptions,
310  ClangTidyOptions::getDefaults().mergeWith(DefaultOptions, 0),
311  *ParsedConfig, OverrideOptions, std::move(FS));
312  } else {
313  llvm::errs() << "Error: invalid configuration specified.\n"
314  << ParsedConfig.getError().message() << "\n";
315  return nullptr;
316  }
317  }
318  return std::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
319  OverrideOptions, std::move(FS));
320 }
321 
322 llvm::IntrusiveRefCntPtr<vfs::FileSystem>
323 getVfsFromFile(const std::string &OverlayFile,
324  llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS) {
325  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
326  BaseFS->getBufferForFile(OverlayFile);
327  if (!Buffer) {
328  llvm::errs() << "Can't load virtual filesystem overlay file '"
329  << OverlayFile << "': " << Buffer.getError().message()
330  << ".\n";
331  return nullptr;
332  }
333 
334  IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getVFSFromYAML(
335  std::move(Buffer.get()), /*DiagHandler*/ nullptr, OverlayFile);
336  if (!FS) {
337  llvm::errs() << "Error: invalid virtual filesystem overlay file '"
338  << OverlayFile << "'.\n";
339  return nullptr;
340  }
341  return FS;
342 }
343 
344 int clangTidyMain(int argc, const char **argv) {
345  llvm::InitLLVM X(argc, argv);
346  llvm::Expected<CommonOptionsParser> OptionsParser =
347  CommonOptionsParser::create(argc, argv, ClangTidyCategory,
348  cl::ZeroOrMore);
349  if (!OptionsParser) {
350  llvm::WithColor::error() << llvm::toString(OptionsParser.takeError());
351  return 1;
352  }
353 
354  llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
355  new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
356 
357  if (!VfsOverlay.empty()) {
358  IntrusiveRefCntPtr<vfs::FileSystem> VfsFromFile =
359  getVfsFromFile(VfsOverlay, BaseFS);
360  if (!VfsFromFile)
361  return 1;
362  BaseFS->pushOverlay(VfsFromFile);
363  }
364 
365  auto OwningOptionsProvider = createOptionsProvider(BaseFS);
366  auto *OptionsProvider = OwningOptionsProvider.get();
367  if (!OptionsProvider)
368  return 1;
369 
370  auto MakeAbsolute = [](const std::string &Input) -> SmallString<256> {
371  if (Input.empty())
372  return {};
373  SmallString<256> AbsolutePath(Input);
374  if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
375  llvm::errs() << "Can't make absolute path from " << Input << ": "
376  << EC.message() << "\n";
377  }
378  return AbsolutePath;
379  };
380 
381  SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile);
382 
383  StringRef FileName("dummy");
384  auto PathList = OptionsParser->getSourcePathList();
385  if (!PathList.empty()) {
386  FileName = PathList.front();
387  }
388 
389  SmallString<256> FilePath = MakeAbsolute(std::string(FileName));
390 
391  ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
392  std::vector<std::string> EnabledChecks =
394 
395  if (ExplainConfig) {
396  // FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
397  std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
398  RawOptions = OptionsProvider->getRawOptions(FilePath);
399  for (const std::string &Check : EnabledChecks) {
400  for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
401  if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
402  llvm::outs() << "'" << Check << "' is enabled in the " << It->second
403  << ".\n";
404  break;
405  }
406  }
407  }
408  return 0;
409  }
410 
411  if (ListChecks) {
412  if (EnabledChecks.empty()) {
413  llvm::errs() << "No checks enabled.\n";
414  return 1;
415  }
416  llvm::outs() << "Enabled checks:";
417  for (const auto &CheckName : EnabledChecks)
418  llvm::outs() << "\n " << CheckName;
419  llvm::outs() << "\n\n";
420  return 0;
421  }
422 
423  if (DumpConfig) {
424  EffectiveOptions.CheckOptions =
426  llvm::outs() << configurationAsText(
427  ClangTidyOptions::getDefaults().mergeWith(
428  EffectiveOptions, 0))
429  << "\n";
430  return 0;
431  }
432 
433  if (EnabledChecks.empty()) {
434  llvm::errs() << "Error: no checks enabled.\n";
435  llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
436  return 1;
437  }
438 
439  if (PathList.empty()) {
440  llvm::errs() << "Error: no input files specified.\n";
441  llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
442  return 1;
443  }
444 
445  llvm::InitializeAllTargetInfos();
446  llvm::InitializeAllTargetMCs();
447  llvm::InitializeAllAsmParsers();
448 
449  ClangTidyContext Context(std::move(OwningOptionsProvider),
451  std::vector<ClangTidyError> Errors =
452  runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS,
453  EnableCheckProfile, ProfilePrefix);
454  bool FoundErrors = llvm::find_if(Errors, [](const ClangTidyError &E) {
455  return E.DiagLevel == ClangTidyError::Error;
456  }) != Errors.end();
457 
458  const bool DisableFixes = Fix && FoundErrors && !FixErrors;
459 
460  unsigned WErrorCount = 0;
461 
462  // -fix-errors implies -fix.
463  handleErrors(Errors, Context, (FixErrors || Fix) && !DisableFixes, WErrorCount,
464  BaseFS);
465 
466  if (!ExportFixes.empty() && !Errors.empty()) {
467  std::error_code EC;
468  llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::OF_None);
469  if (EC) {
470  llvm::errs() << "Error opening output file: " << EC.message() << '\n';
471  return 1;
472  }
473  exportReplacements(FilePath.str(), Errors, OS);
474  }
475 
476  if (!Quiet) {
477  printStats(Context.getStats());
478  if (DisableFixes)
479  llvm::errs()
480  << "Found compiler errors, but -fix-errors was not specified.\n"
481  "Fixes have NOT been applied.\n\n";
482  }
483 
484  if (WErrorCount) {
485  if (!Quiet) {
486  StringRef Plural = WErrorCount == 1 ? "" : "s";
487  llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
488  << Plural << "\n";
489  }
490  return 1;
491  }
492 
493  if (FoundErrors) {
494  // TODO: Figure out when zero exit code should be used with -fix-errors:
495  // a. when a fix has been applied for an error
496  // b. when a fix has been applied for all errors
497  // c. some other condition.
498  // For now always returning zero when -fix-errors is used.
499  if (FixErrors)
500  return 0;
501  if (!Quiet)
502  llvm::errs() << "Found compiler error(s).\n";
503  return 1;
504  }
505 
506  return 0;
507 }
508 
509 } // namespace tidy
510 } // namespace clang
llvm
Some operations such as code completion produce a set of candidates.
Definition: YAMLGenerator.cpp:28
E
const Expr * E
Definition: AvoidBindCheck.cpp:88
StoreCheckProfile
static cl::opt< std::string > StoreCheckProfile("store-check-profile", cl::desc(R"( By default reports are printed in tabulated format to stderr. When this option is passed, these per-TU profiles are instead stored as JSON. )"), cl::value_desc("prefix"), cl::cat(ClangTidyCategory))
clang::tidy::ClangTidyStats::ErrorsIgnoredCheckFilter
unsigned ErrorsIgnoredCheckFilter
Definition: ClangTidyDiagnosticConsumer.h:56
Checks
static cl::opt< std::string > Checks("checks", cl::desc(R"( Comma-separated list of globs with optional '-' prefix. Globs are processed in order of appearance in the list. Globs without '-' prefix add checks with matching names to the set, globs with the '-' prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
FormatStyle
static cl::opt< std::string > FormatStyle("format-style", cl::desc(R"( Style for formatting code around applied fixes: - 'none' (default) turns off formatting - 'file' (literally 'file', not a placeholder) uses .clang-format file in the closest parent directory - '{ <json> }' specifies options inline, e.g. -format-style='{BasedOnStyle: llvm, IndentWidth: 8}' - 'llvm', 'google', 'webkit', 'mozilla' See clang-format documentation for the up-to-date information about formatting styles and options. This option overrides the 'FormatStyle` option in .clang-tidy file, if any. )"), cl::init("none"), cl::cat(ClangTidyCategory))
clang::tidy::parseLineFilter
std::error_code parseLineFilter(StringRef LineFilter, clang::tidy::ClangTidyGlobalOptions &Options)
Parses -line-filter option and stores it to the Options.
Definition: ClangTidyOptions.cpp:372
clang::tidy::ClangTidyStats
Contains displayed and ignored diagnostic counters for a ClangTidy run.
Definition: ClangTidyDiagnosticConsumer.h:50
SystemHeaders
static cl::opt< bool > SystemHeaders("system-headers", cl::desc("Display the errors from system headers."), cl::init(false), cl::cat(ClangTidyCategory))
ClangTidyCategory
static cl::OptionCategory ClangTidyCategory("clang-tidy options")
clang::tidy::getCheckOptions
ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers)
Returns the effective check-specific options.
Definition: ClangTidy.cpp:488
clang::tidy::clangTidyMain
int clangTidyMain(int argc, const char **argv)
Definition: ClangTidyMain.cpp:217
ListChecks
static cl::opt< bool > ListChecks("list-checks", cl::desc(R"( List all enabled checks and exit. Use with -checks=* to list all available checks. )"), cl::init(false), cl::cat(ClangTidyCategory))
Fix
static cl::opt< bool > Fix("fix", cl::desc(R"( Apply suggested fixes. Without -fix-errors clang-tidy will bail out if any compilation errors were found. )"), cl::init(false), cl::cat(ClangTidyCategory))
run-clang-tidy.make_absolute
def make_absolute(f, directory)
Definition: run-clang-tidy.py:76
UseColor
static cl::opt< bool > UseColor("use-color", cl::desc(R"( Use colors in diagnostics. If not set, colors will be used if the terminal connected to standard output supports colors. This option overrides the 'UseColor' option in .clang-tidy file, if any. )"), cl::init(false), cl::cat(ClangTidyCategory))
Error
constexpr static llvm::SourceMgr::DiagKind Error
Definition: ConfigCompile.cpp:211
clang::tidy::runClangTidy
std::vector< ClangTidyError > runClangTidy(clang::tidy::ClangTidyContext &Context, const CompilationDatabase &Compilations, ArrayRef< std::string > InputFiles, llvm::IntrusiveRefCntPtr< llvm::vfs::OverlayFileSystem > BaseFS, bool EnableCheckProfile, llvm::StringRef StoreCheckProfile)
Definition: ClangTidy.cpp:499
AllowEnablingAnalyzerAlphaCheckers
static cl::opt< bool > AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers", cl::init(false), cl::Hidden, cl::cat(ClangTidyCategory))
This option allows enabling the experimental alpha checkers from the static analyzer.
clang::tidy::ClangTidyStats::ErrorsIgnoredNOLINT
unsigned ErrorsIgnoredNOLINT
Definition: ClangTidyDiagnosticConsumer.h:57
clang::tidy::handleErrors
void handleErrors(llvm::ArrayRef< ClangTidyError > Errors, ClangTidyContext &Context, bool Fix, unsigned &WarningsAsErrorsCount, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS)
Displays the found Errors to the users.
Definition: ClangTidy.cpp:576
clang::tidy::ClangTidyStats::errorsIgnored
unsigned errorsIgnored() const
Definition: ClangTidyDiagnosticConsumer.h:61
clang::tooling
Definition: ClangTidy.h:25
clang::tidy::parseConfiguration
llvm::ErrorOr< ClangTidyOptions > parseConfiguration(StringRef Config)
Definition: ClangTidyOptions.cpp:379
clang::tidy::getVfsFromFile
llvm::IntrusiveRefCntPtr< vfs::FileSystem > getVfsFromFile(const std::string &OverlayFile, llvm::IntrusiveRefCntPtr< vfs::FileSystem > BaseFS)
Definition: ClangTidyMain.cpp:196
FS
MockFS FS
Definition: ClangdLSPServerTests.cpp:66
ClangTidyMain.h
clang::clangd::Separator
Definition: FuzzyMatch.h:59
clang::tidy::abseil::X
static ClangTidyModuleRegistry::Add< AbseilModule > X("abseil-module", "Add Abseil checks.")
clang::tidy::configurationAsText
std::string configurationAsText(const ClangTidyOptions &Options)
Serializes configuration to a YAML-encoded string.
Definition: ClangTidyOptions.cpp:388
Quiet
static cl::opt< bool > Quiet("quiet", cl::desc(R"( Run clang-tidy in quiet mode. This suppresses printing statistics about ignored warnings and warnings treated as errors if the respective options are specified. )"), cl::init(false), cl::cat(ClangTidyCategory))
clang::tidy::ClangTidyStats::ErrorsIgnoredLineFilter
unsigned ErrorsIgnoredLineFilter
Definition: ClangTidyDiagnosticConsumer.h:59
clang::tidy::ClangTidyStats::ErrorsIgnoredNonUserCode
unsigned ErrorsIgnoredNonUserCode
Definition: ClangTidyDiagnosticConsumer.h:58
HeaderFilter
static cl::opt< std::string > HeaderFilter("header-filter", cl::desc(R"( Regular expression matching the names of the headers to output diagnostics from. Diagnostics from the main file of each translation unit are always displayed. Can be used together with -line-filter. This option overrides the 'HeaderFilterRegex' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
DefaultChecks
const char DefaultChecks[]
Definition: ClangTidyMain.cpp:36
Config
static cl::opt< std::string > Config("config", cl::desc(R"( Specifies a configuration in YAML/JSON format: -config="{Checks:' *', CheckOptions:[{key:x, value:y}]}" When the value is empty, clang-tidy will attempt to find a file named .clang-tidy for each source file in its parent directories. )"), cl::init(""), cl::cat(ClangTidyCategory))
WarningsAsErrors
static cl::opt< std::string > WarningsAsErrors("warnings-as-errors", cl::desc(R"( Upgrades warnings to errors. Same format as '-checks'. This option's value is appended to the value of the 'WarningsAsErrors' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
FixErrors
static cl::opt< bool > FixErrors("fix-errors", cl::desc(R"( Apply suggested fixes even if compilation errors were found. If compiler errors have attached fix-its, clang-tidy will apply them as well. )"), cl::init(false), cl::cat(ClangTidyCategory))
EnableCheckProfile
static cl::opt< bool > EnableCheckProfile("enable-check-profile", cl::desc(R"( Enable per-check timing profiles, and print a report to stderr. )"), cl::init(false), cl::cat(ClangTidyCategory))
ExportFixes
static cl::opt< std::string > ExportFixes("export-fixes", cl::desc(R"( YAML file to store suggested fixes in. The stored fixes can be applied to the input source code with clang-apply-replacements. )"), cl::value_desc("filename"), cl::cat(ClangTidyCategory))
LineFilter
static cl::opt< std::string > LineFilter("line-filter", cl::desc(R"( List of files with line ranges to filter the warnings. Can be used together with -header-filter. The format of the list is a JSON array of objects: [ {"name":"file1.cpp","lines":[[1,3],[5,7]]}, {"name":"file2.h"} ] )"), cl::init(""), cl::cat(ClangTidyCategory))
clang::tidy::createOptionsProvider
static std::unique_ptr< ClangTidyOptionsProvider > createOptionsProvider(llvm::IntrusiveRefCntPtr< vfs::FileSystem > FS)
Definition: ClangTidyMain.cpp:144
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::pp_trace::error
static LLVM_ATTRIBUTE_NORETURN void error(Twine Message)
Definition: PPTrace.cpp:72
OS
llvm::raw_string_ostream OS
Definition: TraceTests.cpp:162
clang::tidy::cppcoreguidelines::toString
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
Definition: SpecialMemberFunctionsCheck.cpp:60
clang::tidy::getCheckNames
std::vector< std::string > getCheckNames(const ClangTidyOptions &Options, bool AllowEnablingAnalyzerAlphaCheckers)
Fills the list of check names that are enabled when the provided filters are applied.
Definition: ClangTidy.cpp:477
VfsOverlay
static cl::opt< std::string > VfsOverlay("vfsoverlay", cl::desc(R"( Overlay the virtual filesystem described by file over the real file system. )"), cl::value_desc("filename"), cl::cat(ClangTidyCategory))
clang::tidy::printStats
static void printStats(const ClangTidyStats &Stats)
Definition: ClangTidyMain.cpp:116
clang::tidy::exportReplacements
void exportReplacements(const llvm::StringRef MainFilePath, const std::vector< ClangTidyError > &Errors, raw_ostream &OS)
Definition: ClangTidy.cpp:603
DumpConfig
static cl::opt< bool > DumpConfig("dump-config", cl::desc(R"( Dumps configuration in the YAML format to stdout. This option can be used along with a file name (and '--' if the file is outside of a project with configured compilation database). The configuration used for this file will be printed. Use along with -checks=* to include configuration of all checks. )"), cl::init(false), cl::cat(ClangTidyCategory))
ExplainConfig
static cl::opt< bool > ExplainConfig("explain-config", cl::desc(R"( For each enabled check explains, where it is enabled, i.e. in clang-tidy binary, command line or a specific configuration file. )"), cl::init(false), cl::cat(ClangTidyCategory))
CommonHelp
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage)
FileName
PathRef FileName
Definition: CodeComplete.cpp:1043
ClangTidyHelp
static cl::extrahelp ClangTidyHelp(R"( Configuration files: clang-tidy attempts to read configuration for each source file from a .clang-tidy file located in the closest parent directory of the source file. If InheritParentConfig is true in a config file, the configuration file in the parent directory (if any exists) will be taken and current config file will be applied on top of the parent one. If any configuration options have a corresponding command-line option, command-line option takes precedence. The effective configuration can be inspected using -dump-config: $ clang-tidy -dump-config --- Checks: '-*,some-check' WarningsAsErrors: '' HeaderFilterRegex: '' FormatStyle: none InheritParentConfig: true User: user CheckOptions: - key: some-check.SomeOption value: 'some value' ... )")