clang-tools 22.0.0git
ClangTidyOptions.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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#include "ClangTidyOptions.h"
11#include "clang/Basic/DiagnosticIDs.h"
12#include "clang/Basic/LLVM.h"
13#include "llvm/ADT/SmallString.h"
14#include "llvm/ADT/StringExtras.h"
15#include "llvm/Support/Debug.h"
16#include "llvm/Support/ErrorOr.h"
17#include "llvm/Support/MemoryBufferRef.h"
18#include "llvm/Support/Path.h"
19#include "llvm/Support/YAMLTraits.h"
20#include <algorithm>
21#include <optional>
22#include <utility>
23
24#define DEBUG_TYPE "clang-tidy-options"
25
29
30LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter)
31LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter::LineRange)
32
33namespace llvm::yaml {
34
35// Map std::pair<int, int> to a JSON array of size 2.
36template <> struct SequenceTraits<FileFilter::LineRange> {
37 static size_t size(IO &IO, FileFilter::LineRange &Range) {
38 return Range.first == 0 ? 0 : Range.second == 0 ? 1 : 2;
39 }
40 static unsigned &element(IO &IO, FileFilter::LineRange &Range, size_t Index) {
41 if (Index > 1)
42 IO.setError("Too many elements in line range.");
43 return Index == 0 ? Range.first : Range.second;
44 }
45};
46
47template <> struct MappingTraits<FileFilter> {
48 static void mapping(IO &IO, FileFilter &File) {
49 IO.mapRequired("name", File.Name);
50 IO.mapOptional("lines", File.LineRanges);
51 }
52 static std::string validate(IO &Io, FileFilter &File) {
53 if (File.Name.empty())
54 return "No file name specified";
55 for (const FileFilter::LineRange &Range : File.LineRanges) {
56 if (Range.first <= 0 || Range.second <= 0)
57 return "Invalid line range";
58 }
59 return "";
60 }
61};
62
63template <> struct MappingTraits<ClangTidyOptions::StringPair> {
64 static void mapping(IO &IO, ClangTidyOptions::StringPair &KeyValue) {
65 IO.mapRequired("key", KeyValue.first);
66 IO.mapRequired("value", KeyValue.second);
67 }
68};
69
70struct NOptionMap {
71 NOptionMap(IO &) {}
72 NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
73 Options.reserve(OptionMap.size());
74 for (const auto &KeyValue : OptionMap)
75 Options.emplace_back(std::string(KeyValue.getKey()),
76 KeyValue.getValue().Value);
77 }
80 for (const auto &KeyValue : Options)
81 Map[KeyValue.first] = ClangTidyOptions::ClangTidyValue(KeyValue.second);
82 return Map;
83 }
84 std::vector<ClangTidyOptions::StringPair> Options;
85};
86
87template <>
88void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
89 EmptyContext &Ctx) {
90 if (IO.outputting()) {
91 // Ensure check options are sorted
92 std::vector<std::pair<StringRef, StringRef>> SortedOptions;
93 SortedOptions.reserve(Val.size());
94 for (auto &Key : Val) {
95 SortedOptions.emplace_back(Key.getKey(), Key.getValue().Value);
96 }
97 std::sort(SortedOptions.begin(), SortedOptions.end());
98
99 IO.beginMapping();
100 // Only output as a map
101 for (auto &Option : SortedOptions) {
102 bool UseDefault = false;
103 void *SaveInfo = nullptr;
104 // Requires 'llvm::yaml::IO' to accept 'StringRef'
105 // NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
106 IO.preflightKey(Option.first.data(), true, false, UseDefault, SaveInfo);
107 IO.scalarString(Option.second, needsQuotes(Option.second));
108 IO.postflightKey(SaveInfo);
109 }
110 IO.endMapping();
111 } else {
112 // We need custom logic here to support the old method of specifying check
113 // options using a list of maps containing key and value keys.
114 auto &I = reinterpret_cast<Input &>(IO);
115 if (isa<SequenceNode>(I.getCurrentNode())) {
116 MappingNormalization<NOptionMap, ClangTidyOptions::OptionMap> NOpts(IO,
117 Val);
118 EmptyContext Ctx;
119 yamlize(IO, NOpts->Options, true, Ctx);
120 } else if (isa<MappingNode>(I.getCurrentNode())) {
121 IO.beginMapping();
122 for (StringRef Key : IO.keys()) {
123 // Requires 'llvm::yaml::IO' to accept 'StringRef'
124 // NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
125 IO.mapRequired(Key.data(), Val[Key].Value);
126 }
127 IO.endMapping();
128 } else {
129 IO.setError("expected a sequence or map");
130 }
131 }
132}
133
134namespace {
135struct MultiLineString {
136 std::string &S;
137};
138} // namespace
139
140template <> struct BlockScalarTraits<MultiLineString> {
141 static void output(const MultiLineString &S, void *Ctxt, raw_ostream &OS) {
142 OS << S.S;
143 }
144 static StringRef input(StringRef Str, void *Ctxt, MultiLineString &S) {
145 S.S = Str;
146 return "";
147 }
148};
149
150template <> struct ScalarEnumerationTraits<clang::DiagnosticIDs::Level> {
151 static void enumeration(IO &IO, clang::DiagnosticIDs::Level &Level) {
152 IO.enumCase(Level, "Warning", clang::DiagnosticIDs::Level::Warning);
153 IO.enumCase(Level, "Note", clang::DiagnosticIDs::Level::Note);
154 }
155};
156template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckDiag> {
157 static const bool flow = false;
158};
159template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
161 IO.mapRequired("BindName", D.BindName);
162 MultiLineString MLS{D.Message};
163 IO.mapRequired("Message", MLS);
164 IO.mapOptional("Level", D.Level);
165 }
166};
167template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
168 static const bool flow = false;
169};
170template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
172 IO.mapRequired("Name", V.Name);
173 MultiLineString MLS{V.Query};
174 IO.mapRequired("Query", MLS);
175 IO.mapRequired("Diagnostic", V.Diags);
176 }
177};
178
180 std::optional<std::string> AsString;
181 std::optional<std::vector<std::string>> AsVector;
182};
183
184template <> void yamlize(IO &IO, ChecksVariant &Val, bool, EmptyContext &Ctx) {
185 if (!IO.outputting()) {
186 // Special case for reading from YAML
187 // Must support reading from both a string or a list
188 auto &I = reinterpret_cast<Input &>(IO);
189 if (isa<ScalarNode, BlockScalarNode>(I.getCurrentNode())) {
190 Val.AsString = std::string();
191 yamlize(IO, *Val.AsString, true, Ctx);
192 } else if (isa<SequenceNode>(I.getCurrentNode())) {
193 Val.AsVector = std::vector<std::string>();
194 yamlize(IO, *Val.AsVector, true, Ctx);
195 } else {
196 IO.setError("expected string or sequence");
197 }
198 }
199}
200
201static void mapChecks(IO &IO, std::optional<std::string> &Checks) {
202 if (IO.outputting()) {
203 // Output always a string
204 IO.mapOptional("Checks", Checks);
205 } else {
206 // Input as either a string or a list
207 ChecksVariant ChecksAsVariant;
208 IO.mapOptional("Checks", ChecksAsVariant);
209 if (ChecksAsVariant.AsString)
210 Checks = ChecksAsVariant.AsString;
211 else if (ChecksAsVariant.AsVector)
212 Checks = llvm::join(*ChecksAsVariant.AsVector, ",");
213 }
214}
215
216template <> struct MappingTraits<ClangTidyOptions> {
217 static void mapping(IO &IO, ClangTidyOptions &Options) {
218 mapChecks(IO, Options.Checks);
219 IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
220 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
221 IO.mapOptional("ImplementationFileExtensions",
223 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
224 IO.mapOptional("ExcludeHeaderFilterRegex",
226 IO.mapOptional("FormatStyle", Options.FormatStyle);
227 IO.mapOptional("User", Options.User);
228 IO.mapOptional("CheckOptions", Options.CheckOptions);
229 IO.mapOptional("ExtraArgs", Options.ExtraArgs);
230 IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
231 IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
232 IO.mapOptional("UseColor", Options.UseColor);
233 IO.mapOptional("SystemHeaders", Options.SystemHeaders);
234 IO.mapOptional("CustomChecks", Options.CustomChecks);
235 }
236};
237
238} // namespace llvm::yaml
239
240namespace clang::tidy {
241
243 ClangTidyOptions Options;
244 Options.Checks = "";
245 Options.WarningsAsErrors = "";
246 Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
247 Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
248 Options.HeaderFilterRegex = "";
249 Options.ExcludeHeaderFilterRegex = "";
250 Options.SystemHeaders = false;
251 Options.FormatStyle = "none";
252 Options.User = std::nullopt;
253 for (const ClangTidyModuleRegistry::entry &Module :
254 ClangTidyModuleRegistry::entries())
255 Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
256 return Options;
257}
258
259template <typename T>
260static void mergeVectors(std::optional<T> &Dest, const std::optional<T> &Src) {
261 if (Src) {
262 if (Dest)
263 Dest->insert(Dest->end(), Src->begin(), Src->end());
264 else
265 Dest = Src;
266 }
267}
268
269static void mergeCommaSeparatedLists(std::optional<std::string> &Dest,
270 const std::optional<std::string> &Src) {
271 if (Src)
272 Dest = (Dest && !Dest->empty() ? *Dest + "," : "") + *Src;
273}
274
275template <typename T>
276static void overrideValue(std::optional<T> &Dest, const std::optional<T> &Src) {
277 if (Src)
278 Dest = Src;
279}
280
282 unsigned Order) {
292 overrideValue(User, Other.User);
296 // FIXME: how to handle duplicate names check?
298 for (const auto &KeyValue : Other.CheckOptions) {
299 CheckOptions.insert_or_assign(
300 KeyValue.getKey(),
301 ClangTidyValue(KeyValue.getValue().Value,
302 KeyValue.getValue().Priority + Order));
303 }
304 return *this;
305}
306
308 unsigned Order) const {
309 ClangTidyOptions Result = *this;
310 Result.mergeWith(Other, Order);
311 return Result;
312}
313
315 "clang-tidy binary";
317 "command-line option '-checks'";
318const char
320 "command-line option '-config'";
321
323ClangTidyOptionsProvider::getOptions(llvm::StringRef FileName) {
324 ClangTidyOptions Result;
325 unsigned Priority = 0;
326 for (auto &Source : getRawOptions(FileName))
327 Result.mergeWith(Source.first, ++Priority);
328 return Result;
329}
330
331std::vector<OptionsSource>
332DefaultOptionsProvider::getRawOptions(llvm::StringRef FileName) {
333 std::vector<OptionsSource> Result;
334 Result.emplace_back(DefaultOptions, OptionsSourceTypeDefaultBinary);
335 return Result;
336}
337
339 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
341 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
342 : FileOptionsBaseProvider(std::move(GlobalOptions),
343 std::move(DefaultOptions),
344 std::move(OverrideOptions), std::move(FS)),
345 ConfigOptions(std::move(ConfigOptions)) {}
346
347std::vector<OptionsSource>
348ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
349 std::vector<OptionsSource> RawOptions =
351 if (ConfigOptions.InheritParentConfig.value_or(false)) {
352 LLVM_DEBUG(llvm::dbgs()
353 << "Getting options for file " << FileName << "...\n");
354
355 llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
357 if (AbsoluteFilePath) {
358 addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
359 }
360 }
361 RawOptions.emplace_back(ConfigOptions,
363 RawOptions.emplace_back(OverrideOptions,
365 return RawOptions;
366}
367
369 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
371 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
372 : DefaultOptionsProvider(std::move(GlobalOptions),
373 std::move(DefaultOptions)),
374 OverrideOptions(std::move(OverrideOptions)), FS(std::move(VFS)) {
375 if (!FS)
376 FS = llvm::vfs::getRealFileSystem();
377 ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
378}
379
388
389llvm::ErrorOr<llvm::SmallString<128>>
391 assert(FS && "FS must be set.");
392 llvm::SmallString<128> NormalizedAbsolutePath = {Path};
393 std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
394 if (Err)
395 return Err;
396 llvm::sys::path::remove_dots(NormalizedAbsolutePath, /*remove_dot_dot=*/true);
397 return NormalizedAbsolutePath;
398}
399
401 llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
402 auto CurSize = CurOptions.size();
403 // Look for a suitable configuration file in all parent directories of the
404 // file. Start with the immediate parent directory and move up.
405 StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
406 auto MemorizedConfigFile =
407 [this, &RootPath](StringRef CurrentPath) -> std::optional<OptionsSource> {
408 const auto Iter = CachedOptions.Memorized.find(CurrentPath);
409 if (Iter != CachedOptions.Memorized.end())
410 return CachedOptions.Storage[Iter->second];
411 std::optional<OptionsSource> OptionsSource = tryReadConfigFile(CurrentPath);
412 if (OptionsSource) {
413 const size_t Index = CachedOptions.Storage.size();
414 CachedOptions.Storage.emplace_back(OptionsSource.value());
415 while (RootPath != CurrentPath) {
416 LLVM_DEBUG(llvm::dbgs()
417 << "Caching configuration for path " << RootPath << ".\n");
418 CachedOptions.Memorized[RootPath] = Index;
419 RootPath = llvm::sys::path::parent_path(RootPath);
420 }
421 CachedOptions.Memorized[CurrentPath] = Index;
422 RootPath = llvm::sys::path::parent_path(CurrentPath);
423 }
424 return OptionsSource;
425 };
426 for (StringRef CurrentPath = RootPath; !CurrentPath.empty();
427 CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
428 if (std::optional<OptionsSource> Result =
429 MemorizedConfigFile(CurrentPath)) {
430 CurOptions.emplace_back(Result.value());
431 if (!Result->first.InheritParentConfig.value_or(false))
432 break;
433 }
434 }
435 // Reverse order of file configs because closer configs should have higher
436 // priority.
437 std::reverse(CurOptions.begin() + CurSize, CurOptions.end());
438}
439
441 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
443 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
444 : FileOptionsBaseProvider(std::move(GlobalOptions),
445 std::move(DefaultOptions),
446 std::move(OverrideOptions), std::move(VFS)) {}
447
455
456// FIXME: This method has some common logic with clang::format::getStyle().
457// Consider pulling out common bits to a findParentFileWithName function or
458// similar.
459std::vector<OptionsSource>
461 LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
462 << "...\n");
463
464 llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
466 if (!AbsoluteFilePath)
467 return {};
468
469 std::vector<OptionsSource> RawOptions =
470 DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
471 addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
472 OptionsSource CommandLineOptions(OverrideOptions,
474
475 RawOptions.push_back(CommandLineOptions);
476 return RawOptions;
477}
478
479std::optional<OptionsSource>
481 assert(!Directory.empty());
482
483 llvm::ErrorOr<llvm::vfs::Status> DirectoryStatus = FS->status(Directory);
484
485 if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
486 llvm::errs() << "Error reading configuration from " << Directory
487 << ": directory doesn't exist.\n";
488 return std::nullopt;
489 }
490
491 for (const ConfigFileHandler &ConfigHandler : ConfigHandlers) {
492 SmallString<128> ConfigFile(Directory);
493 llvm::sys::path::append(ConfigFile, ConfigHandler.first);
494 LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
495
496 llvm::ErrorOr<llvm::vfs::Status> FileStatus = FS->status(ConfigFile);
497
498 if (!FileStatus || !FileStatus->isRegularFile())
499 continue;
500
501 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
502 FS->getBufferForFile(ConfigFile);
503 if (std::error_code EC = Text.getError()) {
504 llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
505 << "\n";
506 continue;
507 }
508
509 // Skip empty files, e.g. files opened for writing via shell output
510 // redirection.
511 if ((*Text)->getBuffer().empty())
512 continue;
513 llvm::ErrorOr<ClangTidyOptions> ParsedOptions =
514 ConfigHandler.second({(*Text)->getBuffer(), ConfigFile});
515 if (!ParsedOptions) {
516 if (ParsedOptions.getError())
517 llvm::errs() << "Error parsing " << ConfigFile << ": "
518 << ParsedOptions.getError().message() << "\n";
519 continue;
520 }
521 return OptionsSource(*ParsedOptions, std::string(ConfigFile));
522 }
523 return std::nullopt;
524}
525
526/// Parses -line-filter option and stores it to the \c Options.
527std::error_code parseLineFilter(StringRef LineFilter,
529 llvm::yaml::Input Input(LineFilter);
530 Input >> Options.LineFilter;
531 return Input.error();
532}
533
534llvm::ErrorOr<ClangTidyOptions>
535parseConfiguration(llvm::MemoryBufferRef Config) {
536 llvm::yaml::Input Input(Config);
537 ClangTidyOptions Options;
538 Input >> Options;
539 if (Input.error())
540 return Input.error();
541 return Options;
542}
543
544static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx) {
545 (*reinterpret_cast<DiagCallback *>(Ctx))(Diag);
546}
547
548llvm::ErrorOr<ClangTidyOptions>
550 DiagCallback Handler) {
551 llvm::yaml::Input Input(Config, nullptr, Handler ? diagHandlerImpl : nullptr,
552 &Handler);
553 ClangTidyOptions Options;
554 Input >> Options;
555 if (Input.error())
556 return Input.error();
557 return Options;
558}
559
560std::string configurationAsText(const ClangTidyOptions &Options) {
561 std::string Text;
562 llvm::raw_string_ostream Stream(Text);
563 llvm::yaml::Output Output(Stream);
564 // We use the same mapping method for input and output, so we need a non-const
565 // reference here.
566 ClangTidyOptions NonConstValue = Options;
567 Output << NonConstValue;
568 return Stream.str();
569}
570
571} // namespace clang::tidy
static cl::opt< std::string > Directory(cl::Positional, cl::Required, cl::desc("<Search Root Directory>"))
static cl::opt< std::string > ConfigFile("config-file", desc(R"( Specify the path of .clang-tidy or custom config file: e.g. --config-file=/some/path/myTidyConfigFile This option internally works exactly the same way as --config option after reading specified config file. Use either --config-file or --config, not both. )"), cl::init(""), cl::cat(ClangTidyCategory))
static cl::opt< std::string > Config("config", desc(R"( Specifies a configuration in YAML/JSON format: -config="{Checks:' *', CheckOptions:{x: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< std::string > LineFilter("line-filter", desc(R"( List of files and line ranges to output diagnostics from. The range is inclusive on both ends. Can be used together with -header-filter. The format of the list is a JSON array of objects. For example: [ {"name":"file1.cpp","lines":[[1,3],[5,7]]}, {"name":"file2.h"} ] This will output diagnostics from 'file1.cpp' only for the line ranges [1,3] and [5,7], as well as all from the entire 'file2.h'. )"), cl::init(""), cl::cat(ClangTidyCategory))
static cl::opt< std::string > Checks("checks", 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))
clang::tidy::ClangTidyOptionsProvider::OptionsSource OptionsSource
ClangTidyOptions getOptions(llvm::StringRef FileName)
Returns options applying to a specific translation unit with the specified FileName.
static const char OptionsSourceTypeCheckCommandLineOption[]
virtual std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName)=0
Returns an ordered vector of OptionsSources, in order of increasing priority.
std::pair< ClangTidyOptions, std::string > OptionsSource
ClangTidyOptions and its source.
static const char OptionsSourceTypeConfigCommandLineOption[]
static const char OptionsSourceTypeDefaultBinary[]
ConfigOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
DefaultOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions Options)
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
struct clang::tidy::FileOptionsBaseProvider::OptionsCache CachedOptions
std::pair< std::string, std::function< llvm::ErrorOr< ClangTidyOptions >( llvm::MemoryBufferRef)> > ConfigFileHandler
llvm::ErrorOr< llvm::SmallString< 128 > > getNormalizedAbsolutePath(llvm::StringRef AbsolutePath)
std::optional< OptionsSource > tryReadConfigFile(llvm::StringRef Directory)
Try to read configuration files from Directory using registered ConfigHandlers.
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS
FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
std::vector< ConfigFileHandler > ConfigFileHandlers
Configuration file handlers listed in the order of priority.
void addRawFileOptions(llvm::StringRef AbsolutePath, std::vector< OptionsSource > &CurOptions)
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
FileOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
Initializes the FileOptionsProvider instance.
std::error_code parseLineFilter(StringRef LineFilter, clang::tidy::ClangTidyGlobalOptions &Options)
Parses -line-filter option and stores it to the Options.
static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx)
static void mergeVectors(std::optional< T > &Dest, const std::optional< T > &Src)
llvm::ErrorOr< ClangTidyOptions > parseConfigurationWithDiags(llvm::MemoryBufferRef Config, DiagCallback Handler)
llvm::function_ref< void(const llvm::SMDiagnostic &)> DiagCallback
static void mergeCommaSeparatedLists(std::optional< std::string > &Dest, const std::optional< std::string > &Src)
std::string configurationAsText(const ClangTidyOptions &Options)
Serializes configuration to a YAML-encoded string.
llvm::ErrorOr< ClangTidyOptions > parseConfiguration(llvm::MemoryBufferRef Config)
Parses configuration from JSON and returns ClangTidyOptions or an error.
static void overrideValue(std::optional< T > &Dest, const std::optional< T > &Src)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static void mapChecks(IO &IO, std::optional< std::string > &Checks)
void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool, EmptyContext &Ctx)
Helper structure for storing option value with priority of the value.
llvm::SmallVector< CustomCheckDiag > Diags
std::pair< std::string, std::string > StringPair
llvm::StringMap< ClangTidyValue > OptionMap
std::pair< unsigned int, unsigned int > LineRange
LineRange is a pair<start, end> (inclusive).
std::vector< FileFilter > LineFilter
Output warnings from certain line ranges of certain files only.
Helper structure for storing option value with priority of the value.
Contains options for clang-tidy.
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
ClangTidyOptions merge(const ClangTidyOptions &Other, unsigned Order) const
Creates a new ClangTidyOptions instance combined from all fields of this instance overridden by the f...
std::optional< bool > InheritParentConfig
Only used in the FileOptionsProvider and ConfigOptionsProvider.
std::optional< std::string > HeaderFilterRegex
Output warnings from headers matching this filter.
std::optional< std::string > Checks
Checks filter.
std::optional< std::string > WarningsAsErrors
WarningsAsErrors filter.
std::optional< std::vector< std::string > > ImplementationFileExtensions
File extensions to consider to determine if a given diagnostic is located is located in an implementa...
ClangTidyOptions & mergeWith(const ClangTidyOptions &Other, unsigned Order)
Overwrites all fields in here by the fields of Other that have a value.
std::optional< std::string > User
Specifies the name or e-mail of the user running clang-tidy.
std::optional< std::vector< std::string > > HeaderFileExtensions
File extensions to consider to determine if a given diagnostic is located in a header file.
std::optional< bool > UseColor
Use colors in diagnostics. If missing, it will be auto detected.
std::optional< bool > SystemHeaders
Output warnings from system headers matching HeaderFilterRegex.
static ClangTidyOptions getDefaults()
These options are used for all settings that haven't been overridden by the OptionsProvider.
std::optional< CustomCheckValueList > CustomChecks
std::optional< std::string > ExcludeHeaderFilterRegex
Exclude warnings from headers matching this filter, even if they match HeaderFilterRegex.
std::optional< ArgList > ExtraArgsBefore
Add extra compilation arguments to the start of the list.
std::optional< std::string > FormatStyle
Format code around applied fixes with clang-format using this style.
std::optional< ArgList > ExtraArgs
Add extra compilation arguments to the end of the list.
Contains a list of line ranges in a single file.
static void output(const MultiLineString &S, void *Ctxt, raw_ostream &OS)
static StringRef input(StringRef Str, void *Ctxt, MultiLineString &S)
std::optional< std::string > AsString
std::optional< std::vector< std::string > > AsVector
static void mapping(IO &IO, ClangTidyOptions &Options)
static void mapping(IO &IO, ClangTidyOptions::CustomCheckDiag &D)
static void mapping(IO &IO, ClangTidyOptions::CustomCheckValue &V)
static void mapping(IO &IO, ClangTidyOptions::StringPair &KeyValue)
static std::string validate(IO &Io, FileFilter &File)
static void mapping(IO &IO, FileFilter &File)
ClangTidyOptions::OptionMap denormalize(IO &)
NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap)
std::vector< ClangTidyOptions::StringPair > Options
static void enumeration(IO &IO, clang::DiagnosticIDs::Level &Level)
static unsigned & element(IO &IO, FileFilter::LineRange &Range, size_t Index)
static size_t size(IO &IO, FileFilter::LineRange &Range)