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 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
69struct NOptionMap {
70 NOptionMap(IO &) {}
71 NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
72 Options.reserve(OptionMap.size());
73 for (const auto &KeyValue : OptionMap)
74 Options.emplace_back(std::string(KeyValue.getKey()),
75 KeyValue.getValue().Value);
76 }
79 for (const auto &KeyValue : Options)
80 Map[KeyValue.first] = ClangTidyOptions::ClangTidyValue(KeyValue.second);
81 return Map;
82 }
83 std::vector<ClangTidyOptions::StringPair> Options;
84};
85
86template <>
87void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
88 EmptyContext &Ctx) {
89 if (IO.outputting()) {
90 // Ensure check options are sorted
91 std::vector<std::pair<StringRef, StringRef>> SortedOptions;
92 SortedOptions.reserve(Val.size());
93 for (auto &Key : Val)
94 SortedOptions.emplace_back(Key.getKey(), Key.getValue().Value);
95 std::sort(SortedOptions.begin(), SortedOptions.end());
96
97 IO.beginMapping();
98 // Only output as a map
99 for (auto &Option : SortedOptions) {
100 bool UseDefault = false;
101 void *SaveInfo = nullptr;
102 // Requires 'llvm::yaml::IO' to accept 'StringRef'
103 // NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
104 IO.preflightKey(Option.first.data(), true, false, UseDefault, SaveInfo);
105 IO.scalarString(Option.second, needsQuotes(Option.second));
106 IO.postflightKey(SaveInfo);
107 }
108 IO.endMapping();
109 } else {
110 // We need custom logic here to support the old method of specifying check
111 // options using a list of maps containing key and value keys.
112 auto &I = reinterpret_cast<Input &>(IO);
113 if (isa<SequenceNode>(I.getCurrentNode())) {
114 MappingNormalization<NOptionMap, ClangTidyOptions::OptionMap> NOpts(IO,
115 Val);
116 EmptyContext Ctx;
117 yamlize(IO, NOpts->Options, true, Ctx);
118 } else if (isa<MappingNode>(I.getCurrentNode())) {
119 IO.beginMapping();
120 for (const StringRef Key : IO.keys()) {
121 // Requires 'llvm::yaml::IO' to accept 'StringRef'
122 // NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
123 IO.mapRequired(Key.data(), Val[Key].Value);
124 }
125 IO.endMapping();
126 } else {
127 IO.setError("expected a sequence or map");
128 }
129 }
130}
131
132namespace {
133struct MultiLineString {
134 std::string &S;
135};
136} // namespace
137
138template <> struct BlockScalarTraits<MultiLineString> {
139 static void output(const MultiLineString &S, void *Ctxt, raw_ostream &OS) {
140 OS << S.S;
141 }
142 static StringRef input(StringRef Str, void *Ctxt, MultiLineString &S) {
143 S.S = Str;
144 return "";
145 }
146};
147
148template <> struct ScalarEnumerationTraits<clang::DiagnosticIDs::Level> {
149 static void enumeration(IO &IO, clang::DiagnosticIDs::Level &Level) {
150 IO.enumCase(Level, "Warning", clang::DiagnosticIDs::Level::Warning);
151 IO.enumCase(Level, "Note", clang::DiagnosticIDs::Level::Note);
152 }
153};
154template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckDiag> {
155 // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
156 static const bool flow = false;
157};
158template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
160 IO.mapRequired("BindName", D.BindName);
161 MultiLineString MLS{D.Message};
162 IO.mapRequired("Message", MLS);
163 IO.mapOptional("Level", D.Level);
164 }
165};
166template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
167 // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
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 <>
185void yamlize(IO &IO, GlobListVariant &Val, bool, EmptyContext &Ctx) {
186 if (!IO.outputting()) {
187 // Special case for reading from YAML
188 // Must support reading from both a string or a list
189 auto &I = reinterpret_cast<Input &>(IO);
190 if (isa<ScalarNode, BlockScalarNode>(I.getCurrentNode())) {
191 Val.AsString = std::string();
192 yamlize(IO, *Val.AsString, true, Ctx);
193 } else if (isa<SequenceNode>(I.getCurrentNode())) {
194 Val.AsVector = std::vector<std::string>();
195 yamlize(IO, *Val.AsVector, true, Ctx);
196 } else {
197 IO.setError("expected string or sequence");
198 }
199 }
200}
201
202static void mapGlobList(IO &IO, std::optional<std::string> &GlobList,
203 StringRef Key) {
204 if (IO.outputting()) {
205 // Output always a string
206 IO.mapOptional(Key, GlobList);
207 } else {
208 // Input as either a string or a list
209 GlobListVariant GlobListAsVariant;
210 IO.mapOptional(Key, GlobListAsVariant);
211 if (GlobListAsVariant.AsString)
212 GlobList = GlobListAsVariant.AsString;
213 else if (GlobListAsVariant.AsVector)
214 GlobList = llvm::join(*GlobListAsVariant.AsVector, ",");
215 }
216}
217
218template <> struct MappingTraits<ClangTidyOptions> {
219 static void mapping(IO &IO, ClangTidyOptions &Options) {
220 mapGlobList(IO, Options.Checks, "Checks");
221 mapGlobList(IO, Options.WarningsAsErrors, "WarningsAsErrors");
222 IO.mapOptional("HeaderFileExtensions", Options.HeaderFileExtensions);
223 IO.mapOptional("ImplementationFileExtensions",
225 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
226 IO.mapOptional("ExcludeHeaderFilterRegex",
228 IO.mapOptional("FormatStyle", Options.FormatStyle);
229 IO.mapOptional("User", Options.User);
230 IO.mapOptional("CheckOptions", Options.CheckOptions);
231 IO.mapOptional("ExtraArgs", Options.ExtraArgs);
232 IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
233 IO.mapOptional("RemovedArgs", Options.RemovedArgs);
234 IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
235 IO.mapOptional("UseColor", Options.UseColor);
236 IO.mapOptional("SystemHeaders", Options.SystemHeaders);
237 IO.mapOptional("CustomChecks", Options.CustomChecks);
238 }
239};
240
241} // namespace llvm::yaml
242
243namespace clang::tidy {
244
246 ClangTidyOptions Options;
247 Options.Checks = "";
248 Options.WarningsAsErrors = "";
249 Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
250 Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
251 Options.HeaderFilterRegex = ".*";
252 Options.ExcludeHeaderFilterRegex = "";
253 Options.SystemHeaders = false;
254 Options.FormatStyle = "none";
255 Options.User = std::nullopt;
256 Options.RemovedArgs = std::nullopt;
257 for (const ClangTidyModuleRegistry::entry &Module :
258 ClangTidyModuleRegistry::entries())
259 Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
260 return Options;
261}
262
263template <typename T>
264static void mergeVectors(std::optional<T> &Dest, const std::optional<T> &Src) {
265 if (Src) {
266 if (Dest)
267 Dest->insert(Dest->end(), Src->begin(), Src->end());
268 else
269 Dest = Src;
270 }
271}
272
273static void mergeCommaSeparatedLists(std::optional<std::string> &Dest,
274 const std::optional<std::string> &Src) {
275 if (Src)
276 Dest = (Dest && !Dest->empty() ? *Dest + "," : "") + *Src;
277}
278
279template <typename T>
280static void overrideValue(std::optional<T> &Dest, const std::optional<T> &Src) {
281 if (Src)
282 Dest = Src;
283}
284
286 unsigned Order) {
296 overrideValue(User, Other.User);
301 // FIXME: how to handle duplicate names check?
303 for (const auto &KeyValue : Other.CheckOptions) {
304 CheckOptions.insert_or_assign(
305 KeyValue.getKey(),
306 ClangTidyValue(KeyValue.getValue().Value,
307 KeyValue.getValue().Priority + Order));
308 }
309 return *this;
310}
311
313 unsigned Order) const {
314 ClangTidyOptions Result = *this;
315 Result.mergeWith(Other, Order);
316 return Result;
317}
318
320 "clang-tidy binary";
322 "command-line option '-checks'";
323const char
325 "command-line option '-config'";
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.
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)