9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H
12#include "clang/Basic/DiagnosticIDs.h"
13#include "llvm/ADT/IntrusiveRefCntPtr.h"
14#include "llvm/ADT/SmallString.h"
15#include "llvm/ADT/StringMap.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/ErrorOr.h"
18#include "llvm/Support/MemoryBufferRef.h"
19#include "llvm/Support/VirtualFileSystem.h"
23#include <system_error>
35 using LineRange = std::pair<unsigned int, unsigned int>;
68 unsigned Order)
const;
113 std::optional<std::string>
User;
136 std::optional<DiagnosticIDs::Level>
Level;
141 llvm::SmallVector<CustomCheckDiag>
Diags;
191 virtual std::vector<OptionsSource>
205 : GlobalOptions(std::
move(GlobalOptions)),
206 DefaultOptions(std::
move(Options)) {}
208 return GlobalOptions;
210 std::vector<OptionsSource>
getRawOptions(llvm::StringRef FileName)
override;
222 std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
223 llvm::MemoryBufferRef)>>;
247 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS);
255 std::vector<OptionsSource> &CurOptions);
257 llvm::ErrorOr<llvm::SmallString<128>>
270 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS;
280 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS =
nullptr);
281 std::vector<OptionsSource>
getRawOptions(llvm::StringRef FileName)
override;
310 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
FS =
nullptr);
334 std::vector<OptionsSource>
getRawOptions(llvm::StringRef FileName)
override;
343llvm::ErrorOr<ClangTidyOptions>
346using DiagCallback = llvm::function_ref<void(
const llvm::SMDiagnostic &)>;
348llvm::ErrorOr<ClangTidyOptions>
static cl::opt< std::string > Directory(cl::Positional, cl::Required, cl::desc("<Search Root Directory>"))
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))
Abstract interface for retrieving various ClangTidy options.
virtual ~ClangTidyOptionsProvider()
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[]
virtual const ClangTidyGlobalOptions & getGlobalOptions()=0
Returns global options, which are independent of the file.
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.
const ClangTidyGlobalOptions & getGlobalOptions() override
Returns global options, which are independent of the file.
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
ClangTidyOptions OverrideOptions
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.
ConfigFileHandlers 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.
llvm::ErrorOr< ClangTidyOptions > parseConfigurationWithDiags(llvm::MemoryBufferRef Config, DiagCallback Handler)
llvm::function_ref< void(const llvm::SMDiagnostic &)> DiagCallback
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.
std::vector< FileFilter > LineFilter
Output warnings from certain line ranges of certain files only.
ClangTidyValue(llvm::StringRef Value, unsigned Priority=0)
ClangTidyValue(const char *Value)
unsigned Priority
Priority stores relative precedence of the value loaded from config files to disambiguate local vs gl...
std::optional< DiagnosticIDs::Level > Level
llvm::SmallVector< CustomCheckDiag > Diags
Contains options for clang-tidy.
std::pair< std::string, std::string > StringPair
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...
llvm::StringMap< ClangTidyValue > OptionMap
std::optional< bool > InheritParentConfig
Only used in the FileOptionsProvider and ConfigOptionsProvider.
std::vector< std::string > ArgList
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...
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.
llvm::SmallVector< CustomCheckValue > CustomCheckValueList
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.
std::pair< unsigned int, unsigned int > LineRange
LineRange is a pair<start, end> (inclusive).
std::string Name
File name.
std::vector< LineRange > LineRanges
A list of line ranges in this file, for which we show warnings.
llvm::StringMap< size_t > Memorized
llvm::SmallVector< OptionsSource, 4U > Storage