clang-tools  14.0.0git
ClangTidyOptions.cpp
Go to the documentation of this file.
1 //===--- ClangTidyOptions.cpp - clang-tidy ----------------------*- C++ -*-===//
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/LLVM.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/Support/Debug.h"
14 #include "llvm/Support/Errc.h"
15 #include "llvm/Support/FileSystem.h"
16 #include "llvm/Support/MemoryBufferRef.h"
17 #include "llvm/Support/Path.h"
18 #include "llvm/Support/YAMLTraits.h"
19 #include <utility>
20 
21 #define DEBUG_TYPE "clang-tidy-options"
22 
26 
27 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter)
28 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(FileFilter::LineRange)
29 
30 namespace llvm {
31 namespace yaml {
32 
33 // Map std::pair<int, int> to a JSON array of size 2.
34 template <> struct SequenceTraits<FileFilter::LineRange> {
35  static size_t size(IO &IO, FileFilter::LineRange &Range) {
36  return Range.first == 0 ? 0 : Range.second == 0 ? 1 : 2;
37  }
38  static unsigned &element(IO &IO, FileFilter::LineRange &Range, size_t Index) {
39  if (Index > 1)
40  IO.setError("Too many elements in line range.");
41  return Index == 0 ? Range.first : Range.second;
42  }
43 };
44 
45 template <> struct MappingTraits<FileFilter> {
46  static void mapping(IO &IO, FileFilter &File) {
47  IO.mapRequired("name", File.Name);
48  IO.mapOptional("lines", File.LineRanges);
49  }
50  static std::string validate(IO &Io, FileFilter &File) {
51  if (File.Name.empty())
52  return "No file name specified";
53  for (const FileFilter::LineRange &Range : File.LineRanges) {
54  if (Range.first <= 0 || Range.second <= 0)
55  return "Invalid line range";
56  }
57  return "";
58  }
59 };
60 
61 template <> struct MappingTraits<ClangTidyOptions::StringPair> {
62  static void mapping(IO &IO, ClangTidyOptions::StringPair &KeyValue) {
63  IO.mapRequired("key", KeyValue.first);
64  IO.mapRequired("value", KeyValue.second);
65  }
66 };
67 
68 struct NOptionMap {
69  NOptionMap(IO &) {}
70  NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
71  Options.reserve(OptionMap.size());
72  for (const auto &KeyValue : OptionMap)
73  Options.emplace_back(std::string(KeyValue.getKey()), KeyValue.getValue().Value);
74  }
75  ClangTidyOptions::OptionMap denormalize(IO &) {
76  ClangTidyOptions::OptionMap Map;
77  for (const auto &KeyValue : Options)
78  Map[KeyValue.first] = ClangTidyOptions::ClangTidyValue(KeyValue.second);
79  return Map;
80  }
81  std::vector<ClangTidyOptions::StringPair> Options;
82 };
83 
84 template <> struct MappingTraits<ClangTidyOptions> {
85  static void mapping(IO &IO, ClangTidyOptions &Options) {
86  MappingNormalization<NOptionMap, ClangTidyOptions::OptionMap> NOpts(
87  IO, Options.CheckOptions);
88  bool Ignored = false;
89  IO.mapOptional("Checks", Options.Checks);
90  IO.mapOptional("WarningsAsErrors", Options.WarningsAsErrors);
91  IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
92  IO.mapOptional("AnalyzeTemporaryDtors", Ignored); // legacy compatibility
93  IO.mapOptional("FormatStyle", Options.FormatStyle);
94  IO.mapOptional("User", Options.User);
95  IO.mapOptional("CheckOptions", NOpts->Options);
96  IO.mapOptional("ExtraArgs", Options.ExtraArgs);
97  IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
98  IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
99  IO.mapOptional("UseColor", Options.UseColor);
100  }
101 };
102 
103 } // namespace yaml
104 } // namespace llvm
105 
106 namespace clang {
107 namespace tidy {
108 
110  ClangTidyOptions Options;
111  Options.Checks = "";
112  Options.WarningsAsErrors = "";
113  Options.HeaderFilterRegex = "";
114  Options.SystemHeaders = false;
115  Options.FormatStyle = "none";
116  Options.User = llvm::None;
117  for (const ClangTidyModuleRegistry::entry &Module :
118  ClangTidyModuleRegistry::entries())
119  Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
120  return Options;
121 }
122 
123 template <typename T>
124 static void mergeVectors(Optional<T> &Dest, const Optional<T> &Src) {
125  if (Src) {
126  if (Dest)
127  Dest->insert(Dest->end(), Src->begin(), Src->end());
128  else
129  Dest = Src;
130  }
131 }
132 
133 static void mergeCommaSeparatedLists(Optional<std::string> &Dest,
134  const Optional<std::string> &Src) {
135  if (Src)
136  Dest = (Dest && !Dest->empty() ? *Dest + "," : "") + *Src;
137 }
138 
139 template <typename T>
140 static void overrideValue(Optional<T> &Dest, const Optional<T> &Src) {
141  if (Src)
142  Dest = Src;
143 }
144 
146  unsigned Order) {
152  overrideValue(User, Other.User);
156 
157  for (const auto &KeyValue : Other.CheckOptions) {
158  CheckOptions.insert_or_assign(
159  KeyValue.getKey(),
160  ClangTidyValue(KeyValue.getValue().Value,
161  KeyValue.getValue().Priority + Order));
162  }
163  return *this;
164 }
165 
167  unsigned Order) const {
168  ClangTidyOptions Result = *this;
169  Result.mergeWith(Other, Order);
170  return Result;
171 }
172 
174  "clang-tidy binary";
176  "command-line option '-checks'";
177 const char
179  "command-line option '-config'";
180 
183  ClangTidyOptions Result;
184  unsigned Priority = 0;
185  for (auto &Source : getRawOptions(FileName))
186  Result.mergeWith(Source.first, ++Priority);
187  return Result;
188 }
189 
190 std::vector<OptionsSource>
192  std::vector<OptionsSource> Result;
193  Result.emplace_back(DefaultOptions, OptionsSourceTypeDefaultBinary);
194  return Result;
195 }
196 
198  ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
199  ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions,
200  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
201  : FileOptionsBaseProvider(std::move(GlobalOptions),
202  std::move(DefaultOptions),
203  std::move(OverrideOptions), std::move(FS)),
204  ConfigOptions(std::move(ConfigOptions)) {}
205 
206 std::vector<OptionsSource>
208  std::vector<OptionsSource> RawOptions =
210  if (ConfigOptions.InheritParentConfig.getValueOr(false)) {
211  LLVM_DEBUG(llvm::dbgs()
212  << "Getting options for file " << FileName << "...\n");
213  assert(FS && "FS must be set.");
214 
215  llvm::SmallString<128> AbsoluteFilePath(FileName);
216 
217  if (!FS->makeAbsolute(AbsoluteFilePath)) {
218  addRawFileOptions(AbsoluteFilePath, RawOptions);
219  }
220  }
221  RawOptions.emplace_back(ConfigOptions,
223  RawOptions.emplace_back(OverrideOptions,
225  return RawOptions;
226 }
227 
229  ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
230  ClangTidyOptions OverrideOptions,
231  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
232  : DefaultOptionsProvider(std::move(GlobalOptions),
233  std::move(DefaultOptions)),
234  OverrideOptions(std::move(OverrideOptions)), FS(std::move(VFS)) {
235  if (!FS)
236  FS = llvm::vfs::getRealFileSystem();
237  ConfigHandlers.emplace_back(".clang-tidy", parseConfiguration);
238 }
239 
241  ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
242  ClangTidyOptions OverrideOptions,
244  : DefaultOptionsProvider(std::move(GlobalOptions),
245  std::move(DefaultOptions)),
246  OverrideOptions(std::move(OverrideOptions)),
247  ConfigHandlers(std::move(ConfigHandlers)) {}
248 
250  llvm::StringRef AbsolutePath, std::vector<OptionsSource> &CurOptions) {
251  auto CurSize = CurOptions.size();
252 
253  // Look for a suitable configuration file in all parent directories of the
254  // file. Start with the immediate parent directory and move up.
255  StringRef Path = llvm::sys::path::parent_path(AbsolutePath);
256  for (StringRef CurrentPath = Path; !CurrentPath.empty();
257  CurrentPath = llvm::sys::path::parent_path(CurrentPath)) {
258  llvm::Optional<OptionsSource> Result;
259 
260  auto Iter = CachedOptions.find(CurrentPath);
261  if (Iter != CachedOptions.end())
262  Result = Iter->second;
263 
264  if (!Result)
265  Result = tryReadConfigFile(CurrentPath);
266 
267  if (Result) {
268  // Store cached value for all intermediate directories.
269  while (Path != CurrentPath) {
270  LLVM_DEBUG(llvm::dbgs()
271  << "Caching configuration for path " << Path << ".\n");
272  if (!CachedOptions.count(Path))
273  CachedOptions[Path] = *Result;
274  Path = llvm::sys::path::parent_path(Path);
275  }
276  CachedOptions[Path] = *Result;
277 
278  CurOptions.push_back(*Result);
279  if (!Result->first.InheritParentConfig.getValueOr(false))
280  break;
281  }
282  }
283  // Reverse order of file configs because closer configs should have higher
284  // priority.
285  std::reverse(CurOptions.begin() + CurSize, CurOptions.end());
286 }
287 
289  ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
290  ClangTidyOptions OverrideOptions,
291  llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
292  : FileOptionsBaseProvider(std::move(GlobalOptions),
293  std::move(DefaultOptions),
294  std::move(OverrideOptions), std::move(VFS)) {}
295 
297  ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions,
298  ClangTidyOptions OverrideOptions,
301  std::move(GlobalOptions), std::move(DefaultOptions),
302  std::move(OverrideOptions), std::move(ConfigHandlers)) {}
303 
304 // FIXME: This method has some common logic with clang::format::getStyle().
305 // Consider pulling out common bits to a findParentFileWithName function or
306 // similar.
307 std::vector<OptionsSource>
309  LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
310  << "...\n");
311  assert(FS && "FS must be set.");
312 
313  llvm::SmallString<128> AbsoluteFilePath(FileName);
314 
315  if (FS->makeAbsolute(AbsoluteFilePath))
316  return {};
317 
318  std::vector<OptionsSource> RawOptions =
319  DefaultOptionsProvider::getRawOptions(AbsoluteFilePath.str());
320  addRawFileOptions(AbsoluteFilePath, RawOptions);
321  OptionsSource CommandLineOptions(OverrideOptions,
323 
324  RawOptions.push_back(CommandLineOptions);
325  return RawOptions;
326 }
327 
328 llvm::Optional<OptionsSource>
330  assert(!Directory.empty());
331 
332  llvm::ErrorOr<llvm::vfs::Status> DirectoryStatus = FS->status(Directory);
333 
334  if (!DirectoryStatus || !DirectoryStatus->isDirectory()) {
335  llvm::errs() << "Error reading configuration from " << Directory
336  << ": directory doesn't exist.\n";
337  return llvm::None;
338  }
339 
340  for (const ConfigFileHandler &ConfigHandler : ConfigHandlers) {
341  SmallString<128> ConfigFile(Directory);
342  llvm::sys::path::append(ConfigFile, ConfigHandler.first);
343  LLVM_DEBUG(llvm::dbgs() << "Trying " << ConfigFile << "...\n");
344 
345  llvm::ErrorOr<llvm::vfs::Status> FileStatus = FS->status(ConfigFile);
346 
347  if (!FileStatus || !FileStatus->isRegularFile())
348  continue;
349 
350  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Text =
351  FS->getBufferForFile(ConfigFile);
352  if (std::error_code EC = Text.getError()) {
353  llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
354  << "\n";
355  continue;
356  }
357 
358  // Skip empty files, e.g. files opened for writing via shell output
359  // redirection.
360  if ((*Text)->getBuffer().empty())
361  continue;
362  llvm::ErrorOr<ClangTidyOptions> ParsedOptions =
363  ConfigHandler.second({(*Text)->getBuffer(), ConfigFile});
364  if (!ParsedOptions) {
365  if (ParsedOptions.getError())
366  llvm::errs() << "Error parsing " << ConfigFile << ": "
367  << ParsedOptions.getError().message() << "\n";
368  continue;
369  }
370  return OptionsSource(*ParsedOptions, std::string(ConfigFile));
371  }
372  return llvm::None;
373 }
374 
375 /// Parses -line-filter option and stores it to the \c Options.
376 std::error_code parseLineFilter(StringRef LineFilter,
378  llvm::yaml::Input Input(LineFilter);
379  Input >> Options.LineFilter;
380  return Input.error();
381 }
382 
383 llvm::ErrorOr<ClangTidyOptions>
384 parseConfiguration(llvm::MemoryBufferRef Config) {
385  llvm::yaml::Input Input(Config);
386  ClangTidyOptions Options;
387  Input >> Options;
388  if (Input.error())
389  return Input.error();
390  return Options;
391 }
392 
393 static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx) {
394  (*reinterpret_cast<DiagCallback *>(Ctx))(Diag);
395 }
396 
397 llvm::ErrorOr<ClangTidyOptions>
398 parseConfigurationWithDiags(llvm::MemoryBufferRef Config,
399  DiagCallback Handler) {
400  llvm::yaml::Input Input(Config, nullptr, Handler ? diagHandlerImpl : nullptr,
401  &Handler);
402  ClangTidyOptions Options;
403  Input >> Options;
404  if (Input.error())
405  return Input.error();
406  return Options;
407 }
408 
409 std::string configurationAsText(const ClangTidyOptions &Options) {
410  std::string Text;
411  llvm::raw_string_ostream Stream(Text);
412  llvm::yaml::Output Output(Stream);
413  // We use the same mapping method for input and output, so we need a non-const
414  // reference here.
415  ClangTidyOptions NonConstValue = Options;
416  Output << NonConstValue;
417  return Stream.str();
418 }
419 
420 } // namespace tidy
421 } // namespace clang
Range
CharSourceRange Range
SourceRange for the file name.
Definition: IncludeOrderCheck.cpp:38
clang::tidy::parseConfiguration
llvm::ErrorOr< ClangTidyOptions > parseConfiguration(llvm::MemoryBufferRef Config)
Parses configuration from JSON and returns ClangTidyOptions or an error.
Definition: ClangTidyOptions.cpp:384
clang::tidy::DefaultOptionsProvider::getRawOptions
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
Definition: ClangTidyOptions.cpp:191
llvm
Some operations such as code completion produce a set of candidates.
Definition: YAMLGenerator.cpp:28
clang::tidy::DefaultOptionsProvider
Implementation of the ClangTidyOptionsProvider interface, which returns the same options for all file...
Definition: ClangTidyOptions.h:175
clang::tidy::ClangTidyOptions::Checks
llvm::Optional< std::string > Checks
Checks filter.
Definition: ClangTidyOptions.h:70
clang::tidy::FileOptionsBaseProvider::ConfigHandlers
ConfigFileHandlers ConfigHandlers
Definition: ClangTidyOptions.h:238
clang::tidy::parseLineFilter
std::error_code parseLineFilter(StringRef LineFilter, clang::tidy::ClangTidyGlobalOptions &Options)
Parses -line-filter option and stores it to the Options.
Definition: ClangTidyOptions.cpp:376
llvm::yaml::SequenceTraits< FileFilter::LineRange >::element
static unsigned & element(IO &IO, FileFilter::LineRange &Range, size_t Index)
Definition: ClangTidyOptions.cpp:38
clang::tidy::ClangTidyOptionsProvider::OptionsSourceTypeCheckCommandLineOption
static const char OptionsSourceTypeCheckCommandLineOption[]
Definition: ClangTidyOptions.h:145
clang::tidy::FileOptionsBaseProvider::addRawFileOptions
void addRawFileOptions(llvm::StringRef AbsolutePath, std::vector< OptionsSource > &CurOptions)
Definition: ClangTidyOptions.cpp:249
clang::tidy::ClangTidyOptions::ClangTidyValue
Helper structure for storing option value with priority of the value.
Definition: ClangTidyOptions.h:103
Text
std::string Text
Definition: HTMLGenerator.cpp:80
Ctx
Context Ctx
Definition: TUScheduler.cpp:454
clang::tidy::FileFilter
Contains a list of line ranges in a single file.
Definition: ClangTidyOptions.h:29
clang::tidy::ClangTidyOptions::ExtraArgsBefore
llvm::Optional< ArgList > ExtraArgsBefore
Add extra compilation arguments to the start of the list.
Definition: ClangTidyOptions.h:126
llvm::yaml::MappingTraits< ClangTidyOptions::StringPair >::mapping
static void mapping(IO &IO, ClangTidyOptions::StringPair &KeyValue)
Definition: ClangTidyOptions.cpp:62
clang::tidy::ClangTidyOptions::User
llvm::Optional< std::string > User
Specifies the name or e-mail of the user running clang-tidy.
Definition: ClangTidyOptions.h:100
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:118
ConfigFile
static cl::opt< std::string > ConfigFile("config-file", cl::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))
clang::tidy::ConfigOptionsProvider::ConfigOptionsProvider
ConfigOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
Definition: ClangTidyOptions.cpp:197
llvm::yaml::NOptionMap
Definition: ClangTidyOptions.cpp:68
llvm::yaml::SequenceTraits< FileFilter::LineRange >::size
static size_t size(IO &IO, FileFilter::LineRange &Range)
Definition: ClangTidyOptions.cpp:35
clang::tidy::parseConfigurationWithDiags
llvm::ErrorOr< ClangTidyOptions > parseConfigurationWithDiags(llvm::MemoryBufferRef Config, DiagCallback Handler)
Definition: ClangTidyOptions.cpp:398
clang::tidy::mergeVectors
static void mergeVectors(Optional< T > &Dest, const Optional< T > &Src)
Definition: ClangTidyOptions.cpp:124
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
clang::tidy::ClangTidyOptionsProvider::OptionsSourceTypeDefaultBinary
static const char OptionsSourceTypeDefaultBinary[]
Definition: ClangTidyOptions.h:144
clang::tidy::ClangTidyOptions::InheritParentConfig
llvm::Optional< bool > InheritParentConfig
Only used in the FileOptionsProvider and ConfigOptionsProvider.
Definition: ClangTidyOptions.h:135
clang::tidy::ClangTidyOptions::FormatStyle
llvm::Optional< std::string > FormatStyle
Format code around applied fixes with clang-format using this style.
Definition: ClangTidyOptions.h:94
clang::tidy::ClangTidyOptions::UseColor
llvm::Optional< bool > UseColor
Use colors in diagnostics. If missing, it will be auto detected.
Definition: ClangTidyOptions.h:138
OptionsSource
clang::tidy::ClangTidyOptionsProvider::OptionsSource OptionsSource
Definition: ClangTidyOptions.cpp:25
clang::tidy::ClangTidyOptionsProvider::OptionsSource
std::pair< ClangTidyOptions, std::string > OptionsSource
ClangTidyOptions and its source.
Definition: ClangTidyOptions.h:161
ClangTidyModuleRegistry.h
clang::tidy::diagHandlerImpl
static void diagHandlerImpl(const llvm::SMDiagnostic &Diag, void *Ctx)
Definition: ClangTidyOptions.cpp:393
clang::tidy::ClangTidyOptions::HeaderFilterRegex
llvm::Optional< std::string > HeaderFilterRegex
Output warnings from headers matching this filter.
Definition: ClangTidyOptions.h:77
clang::tidy::ClangTidyOptions::SystemHeaders
llvm::Optional< bool > SystemHeaders
Output warnings from system headers matching HeaderFilterRegex.
Definition: ClangTidyOptions.h:80
clang::tidy::FileOptionsBaseProvider
Definition: ClangTidyOptions.h:191
clang::tidy::ClangTidyGlobalOptions::LineFilter
std::vector< FileFilter > LineFilter
Output warnings from certain line ranges of certain files only.
Definition: ClangTidyOptions.h:45
clang::tidy::ClangTidyOptions::mergeWith
ClangTidyOptions & mergeWith(const ClangTidyOptions &Other, unsigned Order)
Overwrites all fields in here by the fields of Other that have a value.
Definition: ClangTidyOptions.cpp:145
clang::tidy::FileOptionsBaseProvider::FS
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS
Definition: ClangTidyOptions.h:239
llvm::yaml::NOptionMap::Options
std::vector< ClangTidyOptions::StringPair > Options
Definition: ClangTidyOptions.cpp:81
llvm::yaml::MappingTraits< FileFilter >::validate
static std::string validate(IO &Io, FileFilter &File)
Definition: ClangTidyOptions.cpp:50
clang::tidy::FileOptionsProvider::getRawOptions
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
Definition: ClangTidyOptions.cpp:308
Directory
llvm::StringRef Directory
Definition: Serialization.cpp:419
if
if(CLANGD_ENABLE_REMOTE) generate_protos(RemoteIndexProto "Index.proto") generate_protos(MonitoringServiceProto "MonitoringService.proto" GRPC) generate_protos(RemoteIndexServiceProto "Service.proto" DEPENDS "Index.proto" GRPC) target_link_libraries(RemoteIndexServiceProto PRIVATE RemoteIndexProto MonitoringServiceProto) include_directories($
Definition: clangd/index/remote/CMakeLists.txt:1
clang::tidy::FileOptionsBaseProvider::CachedOptions
llvm::StringMap< OptionsSource > CachedOptions
Definition: ClangTidyOptions.h:236
clang::tidy::FileOptionsBaseProvider::ConfigFileHandler
std::pair< std::string, std::function< llvm::ErrorOr< ClangTidyOptions > llvm::MemoryBufferRef)> > ConfigFileHandler
Definition: ClangTidyOptions.h:197
clang::tidy::configurationAsText
std::string configurationAsText(const ClangTidyOptions &Options)
Serializes configuration to a YAML-encoded string.
Definition: ClangTidyOptions.cpp:409
FileName
StringRef FileName
Definition: KernelNameRestrictionCheck.cpp:46
clang::tidy::FileOptionsBaseProvider::tryReadConfigFile
llvm::Optional< OptionsSource > tryReadConfigFile(llvm::StringRef Directory)
Try to read configuration files from Directory using registered ConfigHandlers.
Definition: ClangTidyOptions.cpp:329
clang::tidy::FileOptionsProvider::FileOptionsProvider
FileOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
Initializes the FileOptionsProvider instance.
Definition: ClangTidyOptions.cpp:288
Output
std::string Output
Definition: TraceTests.cpp:162
llvm::yaml::MappingTraits< FileFilter >::mapping
static void mapping(IO &IO, FileFilter &File)
Definition: ClangTidyOptions.cpp:46
clang::tidy::ClangTidyOptionsProvider::OptionsSourceTypeConfigCommandLineOption
static const char OptionsSourceTypeConfigCommandLineOption[]
Definition: ClangTidyOptions.h:146
Config
static cl::opt< std::string > Config("config", cl::desc(R"( Specifies a configuration in YAML/JSON format: -config="{Checks:' *', CheckOptions:[{key:x, value:y}]}" When the value is empty, clang-tidy will attempt to find a file named .clang-tidy for each source file in its parent directories. )"), cl::init(""), cl::cat(ClangTidyCategory))
clang::tidy::ClangTidyGlobalOptions
Global options.
Definition: ClangTidyOptions.h:42
Index
const SymbolIndex * Index
Definition: Dexp.cpp:99
clang::tidy::mergeCommaSeparatedLists
static void mergeCommaSeparatedLists(Optional< std::string > &Dest, const Optional< std::string > &Src)
Definition: ClangTidyOptions.cpp:133
clang::tidy::ClangTidyOptions::WarningsAsErrors
llvm::Optional< std::string > WarningsAsErrors
WarningsAsErrors filter.
Definition: ClangTidyOptions.h:73
clang::tidy::overrideValue
static void overrideValue(Optional< T > &Dest, const Optional< T > &Src)
Definition: ClangTidyOptions.cpp:140
clang::tidy::DiagCallback
llvm::function_ref< void(const llvm::SMDiagnostic &)> DiagCallback
Definition: ClangTidyOptions.h:315
clang::tidy::ClangTidyOptionsProvider::getOptions
ClangTidyOptions getOptions(llvm::StringRef FileName)
Returns options applying to a specific translation unit with the specified FileName.
Definition: ClangTidyOptions.cpp:182
clang::tidy::FileOptionsBaseProvider::FileOptionsBaseProvider
FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS)
Definition: ClangTidyOptions.cpp:228
clang::tidy::FileOptionsBaseProvider::ConfigFileHandlers
std::vector< ConfigFileHandler > ConfigFileHandlers
Configuration file handlers listed in the order of priority.
Definition: ClangTidyOptions.h:216
LineFilter
static cl::opt< std::string > LineFilter("line-filter", cl::desc(R"( List of files with line ranges to filter the warnings. Can be used together with -header-filter. The format of the list is a JSON array of objects: [ {"name":"file1.cpp","lines":[[1,3],[5,7]]}, {"name":"file2.h"} ] )"), cl::init(""), cl::cat(ClangTidyCategory))
llvm::yaml::NOptionMap::denormalize
ClangTidyOptions::OptionMap denormalize(IO &)
Definition: ClangTidyOptions.cpp:75
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyOptionsProvider::getRawOptions
virtual std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName)=0
Returns an ordered vector of OptionsSources, in order of increasing priority.
clang::tidy::FileOptionsBaseProvider::OverrideOptions
ClangTidyOptions OverrideOptions
Definition: ClangTidyOptions.h:237
ClangTidyOptions.h
clang::tidy::ClangTidyOptions::merge
LLVM_NODISCARD ClangTidyOptions merge(const ClangTidyOptions &Other, unsigned Order) const
Creates a new ClangTidyOptions instance combined from all fields of this instance overridden by the f...
Definition: ClangTidyOptions.cpp:166
clang::tidy::ClangTidyOptions::getDefaults
static ClangTidyOptions getDefaults()
These options are used for all settings that haven't been overridden by the OptionsProvider.
Definition: ClangTidyOptions.cpp:109
llvm::yaml::MappingTraits< ClangTidyOptions >::mapping
static void mapping(IO &IO, ClangTidyOptions &Options)
Definition: ClangTidyOptions.cpp:85
clang::tidy::ConfigOptionsProvider::getRawOptions
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
Definition: ClangTidyOptions.cpp:207
clang::tidy::ClangTidyOptions::ExtraArgs
llvm::Optional< ArgList > ExtraArgs
Add extra compilation arguments to the end of the list.
Definition: ClangTidyOptions.h:123
llvm::yaml::NOptionMap::NOptionMap
NOptionMap(IO &)
Definition: ClangTidyOptions.cpp:69
llvm::yaml::NOptionMap::NOptionMap
NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap)
Definition: ClangTidyOptions.cpp:70
yaml
@ yaml
Definition: ClangDocMain.cpp:92
Path
std::vector< HeaderHandle > Path
Definition: PreprocessorTracker.cpp:525