clang-tools  5.0.0
ClangTidyMain.cpp
Go to the documentation of this file.
1 //===--- tools/extra/clang-tidy/ClangTidyMain.cpp - Clang tidy tool -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file This file implements a clang-tidy tool.
11 ///
12 /// This tool uses the Clang Tooling infrastructure, see
13 /// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
14 /// for details on setting it up with LLVM source tree.
15 ///
16 //===----------------------------------------------------------------------===//
17 
18 #include "../ClangTidy.h"
19 #include "clang/Tooling/CommonOptionsParser.h"
20 #include "llvm/Support/Process.h"
21 
22 using namespace clang::ast_matchers;
23 using namespace clang::driver;
24 using namespace clang::tooling;
25 using namespace llvm;
26 
27 static cl::OptionCategory ClangTidyCategory("clang-tidy options");
28 
29 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
30 static cl::extrahelp ClangTidyHelp(R"(
31 Configuration files:
32  clang-tidy attempts to read configuration for each source file from a
33  .clang-tidy file located in the closest parent directory of the source
34  file. If any configuration options have a corresponding command-line
35  option, command-line option takes precedence. The effective
36  configuration can be inspected using -dump-config:
37 
38  $ clang-tidy -dump-config
39  ---
40  Checks: '-*,some-check'
41  WarningsAsErrors: ''
42  HeaderFilterRegex: ''
43  AnalyzeTemporaryDtors: false
44  FormatStyle: none
45  User: user
46  CheckOptions:
47  - key: some-check.SomeOption
48  value: 'some value'
49  ...
50 
51 )");
52 
53 const char DefaultChecks[] = // Enable these checks by default:
54  "clang-diagnostic-*," // * compiler diagnostics
55  "clang-analyzer-*"; // * Static Analyzer checks
56 
57 static cl::opt<std::string> Checks("checks", cl::desc(R"(
58 Comma-separated list of globs with optional '-'
59 prefix. Globs are processed in order of
60 appearance in the list. Globs without '-'
61 prefix add checks with matching names to the
62 set, globs with the '-' prefix remove checks
63 with matching names from the set of enabled
64 checks. This option's value is appended to the
65 value of the 'Checks' option in .clang-tidy
66 file, if any.
67 )"),
68  cl::init(""), cl::cat(ClangTidyCategory));
69 
70 static cl::opt<std::string> WarningsAsErrors("warnings-as-errors", cl::desc(R"(
71 Upgrades warnings to errors. Same format as
72 '-checks'.
73 This option's value is appended to the value of
74 the 'WarningsAsErrors' option in .clang-tidy
75 file, if any.
76 )"),
77  cl::init(""),
78  cl::cat(ClangTidyCategory));
79 
80 static cl::opt<std::string> HeaderFilter("header-filter", cl::desc(R"(
81 Regular expression matching the names of the
82 headers to output diagnostics from. Diagnostics
83 from the main file of each translation unit are
84 always displayed.
85 Can be used together with -line-filter.
86 This option overrides the 'HeaderFilter' option
87 in .clang-tidy file, if any.
88 )"),
89  cl::init(""),
90  cl::cat(ClangTidyCategory));
91 
92 static cl::opt<bool>
93  SystemHeaders("system-headers",
94  cl::desc("Display the errors from system headers."),
95  cl::init(false), cl::cat(ClangTidyCategory));
96 static cl::opt<std::string> LineFilter("line-filter", cl::desc(R"(
97 List of files with line ranges to filter the
98 warnings. Can be used together with
99 -header-filter. The format of the list is a
100 JSON array of objects:
101  [
102  {"name":"file1.cpp","lines":[[1,3],[5,7]]},
103  {"name":"file2.h"}
104  ]
105 )"),
106  cl::init(""),
107  cl::cat(ClangTidyCategory));
108 
109 static cl::opt<bool> Fix("fix", cl::desc(R"(
110 Apply suggested fixes. Without -fix-errors
111 clang-tidy will bail out if any compilation
112 errors were found.
113 )"),
114  cl::init(false), cl::cat(ClangTidyCategory));
115 
116 static cl::opt<bool> FixErrors("fix-errors", cl::desc(R"(
117 Apply suggested fixes even if compilation
118 errors were found. If compiler errors have
119 attached fix-its, clang-tidy will apply them as
120 well.
121 )"),
122  cl::init(false), cl::cat(ClangTidyCategory));
123 
124 static cl::opt<std::string> FormatStyle("format-style", cl::desc(R"(
125 Style for formatting code around applied fixes:
126  - 'none' (default) turns off formatting
127  - 'file' (literally 'file', not a placeholder)
128  uses .clang-format file in the closest parent
129  directory
130  - '{ <json> }' specifies options inline, e.g.
131  -format-style='{BasedOnStyle: llvm, IndentWidth: 8}'
132  - 'llvm', 'google', 'webkit', 'mozilla'
133 See clang-format documentation for the up-to-date
134 information about formatting styles and options.
135 This option overrides the 'FormatStyle` option in
136 .clang-tidy file, if any.
137 )"),
138  cl::init("none"),
139  cl::cat(ClangTidyCategory));
140 
141 static cl::opt<bool> ListChecks("list-checks", cl::desc(R"(
142 List all enabled checks and exit. Use with
143 -checks=* to list all available checks.
144 )"),
145  cl::init(false), cl::cat(ClangTidyCategory));
146 
147 static cl::opt<bool> ExplainConfig("explain-config", cl::desc(R"(
148 For each enabled check explains, where it is
149 enabled, i.e. in clang-tidy binary, command
150 line or a specific configuration file.
151 )"),
152  cl::init(false), cl::cat(ClangTidyCategory));
153 
154 static cl::opt<std::string> Config("config", cl::desc(R"(
155 Specifies a configuration in YAML/JSON format:
156  -config="{Checks: '*',
157  CheckOptions: [{key: x,
158  value: y}]}"
159 When the value is empty, clang-tidy will
160 attempt to find a file named .clang-tidy for
161 each source file in its parent directories.
162 )"),
163  cl::init(""), cl::cat(ClangTidyCategory));
165 static cl::opt<bool> DumpConfig("dump-config", cl::desc(R"(
166 Dumps configuration in the YAML format to
167 stdout. This option can be used along with a
168 file name (and '--' if the file is outside of a
169 project with configured compilation database).
170 The configuration used for this file will be
171 printed.
172 Use along with -checks=* to include
173 configuration of all checks.
174 )"),
175  cl::init(false), cl::cat(ClangTidyCategory));
176 
177 static cl::opt<bool> EnableCheckProfile("enable-check-profile", cl::desc(R"(
178 Enable per-check timing profiles, and print a
179 report to stderr.
180 )"),
181  cl::init(false),
182  cl::cat(ClangTidyCategory));
183 
184 static cl::opt<bool> AnalyzeTemporaryDtors("analyze-temporary-dtors",
185  cl::desc(R"(
186 Enable temporary destructor-aware analysis in
187 clang-analyzer- checks.
188 This option overrides the value read from a
189 .clang-tidy file.
190 )"),
191  cl::init(false),
192  cl::cat(ClangTidyCategory));
193 
194 static cl::opt<std::string> ExportFixes("export-fixes", cl::desc(R"(
195 YAML file to store suggested fixes in. The
196 stored fixes can be applied to the input source
197 code with clang-apply-replacements.
198 )"),
199  cl::value_desc("filename"),
200  cl::cat(ClangTidyCategory));
201 
202 static cl::opt<bool> Quiet("quiet", cl::desc(R"(
203 Run clang-tidy in quiet mode. This suppresses
204 printing statistics about ignored warnings and
205 warnings treated as errors if the respective
206 options are specified.
207 )"),
208  cl::init(false),
209  cl::cat(ClangTidyCategory));
210 
211 namespace clang {
212 namespace tidy {
213 
214 static void printStats(const ClangTidyStats &Stats) {
215  if (Stats.errorsIgnored()) {
216  llvm::errs() << "Suppressed " << Stats.errorsIgnored() << " warnings (";
217  StringRef Separator = "";
218  if (Stats.ErrorsIgnoredNonUserCode) {
219  llvm::errs() << Stats.ErrorsIgnoredNonUserCode << " in non-user code";
220  Separator = ", ";
221  }
222  if (Stats.ErrorsIgnoredLineFilter) {
223  llvm::errs() << Separator << Stats.ErrorsIgnoredLineFilter
224  << " due to line filter";
225  Separator = ", ";
226  }
227  if (Stats.ErrorsIgnoredNOLINT) {
228  llvm::errs() << Separator << Stats.ErrorsIgnoredNOLINT << " NOLINT";
229  Separator = ", ";
230  }
231  if (Stats.ErrorsIgnoredCheckFilter)
232  llvm::errs() << Separator << Stats.ErrorsIgnoredCheckFilter
233  << " with check filters";
234  llvm::errs() << ").\n";
235  if (Stats.ErrorsIgnoredNonUserCode)
236  llvm::errs() << "Use -header-filter=.* to display errors from all "
237  "non-system headers. Use -system-headers to display "
238  "errors from system headers as well.\n";
239  }
240 }
241 
242 static void printProfileData(const ProfileData &Profile,
243  llvm::raw_ostream &OS) {
244  // Time is first to allow for sorting by it.
245  std::vector<std::pair<llvm::TimeRecord, StringRef>> Timers;
246  TimeRecord Total;
247 
248  for (const auto &P : Profile.Records) {
249  Timers.emplace_back(P.getValue(), P.getKey());
250  Total += P.getValue();
251  }
252 
253  std::sort(Timers.begin(), Timers.end());
254 
255  std::string Line = "===" + std::string(73, '-') + "===\n";
256  OS << Line;
257 
258  if (Total.getUserTime())
259  OS << " ---User Time---";
260  if (Total.getSystemTime())
261  OS << " --System Time--";
262  if (Total.getProcessTime())
263  OS << " --User+System--";
264  OS << " ---Wall Time---";
265  if (Total.getMemUsed())
266  OS << " ---Mem---";
267  OS << " --- Name ---\n";
268 
269  // Loop through all of the timing data, printing it out.
270  for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
271  I->first.print(Total, OS);
272  OS << I->second << '\n';
273  }
274 
275  Total.print(Total, OS);
276  OS << "Total\n";
277  OS << Line << "\n";
278  OS.flush();
279 }
280 
281 static std::unique_ptr<ClangTidyOptionsProvider> createOptionsProvider() {
282  ClangTidyGlobalOptions GlobalOptions;
283  if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) {
284  llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n";
285  llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
286  return nullptr;
287  }
288 
289  ClangTidyOptions DefaultOptions;
290  DefaultOptions.Checks = DefaultChecks;
291  DefaultOptions.WarningsAsErrors = "";
292  DefaultOptions.HeaderFilterRegex = HeaderFilter;
293  DefaultOptions.SystemHeaders = SystemHeaders;
294  DefaultOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
295  DefaultOptions.FormatStyle = FormatStyle;
296  DefaultOptions.User = llvm::sys::Process::GetEnv("USER");
297  // USERNAME is used on Windows.
298  if (!DefaultOptions.User)
299  DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME");
300 
301  ClangTidyOptions OverrideOptions;
302  if (Checks.getNumOccurrences() > 0)
303  OverrideOptions.Checks = Checks;
304  if (WarningsAsErrors.getNumOccurrences() > 0)
305  OverrideOptions.WarningsAsErrors = WarningsAsErrors;
306  if (HeaderFilter.getNumOccurrences() > 0)
307  OverrideOptions.HeaderFilterRegex = HeaderFilter;
308  if (SystemHeaders.getNumOccurrences() > 0)
309  OverrideOptions.SystemHeaders = SystemHeaders;
310  if (AnalyzeTemporaryDtors.getNumOccurrences() > 0)
311  OverrideOptions.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
312  if (FormatStyle.getNumOccurrences() > 0)
313  OverrideOptions.FormatStyle = FormatStyle;
314 
315  if (!Config.empty()) {
316  if (llvm::ErrorOr<ClangTidyOptions> ParsedConfig =
318  return llvm::make_unique<ConfigOptionsProvider>(
319  GlobalOptions,
320  ClangTidyOptions::getDefaults().mergeWith(DefaultOptions),
321  *ParsedConfig, OverrideOptions);
322  } else {
323  llvm::errs() << "Error: invalid configuration specified.\n"
324  << ParsedConfig.getError().message() << "\n";
325  return nullptr;
326  }
327  }
328  return llvm::make_unique<FileOptionsProvider>(GlobalOptions, DefaultOptions,
329  OverrideOptions);
330 }
331 
332 static int clangTidyMain(int argc, const char **argv) {
333  CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
334  cl::ZeroOrMore);
335 
336  auto OwningOptionsProvider = createOptionsProvider();
337  auto *OptionsProvider = OwningOptionsProvider.get();
338  if (!OptionsProvider)
339  return 1;
341  StringRef FileName("dummy");
342  auto PathList = OptionsParser.getSourcePathList();
343  if (!PathList.empty()) {
344  FileName = PathList.front();
345  }
346 
347  SmallString<256> FilePath(FileName);
348  if (std::error_code EC = llvm::sys::fs::make_absolute(FilePath)) {
349  llvm::errs() << "Can't make absolute path from " << FileName << ": "
350  << EC.message() << "\n";
351  }
352  ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
353  std::vector<std::string> EnabledChecks = getCheckNames(EffectiveOptions);
354 
356  // FIXME: Show other ClangTidyOptions' fields, like ExtraArg.
357  std::vector<clang::tidy::ClangTidyOptionsProvider::OptionsSource>
358  RawOptions = OptionsProvider->getRawOptions(FilePath);
359  for (const std::string &Check : EnabledChecks) {
360  for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) {
361  if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) {
362  llvm::outs() << "'" << Check << "' is enabled in the " << It->second
363  << ".\n";
364  break;
365  }
366  }
367  }
368  return 0;
369  }
371  if (ListChecks) {
372  if (EnabledChecks.empty()) {
373  llvm::errs() << "No checks enabled.\n";
374  return 1;
375  }
376  llvm::outs() << "Enabled checks:";
377  for (const auto &CheckName : EnabledChecks)
378  llvm::outs() << "\n " << CheckName;
379  llvm::outs() << "\n\n";
380  return 0;
381  }
382 
383  if (DumpConfig) {
384  EffectiveOptions.CheckOptions = getCheckOptions(EffectiveOptions);
385  llvm::outs() << configurationAsText(
386  ClangTidyOptions::getDefaults().mergeWith(
387  EffectiveOptions))
388  << "\n";
389  return 0;
390  }
391 
392  if (EnabledChecks.empty()) {
393  llvm::errs() << "Error: no checks enabled.\n";
394  llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
395  return 1;
396  }
397 
398  if (PathList.empty()) {
399  llvm::errs() << "Error: no input files specified.\n";
400  llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
401  return 1;
402  }
403 
404  ProfileData Profile;
405 
406  ClangTidyContext Context(std::move(OwningOptionsProvider));
407  runClangTidy(Context, OptionsParser.getCompilations(), PathList,
408  EnableCheckProfile ? &Profile : nullptr);
409  ArrayRef<ClangTidyError> Errors = Context.getErrors();
410  bool FoundErrors =
411  std::find_if(Errors.begin(), Errors.end(), [](const ClangTidyError &E) {
412  return E.DiagLevel == ClangTidyError::Error;
413  }) != Errors.end();
414 
415  const bool DisableFixes = Fix && FoundErrors && !FixErrors;
416 
417  unsigned WErrorCount = 0;
418 
419  // -fix-errors implies -fix.
420  handleErrors(Context, (FixErrors || Fix) && !DisableFixes, WErrorCount);
421 
422  if (!ExportFixes.empty() && !Errors.empty()) {
423  std::error_code EC;
424  llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::F_None);
425  if (EC) {
426  llvm::errs() << "Error opening output file: " << EC.message() << '\n';
427  return 1;
428  }
429  exportReplacements(FilePath.str(), Errors, OS);
430  }
431 
432  if (!Quiet) {
433  printStats(Context.getStats());
434  if (DisableFixes)
435  llvm::errs()
436  << "Found compiler errors, but -fix-errors was not specified.\n"
437  "Fixes have NOT been applied.\n\n";
438  }
439 
440  if (EnableCheckProfile)
441  printProfileData(Profile, llvm::errs());
442 
443  if (WErrorCount) {
444  if (!Quiet) {
445  StringRef Plural = WErrorCount == 1 ? "" : "s";
446  llvm::errs() << WErrorCount << " warning" << Plural << " treated as error"
447  << Plural << "\n";
448  }
449  return WErrorCount;
450  }
451 
452  return 0;
453 }
454 
455 // This anchor is used to force the linker to link the CERTModule.
456 extern volatile int CERTModuleAnchorSource;
457 static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
459 
460 // This anchor is used to force the linker to link the BoostModule.
461 extern volatile int BoostModuleAnchorSource;
462 static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
464 
465 // This anchor is used to force the linker to link the BugproneModule.
466 extern volatile int BugproneModuleAnchorSource;
467 static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
469 
470 // This anchor is used to force the linker to link the LLVMModule.
471 extern volatile int LLVMModuleAnchorSource;
472 static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
474 
475 // This anchor is used to force the linker to link the CppCoreGuidelinesModule.
476 extern volatile int CppCoreGuidelinesModuleAnchorSource;
477 static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
479 
480 // This anchor is used to force the linker to link the GoogleModule.
481 extern volatile int GoogleModuleAnchorSource;
482 static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
484 
485 // This anchor is used to force the linker to link the AndroidModule.
486 extern volatile int AndroidModuleAnchorSource;
487 static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
489 
490 // This anchor is used to force the linker to link the MiscModule.
491 extern volatile int MiscModuleAnchorSource;
492 static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
494 
495 // This anchor is used to force the linker to link the ModernizeModule.
496 extern volatile int ModernizeModuleAnchorSource;
497 static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
499 
500 // This anchor is used to force the linker to link the MPIModule.
501 extern volatile int MPIModuleAnchorSource;
502 static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
504 
505 // This anchor is used to force the linker to link the PerformanceModule.
506 extern volatile int PerformanceModuleAnchorSource;
507 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
509 
510 // This anchor is used to force the linker to link the ReadabilityModule.
511 extern volatile int ReadabilityModuleAnchorSource;
512 static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
514 
515 // This anchor is used to force the linker to link the HICPPModule.
516 extern volatile int HICPPModuleAnchorSource;
517 static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
519 
520 } // namespace tidy
521 } // namespace clang
522 
523 int main(int argc, const char **argv) {
524  return clang::tidy::clangTidyMain(argc, argv);
525 }
volatile int GoogleModuleAnchorSource
SetLongJmpCheck & Check
static void printStats(const ClangTidyStats &Stats)
static cl::opt< bool > SystemHeaders("system-headers", cl::desc("Display the errors from system headers."), cl::init(false), cl::cat(ClangTidyCategory))
Read-only set of strings represented as a list of positive and negative globs.
volatile int ReadabilityModuleAnchorSource
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))
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 'HeaderFilter' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
bool contains(StringRef S)
Returns true if the pattern matches S.
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))
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))
ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options)
Returns the effective check-specific options.
Definition: ClangTidy.cpp:467
static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination
volatile int AndroidModuleAnchorSource
void runClangTidy(clang::tidy::ClangTidyContext &Context, const CompilationDatabase &Compilations, ArrayRef< std::string > InputFiles, ProfileData *Profile)
Definition: ClangTidy.cpp:475
std::error_code parseLineFilter(StringRef LineFilter, clang::tidy::ClangTidyGlobalOptions &Options)
Parses -line-filter option and stores it to the Options.
static cl::opt< bool > AnalyzeTemporaryDtors("analyze-temporary-dtors", cl::desc(R"( Enable temporary destructor-aware analysis in clang-analyzer- checks. This option overrides the value read from a .clang-tidy file. )"), cl::init(false), cl::cat(ClangTidyCategory))
llvm::ErrorOr< ClangTidyOptions > parseConfiguration(StringRef Config)
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))
volatile int LLVMModuleAnchorSource
volatile int PerformanceModuleAnchorSource
volatile int CppCoreGuidelinesModuleAnchorSource
static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination
static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination
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))
volatile int MPIModuleAnchorSource
volatile int HICPPModuleAnchorSource
static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination
std::string configurationAsText(const ClangTidyOptions &Options)
Serializes configuration to a YAML-encoded string.
volatile int CERTModuleAnchorSource
static cl::OptionCategory ClangTidyCategory("clang-tidy options")
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))
static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination
std::vector< std::string > getCheckNames(const ClangTidyOptions &Options)
Fills the list of check names that are enabled when the provided filters are applied.
Definition: ClangTidy.cpp:459
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))
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))
static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage)
void handleErrors(ClangTidyContext &Context, bool Fix, unsigned &WarningsAsErrorsCount)
Displays the found Errors to the users.
Definition: ClangTidy.cpp:548
static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination
static void printProfileData(const ProfileData &Profile, llvm::raw_ostream &OS)
volatile int BoostModuleAnchorSource
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))
volatile int MiscModuleAnchorSource
static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination
volatile int BugproneModuleAnchorSource
static int clangTidyMain(int argc, const char **argv)
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination
static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination
void exportReplacements(const llvm::StringRef MainFilePath, const std::vector< ClangTidyError > &Errors, raw_ostream &OS)
Definition: ClangTidy.cpp:573
const char DefaultChecks[]
static std::unique_ptr< ClangTidyOptionsProvider > createOptionsProvider()
int main(int argc, const char **argv)
Contains displayed and ignored diagnostic counters for a ClangTidy run.
ClangTidyContext & Context
Definition: ClangTidy.cpp:87
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))
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 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: '' AnalyzeTemporaryDtors: false FormatStyle: none User: user CheckOptions: - key: some-check.SomeOption value: 'some value' ... )")
volatile int ModernizeModuleAnchorSource
static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination
static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination
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))
static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination
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))
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))