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