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