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