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"
10#include "ClangTidyModule.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 return "";
59 }
60};
61
62template <> struct MappingTraits<ClangTidyOptions::StringPair> {
63 static void mapping(IO &IO, ClangTidyOptions::StringPair &KeyValue) {
64 IO.mapRequired("key", KeyValue.first);
65 IO.mapRequired("value", KeyValue.second);
66 }
67};
68
69namespace {
70
71struct NOptionMap {
72 NOptionMap(IO &) {}
73 NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
74 Options.reserve(OptionMap.size());
75 for (const auto &KeyValue : OptionMap)
76 Options.emplace_back(std::string(KeyValue.getKey()),
77 KeyValue.getValue().Value);
78 }
79 ClangTidyOptions::OptionMap denormalize(IO &) {
81 for (const auto &KeyValue : Options)
82 Map[KeyValue.first] = ClangTidyOptions::ClangTidyValue(KeyValue.second);
83 return Map;
84 }
85 std::vector<ClangTidyOptions::StringPair> Options;
86};
87
88} // namespace
89
90template <>
91void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
92 EmptyContext &Ctx) {
93 if (IO.outputting()) {
94 // Ensure check options are sorted
95 std::vector<std::pair<StringRef, StringRef>> SortedOptions;
96 SortedOptions.reserve(Val.size());
97 for (auto &Key : Val)
98 SortedOptions.emplace_back(Key.getKey(), Key.getValue().Value);
99 std::sort(SortedOptions.begin(), SortedOptions.end());
100
101 IO.beginMapping();
102 // Only output as a map
103 for (auto &Option : SortedOptions) {
104 bool UseDefault = false;
105 void *SaveInfo = nullptr;
106 // Requires 'llvm::yaml::IO' to accept 'StringRef'
107 // NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
108 IO.preflightKey(Option.first.data(), true, false, UseDefault, SaveInfo);
109 IO.scalarString(Option.second, needsQuotes(Option.second));
110 IO.postflightKey(SaveInfo);
111 }
112 IO.endMapping();
113 } else {
114 // We need custom logic here to support the old method of specifying check
115 // options using a list of maps containing key and value keys.
116 auto &I = reinterpret_cast<Input &>(IO);
117 if (isa<SequenceNode>(I.getCurrentNode())) {
118 MappingNormalization<NOptionMap, ClangTidyOptions::OptionMap> NOpts(IO,
119 Val);
120 EmptyContext Ctx;
121 yamlize(IO, NOpts->Options, true, Ctx);
122 } else if (isa<MappingNode>(I.getCurrentNode())) {
123 IO.beginMapping();
124 for (const StringRef Key : IO.keys()) {
125 // Requires 'llvm::yaml::IO' to accept 'StringRef'
126 // NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
127 IO.mapRequired(Key.data(), Val[Key].Value);
128 }
129 IO.endMapping();
130 } else {
131 IO.setError("expected a sequence or map");
132 }
133 }
134}
135
136namespace {
137struct MultiLineString {
138 std::string &S;
139};
140} // namespace
141
142template <> struct BlockScalarTraits<MultiLineString> {
143 static void output(const MultiLineString &S, void *Ctxt, raw_ostream &OS) {
144 OS << S.S;
145 }
146 static StringRef input(StringRef Str, void *Ctxt, MultiLineString &S) {
147 S.S = Str;
148 return "";
149 }
150};
151
152template <> struct ScalarEnumerationTraits<clang::DiagnosticIDs::Level> {
153 static void enumeration(IO &IO, clang::DiagnosticIDs::Level &Level) {
154 IO.enumCase(Level, "Warning", clang::DiagnosticIDs::Level::Warning);
155 IO.enumCase(Level, "Note", clang::DiagnosticIDs::Level::Note);
156 }
157};
158template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckDiag> {
159 // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
160 static constexpr bool flow = false;
161};
162template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
164 IO.mapRequired("BindName", D.BindName);
165 MultiLineString MLS{D.Message};
166 IO.mapRequired("Message", MLS);
167 IO.mapOptional("Level", D.Level);
168 }
169};
170template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
171 // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
172 static constexpr bool flow = false;
173};
174template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
176 IO.mapRequired("Name", V.Name);
177 MultiLineString MLS{V.Query};
178 IO.mapRequired("Query", MLS);
179 IO.mapRequired("Diagnostic", V.Diags);
180 }
181};
182
183namespace {
184
185struct GlobListVariant {
186 std::optional<std::string> AsString;
187 std::optional<std::vector<std::string>> AsVector;
188};
189
190} // namespace
191
192template <>
193void yamlize(IO &IO, GlobListVariant &Val, bool, EmptyContext &Ctx) {
194 if (!IO.outputting()) {
195 // Special case for reading from YAML
196 // Must support reading from both a string or a list
197 auto &I = reinterpret_cast<Input &>(IO);
198 if (isa<ScalarNode, BlockScalarNode>(I.getCurrentNode())) {
199 Val.AsString = std::string();
200 yamlize(IO, *Val.AsString, true, Ctx);
201 } else if (isa<SequenceNode>(I.getCurrentNode())) {
202 Val.AsVector = std::vector<std::string>();
203 yamlize(IO, *Val.AsVector, true, Ctx);
204 } else {
205 IO.setError("expected string or sequence");
206 }
207 }
208}
209
210static void mapGlobList(IO &IO, std::optional<std::string> &GlobList,
211 StringRef Key) {
212 if (IO.outputting()) {
213 // Output always a string
214 IO.mapOptional(Key, GlobList);
215 } else {
216 // Input as either a string or a list
217 GlobListVariant GlobListAsVariant;
218 IO.mapOptional(Key, GlobListAsVariant);
219 if (GlobListAsVariant.AsString)
220 GlobList = GlobListAsVariant.AsString;
221 else if (GlobListAsVariant.AsVector)
222 GlobList = llvm::join(*GlobListAsVariant.AsVector, ",");
223 }
224}
225
226template <> struct MappingTraits<ClangTidyOptions> {
227 static void mapping(IO &IO, ClangTidyOptions &Options) {
228 mapGlobList(IO, Options.Checks, "Checks");
229 mapGlobList(IO, Options.WarningsAsErrors, "WarningsAsErrors");
230 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
231 IO.mapOptional("ImplementationFileExtensions",
233 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
234 IO.mapOptional("ExcludeHeaderFilterRegex",
236 IO.mapOptional("FormatStyle", Options.FormatStyle);
237 IO.mapOptional("User", Options.User);
238 IO.mapOptional("CheckOptions", Options.CheckOptions);
239 IO.mapOptional("ExtraArgs", Options.ExtraArgs);
240 IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
241 IO.mapOptional("RemovedArgs", Options.RemovedArgs);
242 IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
243 IO.mapOptional("UseColor", Options.UseColor);
244 IO.mapOptional("SystemHeaders", Options.SystemHeaders);
245 IO.mapOptional("CustomChecks", Options.CustomChecks);
246 }
247};
248
249} // namespace llvm::yaml
250
251namespace clang::tidy {
252
254 ClangTidyOptions Options;
255 Options.Checks = "";
256 Options.WarningsAsErrors = "";
257 Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
258 Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
259 Options.HeaderFilterRegex = ".*";
260 Options.ExcludeHeaderFilterRegex = "";
261 Options.SystemHeaders = false;
262 Options.FormatStyle = "none";
263 Options.User = std::nullopt;
264 Options.RemovedArgs = std::nullopt;
265 for (const ClangTidyModuleRegistry::entry &Module :
266 ClangTidyModuleRegistry::entries())
267 Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
268 return Options;
269}
270
271template <typename T>
272static void mergeVectors(std::optional<T> &Dest, const std::optional<T> &Src) {
273 if (Src) {
274 if (Dest)
275 Dest->insert(Dest->end(), Src->begin(), Src->end());
276 else
277 Dest = Src;
278 }
279}
280
281static void mergeCommaSeparatedLists(std::optional<std::string> &Dest,
282 const std::optional<std::string> &Src) {
283 if (Src)
284 Dest = (Dest && !Dest->empty() ? *Dest + "," : "") + *Src;
285}
286
287template <typename T>
288static void overrideValue(std::optional<T> &Dest, const std::optional<T> &Src) {
289 if (Src)
290 Dest = Src;
291}
292
294 unsigned Order) {
304 overrideValue(User, Other.User);
309 // FIXME: how to handle duplicate names check?
311 for (const auto &KeyValue : Other.CheckOptions) {
312 CheckOptions.insert_or_assign(
313 KeyValue.getKey(),
314 ClangTidyValue(KeyValue.getValue().Value,
315 KeyValue.getValue().Priority + Order));
316 }
317 return *this;
318}
319
321 unsigned Order) const {
322 ClangTidyOptions Result = *this;
323 Result.mergeWith(Other, Order);
324 return Result;
325}
326
328ClangTidyOptionsProvider::getOptions(llvm::StringRef FileName) {
329 ClangTidyOptions Result;
330 unsigned Priority = 0;
331 for (auto &Source : getRawOptions(FileName))
332 Result.mergeWith(Source.first, ++Priority);
333 return Result;
334}
335
336std::vector<OptionsSource>
337DefaultOptionsProvider::getRawOptions(llvm::StringRef FileName) {
338 std::vector<OptionsSource> Result;
339 Result.emplace_back(DefaultOptions, OptionsSourceTypeDefaultBinary);
340 return Result;
341}
342
344 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
346 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
347 : FileOptionsBaseProvider(std::move(GlobalOptions),
348 std::move(DefaultOptions),
349 std::move(OverrideOptions), std::move(FS)),
350 ConfigOptions(std::move(ConfigOptions)) {}
351
352std::vector<OptionsSource>
353ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
354 std::vector<OptionsSource> RawOptions =
356 if (ConfigOptions.InheritParentConfig.value_or(false)) {
357 LLVM_DEBUG(llvm::dbgs()
358 << "Getting options for file " << FileName << "...\n");
359
360 llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
362 if (AbsoluteFilePath)
363 addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
364 }
365 RawOptions.emplace_back(ConfigOptions,
367 RawOptions.emplace_back(OverrideOptions,
369 return RawOptions;
370}
371
373 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
375 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
376 : DefaultOptionsProvider(std::move(GlobalOptions),
377 std::move(DefaultOptions)),
378 OverrideOptions(std::move(OverrideOptions)), FS(std::move(VFS)) {
379 if (!FS)
380 FS = llvm::vfs::getRealFileSystem();
381 ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
382}
383
392
393llvm::ErrorOr<llvm::SmallString<128>>
395 assert(FS && "FS must be set.");
396 llvm::SmallString<128> NormalizedAbsolutePath = {Path};
397 const std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
398 if (Err)
399 return Err;
400 llvm::sys::path::remove_dots(NormalizedAbsolutePath, /*remove_dot_dot=*/true);
401 return NormalizedAbsolutePath;
402}
403
405 llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
406 auto CurSize = CurOptions.size();
407 // Look for a suitable configuration file in all parent directories of the
408 // file. Start with the immediate parent directory and move up.
409 StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
410 auto MemorizedConfigFile =
411 [this, &RootPath](StringRef CurrentPath) -> std::optional<OptionsSource> {
412 const auto Iter = CachedOptions.Memorized.find(CurrentPath);
413 if (Iter != CachedOptions.Memorized.end())
414 return CachedOptions.Storage[Iter->second];
415 std::optional<OptionsSource> OptionsSource = tryReadConfigFile(CurrentPath);
416 if (OptionsSource) {
417 const size_t Index = CachedOptions.Storage.size();
418 CachedOptions.Storage.emplace_back(OptionsSource.value());
419 while (RootPath != CurrentPath) {
420 LLVM_DEBUG(llvm::dbgs()
421 << "Caching configuration for path " << RootPath << ".\n");
422 CachedOptions.Memorized[RootPath] = Index;
423 RootPath = llvm::sys::path::parent_path(RootPath);
424 }
425 CachedOptions.Memorized[CurrentPath] = Index;
426 RootPath = llvm::sys::path::parent_path(CurrentPath);
427 }
428 return OptionsSource;
429 };
430 for (StringRef CurrentPath = RootPath; !CurrentPath.empty();
431 CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
432 if (std::optional<OptionsSource> Result =
433 MemorizedConfigFile(CurrentPath)) {
434 CurOptions.emplace_back(Result.value());
435 if (!Result->first.InheritParentConfig.value_or(false))
436 break;
437 }
438 }
439 // Reverse order of file configs because closer configs should have higher
440 // priority.
441 std::reverse(CurOptions.begin() + CurSize, CurOptions.end());
442}
443
445 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
447 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
448 : FileOptionsBaseProvider(std::move(GlobalOptions),
449 std::move(DefaultOptions),
450 std::move(OverrideOptions), std::move(VFS)) {}
451
459
460// FIXME: This method has some common logic with clang::format::getStyle().
461// Consider pulling out common bits to a findParentFileWithName function or
462// similar.
463std::vector<OptionsSource>
465 LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
466 << "...\n");
467
468 const llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
470 if (!AbsoluteFilePath)
471 return {};
472
473 std::vector<OptionsSource> RawOptions =
474 DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
475 addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
476 const OptionsSource CommandLineOptions(
478
479 RawOptions.push_back(CommandLineOptions);
480 return RawOptions;
481}
482
483std::optional<OptionsSource>
485 assert(!Directory.empty());
486
487 llvm::ErrorOr<llvm::vfs::Status> DirectoryStatus = FS->status(Directory);
488
489 if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
490 llvm::errs() << "Error reading configuration from " << Directory
491 << ": directory doesn't exist.\n";
492 return std::nullopt;
493 }
494
495 for (const ConfigFileHandler &ConfigHandler : ConfigHandlers) {
496 SmallString<128> ConfigFile(Directory);
497 llvm::sys::path::append(ConfigFile, ConfigHandler.first);
498 LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
499
500 llvm::ErrorOr<llvm::vfs::Status> FileStatus = FS->status(ConfigFile);
501
502 if (!FileStatus || !FileStatus->isRegularFile())
503 continue;
504
505 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
506 FS->getBufferForFile(ConfigFile);
507 if (const std::error_code EC = Text.getError()) {
508 llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
509 << "\n";
510 continue;
511 }
512
513 // Skip empty files, e.g. files opened for writing via shell output
514 // redirection.
515 if ((*Text)->getBuffer().empty())
516 continue;
517 llvm::ErrorOr<ClangTidyOptions> ParsedOptions =
518 ConfigHandler.second({(*Text)->getBuffer(), ConfigFile});
519 if (!ParsedOptions) {
520 if (ParsedOptions.getError())
521 llvm::errs() << "Error parsing " << ConfigFile << ": "
522 << ParsedOptions.getError().message() << "\n";
523 continue;
524 }
525 return OptionsSource(*ParsedOptions, std::string(ConfigFile));
526 }
527 return std::nullopt;
528}
529
530/// Parses -line-filter option and stores it to the \c Options.
531std::error_code parseLineFilter(StringRef LineFilter,
533 llvm::yaml::Input Input(LineFilter);
534 Input >> Options.LineFilter;
535 return Input.error();
536}
537
538llvm::ErrorOr<ClangTidyOptions>
539parseConfiguration(llvm::MemoryBufferRef Config) {
540 llvm::yaml::Input Input(Config);
541 ClangTidyOptions Options;
542 Input >> Options;
543 if (Input.error())
544 return Input.error();
545 return Options;
546}
547
548static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx) {
549 (*reinterpret_cast<DiagCallback *>(Ctx))(Diag);
550}
551
552llvm::ErrorOr<ClangTidyOptions>
554 DiagCallback Handler) {
555 llvm::yaml::Input Input(Config, nullptr, Handler ? diagHandlerImpl : nullptr,
556 &Handler);
557 ClangTidyOptions Options;
558 Input >> Options;
559 if (Input.error())
560 return Input.error();
561 return Options;
562}
563
564std::string configurationAsText(const ClangTidyOptions &Options) {
565 std::string Text;
566 llvm::raw_string_ostream Stream(Text);
567 llvm::yaml::Output Output(Stream);
568 // We use the same mapping method for input and output, so we need a non-const
569 // reference here.
570 ClangTidyOptions NonConstValue = Options;
571 Output << NonConstValue;
572 return Stream.str();
573}
574
575} // 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))
clang::tidy::ClangTidyOptionsProvider::OptionsSource OptionsSource
ClangTidyOptions getOptions(llvm::StringRef FileName)
Returns options applying to a specific translation unit with the specified FileName.
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 constexpr char OptionsSourceTypeConfigCommandLineOption[]
static constexpr char OptionsSourceTypeCheckCommandLineOption[]
static constexpr 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 mapGlobList(IO &IO, std::optional< std::string > &GlobList, StringRef Key)
void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool, EmptyContext &Ctx)
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...
std::optional< ArgList > RemovedArgs
Remove command line arguments sent to the compiler matching this.
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)
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)
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)