Go to the documentation of this file.
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
12 #include "llvm/ADT/IntrusiveRefCntPtr.h"
13 #include "llvm/ADT/StringMap.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/ErrorOr.h"
16 #include "llvm/Support/MemoryBufferRef.h"
17 #include "llvm/Support/VirtualFileSystem.h"
21 #include <system_error>
66 unsigned Order)
const;
99 std::optional<std::string>
User;
164 virtual std::vector<OptionsSource>
178 : GlobalOptions(std::move(GlobalOptions)),
179 DefaultOptions(std::move(Options)) {}
181 return GlobalOptions;
194 typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
195 llvm::MemoryBufferRef)>>
220 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS);
229 std::vector<OptionsSource> &CurOptions);
238 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS;
248 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS =
nullptr);
278 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS =
nullptr);
311 llvm::ErrorOr<ClangTidyOptions>
314 using DiagCallback = llvm::function_ref<void(
const llvm::SMDiagnostic &)>;
316 llvm::ErrorOr<ClangTidyOptions>
324 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
std::optional< ArgList > ExtraArgs
Add extra compilation arguments to the end of the list.
llvm::ErrorOr< ClangTidyOptions > parseConfiguration(llvm::MemoryBufferRef Config)
Parses configuration from JSON and returns ClangTidyOptions or an error.
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
llvm::StringMap< ClangTidyValue > OptionMap
Implementation of the ClangTidyOptionsProvider interface, which returns the same options for all file...
unsigned Priority
Priority stores relative precedence of the value loaded from config files to disambiguate local vs gl...
ConfigFileHandlers ConfigHandlers
Abstract interface for retrieving various ClangTidy options.
std::error_code parseLineFilter(StringRef LineFilter, clang::tidy::ClangTidyGlobalOptions &Options)
Parses -line-filter option and stores it to the Options.
ClangTidyValue(llvm::StringRef Value, unsigned Priority=0)
std::vector< std::string > ArgList
static const char OptionsSourceTypeCheckCommandLineOption[]
void addRawFileOptions(llvm::StringRef AbsolutePath, std::vector< OptionsSource > &CurOptions)
Helper structure for storing option value with priority of the value.
Contains a list of line ranges in a single file.
std::vector< LineRange > LineRanges
A list of line ranges in this file, for which we show warnings.
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
ConfigOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions ConfigOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
llvm::ErrorOr< ClangTidyOptions > parseConfigurationWithDiags(llvm::MemoryBufferRef Config, DiagCallback Handler)
Contains options for clang-tidy.
static const char OptionsSourceTypeDefaultBinary[]
const ClangTidyGlobalOptions & getGlobalOptions() override
Returns global options, which are independent of the file.
Implementation of the ClangTidyOptionsProvider interface, which tries to find a configuration file in...
std::optional< bool > InheritParentConfig
Only used in the FileOptionsProvider and ConfigOptionsProvider.
std::pair< ClangTidyOptions, std::string > OptionsSource
ClangTidyOptions and its source.
std::vector< FileFilter > LineFilter
Output warnings from certain line ranges of certain files only.
ClangTidyOptions & mergeWith(const ClangTidyOptions &Other, unsigned Order)
Overwrites all fields in here by the fields of Other that have a value.
static cl::opt< std::string > Config("config", cl::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))
llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
llvm::StringRef Directory
virtual const ClangTidyGlobalOptions & getGlobalOptions()=0
Returns global options, which are independent of the file.
llvm::StringMap< OptionsSource > CachedOptions
std::pair< std::string, std::function< llvm::ErrorOr< ClangTidyOptions > llvm::MemoryBufferRef)> > ConfigFileHandler
std::string configurationAsText(const ClangTidyOptions &Options)
Serializes configuration to a YAML-encoded string.
std::optional< std::string > HeaderFilterRegex
Output warnings from headers matching this filter.
std::optional< OptionsSource > tryReadConfigFile(llvm::StringRef Directory)
Try to read configuration files from Directory using registered ConfigHandlers.
FileOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions DefaultOptions, ClangTidyOptions OverrideOptions, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > FS=nullptr)
Initializes the FileOptionsProvider instance.
static const char OptionsSourceTypeConfigCommandLineOption[]
Implementation of ClangTidyOptions interface, which is used for '-config' command-line option.
std::optional< std::string > Checks
Checks filter.
std::optional< bool > UseColor
Use colors in diagnostics. If missing, it will be auto detected.
std::string Name
File name.
llvm::function_ref< void(const llvm::SMDiagnostic &)> DiagCallback
ClangTidyOptions getOptions(llvm::StringRef FileName)
Returns options applying to a specific translation unit with the specified FileName.
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.
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))
std::optional< std::string > WarningsAsErrors
WarningsAsErrors filter.
std::optional< bool > SystemHeaders
Output warnings from system headers matching HeaderFilterRegex.
std::optional< std::string > FormatStyle
Format code around applied fixes with clang-format using this style.
std::pair< unsigned, unsigned > LineRange
LineRange is a pair<start, end> (inclusive).
virtual std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName)=0
Returns an ordered vector of OptionsSources, in order of increasing priority.
ClangTidyOptions OverrideOptions
std::optional< std::string > User
Specifies the name or e-mail of the user running clang-tidy.
virtual ~ClangTidyOptionsProvider()
ClangTidyValue(const char *Value)
ClangTidyOptions merge(const ClangTidyOptions &Other, unsigned Order) const
Creates a new ClangTidyOptions instance combined from all fields of this instance overridden by the f...
static ClangTidyOptions getDefaults()
These options are used for all settings that haven't been overridden by the OptionsProvider.
std::vector< OptionsSource > getRawOptions(llvm::StringRef FileName) override
Returns an ordered vector of OptionsSources, in order of increasing priority.
std::pair< std::string, std::string > StringPair
std::optional< ArgList > ExtraArgsBefore
Add extra compilation arguments to the start of the list.
DefaultOptionsProvider(ClangTidyGlobalOptions GlobalOptions, ClangTidyOptions Options)