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 (const 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 // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
158 static const bool flow = false;
159};
160template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
162 IO.mapRequired("BindName", D.BindName);
163 MultiLineString MLS{D.Message};
164 IO.mapRequired("Message", MLS);
165 IO.mapOptional("Level", D.Level);
166 }
167};
168template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
169 // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
170 static const bool flow = false;
171};
172template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
174 IO.mapRequired("Name", V.Name);
175 MultiLineString MLS{V.Query};
176 IO.mapRequired("Query", MLS);
177 IO.mapRequired("Diagnostic", V.Diags);
178 }
179};
180
182 std::optional<std::string> AsString;
183 std::optional<std::vector<std::string>> AsVector;
184};
185
186template <>
187void yamlize(IO &IO, GlobListVariant &Val, bool, EmptyContext &Ctx) {
188 if (!IO.outputting()) {
189 // Special case for reading from YAML
190 // Must support reading from both a string or a list
191 auto &I = reinterpret_cast<Input &>(IO);
192 if (isa<ScalarNode, BlockScalarNode>(I.getCurrentNode())) {
193 Val.AsString = std::string();
194 yamlize(IO, *Val.AsString, true, Ctx);
195 } else if (isa<SequenceNode>(I.getCurrentNode())) {
196 Val.AsVector = std::vector<std::string>();
197 yamlize(IO, *Val.AsVector, true, Ctx);
198 } else {
199 IO.setError("expected string or sequence");
200 }
201 }
202}
203
204static void mapGlobList(IO &IO, std::optional<std::string> &GlobList,
205 StringRef Key) {
206 if (IO.outputting()) {
207 // Output always a string
208 IO.mapOptional(Key, GlobList);
209 } else {
210 // Input as either a string or a list
211 GlobListVariant GlobListAsVariant;
212 IO.mapOptional(Key, GlobListAsVariant);
213 if (GlobListAsVariant.AsString)
214 GlobList = GlobListAsVariant.AsString;
215 else if (GlobListAsVariant.AsVector)
216 GlobList = llvm::join(*GlobListAsVariant.AsVector, ",");
217 }
218}
219
220template <> struct MappingTraits<ClangTidyOptions> {
221 static void mapping(IO &IO, ClangTidyOptions &Options) {
222 mapGlobList(IO, Options.Checks, "Checks");
223 mapGlobList(IO, Options.WarningsAsErrors, "WarningsAsErrors");
224 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
225 IO.mapOptional("ImplementationFileExtensions",
227 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
228 IO.mapOptional("ExcludeHeaderFilterRegex",
230 IO.mapOptional("FormatStyle", Options.FormatStyle);
231 IO.mapOptional("User", Options.User);
232 IO.mapOptional("CheckOptions", Options.CheckOptions);
233 IO.mapOptional("ExtraArgs", Options.ExtraArgs);
234 IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
235 IO.mapOptional("RemovedArgs", Options.RemovedArgs);
236 IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
237 IO.mapOptional("UseColor", Options.UseColor);
238 IO.mapOptional("SystemHeaders", Options.SystemHeaders);
239 IO.mapOptional("CustomChecks", Options.CustomChecks);
240 }
241};
242
243} // namespace llvm::yaml
244
245namespace clang::tidy {
246
248 ClangTidyOptions Options;
249 Options.Checks = "";
250 Options.WarningsAsErrors = "";
251 Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
252 Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
253 Options.HeaderFilterRegex = ".*";
254 Options.ExcludeHeaderFilterRegex = "";
255 Options.SystemHeaders = false;
256 Options.FormatStyle = "none";
257 Options.User = std::nullopt;
258 Options.RemovedArgs = std::nullopt;
259 for (const ClangTidyModuleRegistry::entry &Module :
260 ClangTidyModuleRegistry::entries())
261 Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
262 return Options;
263}
264
265template <typename T>
266static void mergeVectors(std::optional<T> &Dest, const std::optional<T> &Src) {
267 if (Src) {
268 if (Dest)
269 Dest->insert(Dest->end(), Src->begin(), Src->end());
270 else
271 Dest = Src;
272 }
273}
274
275static void mergeCommaSeparatedLists(std::optional<std::string> &Dest,
276 const std::optional<std::string> &Src) {
277 if (Src)
278 Dest = (Dest && !Dest->empty() ? *Dest + "," : "") + *Src;
279}
280
281template <typename T>
282static void overrideValue(std::optional<T> &Dest, const std::optional<T> &Src) {
283 if (Src)
284 Dest = Src;
285}
286
288 unsigned Order) {
298 overrideValue(User, Other.User);
303 // FIXME: how to handle duplicate names check?
305 for (const auto &KeyValue : Other.CheckOptions) {
306 CheckOptions.insert_or_assign(
307 KeyValue.getKey(),
308 ClangTidyValue(KeyValue.getValue().Value,
309 KeyValue.getValue().Priority + Order));
310 }
311 return *this;
312}
313
315 unsigned Order) const {
316 ClangTidyOptions Result = *this;
317 Result.mergeWith(Other, Order);
318 return Result;
319}
320
322 "clang-tidy binary";
324 "command-line option '-checks'";
325const char
327 "command-line option '-config'";
328
330ClangTidyOptionsProvider::getOptions(llvm::StringRef FileName) {
331 ClangTidyOptions Result;
332 unsigned Priority = 0;
333 for (auto &Source : getRawOptions(FileName))
334 Result.mergeWith(Source.first, ++Priority);
335 return Result;
336}
337
338std::vector<OptionsSource>
339DefaultOptionsProvider::getRawOptions(llvm::StringRef FileName) {
340 std::vector<OptionsSource> Result;
341 Result.emplace_back(DefaultOptions, OptionsSourceTypeDefaultBinary);
342 return Result;
343}
344
346 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
348 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
349 : FileOptionsBaseProvider(std::move(GlobalOptions),
350 std::move(DefaultOptions),
351 std::move(OverrideOptions), std::move(FS)),
352 ConfigOptions(std::move(ConfigOptions)) {}
353
354std::vector<OptionsSource>
355ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
356 std::vector<OptionsSource> RawOptions =
358 if (ConfigOptions.InheritParentConfig.value_or(false)) {
359 LLVM_DEBUG(llvm::dbgs()
360 << "Getting options for file " << FileName << "...\n");
361
362 llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
364 if (AbsoluteFilePath) {
365 addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
366 }
367 }
368 RawOptions.emplace_back(ConfigOptions,
370 RawOptions.emplace_back(OverrideOptions,
372 return RawOptions;
373}
374
376 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
378 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
379 : DefaultOptionsProvider(std::move(GlobalOptions),
380 std::move(DefaultOptions)),
381 OverrideOptions(std::move(OverrideOptions)), FS(std::move(VFS)) {
382 if (!FS)
383 FS = llvm::vfs::getRealFileSystem();
384 ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
385}
386
395
396llvm::ErrorOr<llvm::SmallString<128>>
398 assert(FS && "FS must be set.");
399 llvm::SmallString<128> NormalizedAbsolutePath = {Path};
400 const std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
401 if (Err)
402 return Err;
403 llvm::sys::path::remove_dots(NormalizedAbsolutePath, /*remove_dot_dot=*/true);
404 return NormalizedAbsolutePath;
405}
406
408 llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
409 auto CurSize = CurOptions.size();
410 // Look for a suitable configuration file in all parent directories of the
411 // file. Start with the immediate parent directory and move up.
412 StringRef RootPath = llvm::sys::path::parent_path(AbsolutePath);
413 auto MemorizedConfigFile =
414 [this, &RootPath](StringRef CurrentPath) -> std::optional<OptionsSource> {
415 const auto Iter = CachedOptions.Memorized.find(CurrentPath);
416 if (Iter != CachedOptions.Memorized.end())
417 return CachedOptions.Storage[Iter->second];
418 std::optional<OptionsSource> OptionsSource = tryReadConfigFile(CurrentPath);
419 if (OptionsSource) {
420 const size_t Index = CachedOptions.Storage.size();
421 CachedOptions.Storage.emplace_back(OptionsSource.value());
422 while (RootPath != CurrentPath) {
423 LLVM_DEBUG(llvm::dbgs()
424 << "Caching configuration for path " << RootPath << ".\n");
425 CachedOptions.Memorized[RootPath] = Index;
426 RootPath = llvm::sys::path::parent_path(RootPath);
427 }
428 CachedOptions.Memorized[CurrentPath] = Index;
429 RootPath = llvm::sys::path::parent_path(CurrentPath);
430 }
431 return OptionsSource;
432 };
433 for (StringRef CurrentPath = RootPath; !CurrentPath.empty();
434 CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
435 if (std::optional<OptionsSource> Result =
436 MemorizedConfigFile(CurrentPath)) {
437 CurOptions.emplace_back(Result.value());
438 if (!Result->first.InheritParentConfig.value_or(false))
439 break;
440 }
441 }
442 // Reverse order of file configs because closer configs should have higher
443 // priority.
444 std::reverse(CurOptions.begin() + CurSize, CurOptions.end());
445}
446
448 ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
450 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
451 : FileOptionsBaseProvider(std::move(GlobalOptions),
452 std::move(DefaultOptions),
453 std::move(OverrideOptions), std::move(VFS)) {}
454
462
463// FIXME: This method has some common logic with clang::format::getStyle().
464// Consider pulling out common bits to a findParentFileWithName function or
465// similar.
466std::vector<OptionsSource>
468 LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
469 << "...\n");
470
471 const llvm::ErrorOr<llvm::SmallString<128>> AbsoluteFilePath =
473 if (!AbsoluteFilePath)
474 return {};
475
476 std::vector<OptionsSource> RawOptions =
477 DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
478 addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
479 const OptionsSource CommandLineOptions(
481
482 RawOptions.push_back(CommandLineOptions);
483 return RawOptions;
484}
485
486std::optional<OptionsSource>
488 assert(!Directory.empty());
489
490 llvm::ErrorOr<llvm::vfs::Status> DirectoryStatus = FS->status(Directory);
491
492 if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
493 llvm::errs() << "Error reading configuration from " << Directory
494 << ": directory doesn't exist.\n";
495 return std::nullopt;
496 }
497
498 for (const ConfigFileHandler &ConfigHandler : ConfigHandlers) {
499 SmallString<128> ConfigFile(Directory);
500 llvm::sys::path::append(ConfigFile, ConfigHandler.first);
501 LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
502
503 llvm::ErrorOr<llvm::vfs::Status> FileStatus = FS->status(ConfigFile);
504
505 if (!FileStatus || !FileStatus->isRegularFile())
506 continue;
507
508 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
509 FS->getBufferForFile(ConfigFile);
510 if (const std::error_code EC = Text.getError()) {
511 llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
512 << "\n";
513 continue;
514 }
515
516 // Skip empty files, e.g. files opened for writing via shell output
517 // redirection.
518 if ((*Text)->getBuffer().empty())
519 continue;
520 llvm::ErrorOr<ClangTidyOptions> ParsedOptions =
521 ConfigHandler.second({(*Text)->getBuffer(), ConfigFile});
522 if (!ParsedOptions) {
523 if (ParsedOptions.getError())
524 llvm::errs() << "Error parsing " << ConfigFile << ": "
525 << ParsedOptions.getError().message() << "\n";
526 continue;
527 }
528 return OptionsSource(*ParsedOptions, std::string(ConfigFile));
529 }
530 return std::nullopt;
531}
532
533/// Parses -line-filter option and stores it to the \c Options.
534std::error_code parseLineFilter(StringRef LineFilter,
536 llvm::yaml::Input Input(LineFilter);
537 Input >> Options.LineFilter;
538 return Input.error();
539}
540
541llvm::ErrorOr<ClangTidyOptions>
542parseConfiguration(llvm::MemoryBufferRef Config) {
543 llvm::yaml::Input Input(Config);
544 ClangTidyOptions Options;
545 Input >> Options;
546 if (Input.error())
547 return Input.error();
548 return Options;
549}
550
551static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx) {
552 (*reinterpret_cast<DiagCallback *>(Ctx))(Diag);
553}
554
555llvm::ErrorOr<ClangTidyOptions>
557 DiagCallback Handler) {
558 llvm::yaml::Input Input(Config, nullptr, Handler ? diagHandlerImpl : nullptr,
559 &Handler);
560 ClangTidyOptions Options;
561 Input >> Options;
562 if (Input.error())
563 return Input.error();
564 return Options;
565}
566
567std::string configurationAsText(const ClangTidyOptions &Options) {
568 std::string Text;
569 llvm::raw_string_ostream Stream(Text);
570 llvm::yaml::Output Output(Stream);
571 // We use the same mapping method for input and output, so we need a non-const
572 // reference here.
573 ClangTidyOptions NonConstValue = Options;
574 Output << NonConstValue;
575 return Stream.str();
576}
577
578} // 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.
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 mapGlobList(IO &IO, std::optional< std::string > &GlobList, StringRef Key)
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...
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)
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)