clang-tools  14.0.0git
TidyProvider.h
Go to the documentation of this file.
1 //===--- TidyProvider.h - create options for running clang-tidy------------===//
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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TIDYPROVIDER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TIDYPROVIDER_H
11 
12 #include "../clang-tidy/ClangTidyOptions.h"
13 #include "support/ThreadsafeFS.h"
14 #include "llvm/ADT/FunctionExtras.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/StringRef.h"
17 
18 namespace clang {
19 namespace clangd {
20 
21 /// A factory to modify a \ref tidy::ClangTidyOptions.
22 using TidyProvider =
23  llvm::unique_function<void(tidy::ClangTidyOptions &,
24  /*Filename=*/llvm::StringRef) const>;
25 
26 /// A factory to modify a \ref tidy::ClangTidyOptions that doesn't hold any
27 /// state.
28 using TidyProviderRef = llvm::function_ref<void(tidy::ClangTidyOptions &,
29  /*Filename=*/llvm::StringRef)>;
30 
31 TidyProvider combine(std::vector<TidyProvider> Providers);
32 
33 /// Provider that just sets the defaults.
35 
36 /// Provider that will enable a nice set of default checks if none are
37 /// specified.
39 
40 /// Provider the enables a specific set of checks and warnings as errors.
41 TidyProvider addTidyChecks(llvm::StringRef Checks,
42  llvm::StringRef WarningsAsErrors = {});
43 
44 /// Provider that will disable checks known to not work with clangd. \p
45 /// ExtraBadChecks specifies any other checks that should be always
46 /// disabled.
48 disableUnusableChecks(llvm::ArrayRef<std::string> ExtraBadChecks = {});
49 
50 /// Provider that searches for .clang-tidy configuration files in the directory
51 /// tree.
52 TidyProvider provideClangTidyFiles(ThreadsafeFS &);
53 
54 // Provider that uses clangd configuration files.
56 
57 tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider,
58  llvm::StringRef Filename);
59 
60 /// Returns if \p Check is a registered clang-tidy check
61 /// \pre \p must not be empty, must not contain '*' or ',' or start with '-'.
62 bool isRegisteredTidyCheck(llvm::StringRef Check);
63 
64 } // namespace clangd
65 } // namespace clang
66 
67 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_TIDYPROVIDER_H
clang::clangd::provideClangdConfig
TidyProviderRef provideClangdConfig()
Definition: TidyProvider.cpp:246
Checks
static cl::opt< std::string > Checks("checks", cl::desc(R"( Comma-separated list of globs with optional '-' prefix. Globs are processed in order of appearance in the list. Globs without '-' prefix add checks with matching names to the set, globs with the '-' prefix remove checks with matching names from the set of enabled checks. This option's value is appended to the value of the 'Checks' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
clang::clangd::getTidyOptionsForFile
tidy::ClangTidyOptions getTidyOptionsForFile(TidyProviderRef Provider, llvm::StringRef Filename)
Definition: TidyProvider.cpp:277
clang::clangd::provideClangTidyFiles
TidyProvider provideClangTidyFiles(ThreadsafeFS &TFS)
Provider that searches for .clang-tidy configuration files in the directory tree.
Definition: TidyProvider.cpp:259
Filename
std::string Filename
Filename as a string.
Definition: IncludeOrderCheck.cpp:39
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:50
ThreadsafeFS.h
clang::clangd::TidyProvider
llvm::unique_function< void(tidy::ClangTidyOptions &, llvm::StringRef) const > TidyProvider
A factory to modify a tidy::ClangTidyOptions.
Definition: TidyProvider.h:24
clang::clangd::provideEnvironment
TidyProviderRef provideEnvironment()
Provider that just sets the defaults.
Definition: TidyProvider.cpp:152
clang::clangd::isRegisteredTidyCheck
bool isRegisteredTidyCheck(llvm::StringRef Check)
Returns if Check is a registered clang-tidy check.
Definition: TidyProvider.cpp:286
WarningsAsErrors
static cl::opt< std::string > WarningsAsErrors("warnings-as-errors", cl::desc(R"( Upgrades warnings to errors. Same format as '-checks'. This option's value is appended to the value of the 'WarningsAsErrors' option in .clang-tidy file, if any. )"), cl::init(""), cl::cat(ClangTidyCategory))
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::clangd::disableUnusableChecks
TidyProvider disableUnusableChecks(llvm::ArrayRef< std::string > ExtraBadChecks)
Provider that will disable checks known to not work with clangd.
Definition: TidyProvider.cpp:197
clang::clangd::provideDefaultChecks
TidyProviderRef provideDefaultChecks()
Provider that will enable a nice set of default checks if none are specified.
Definition: TidyProvider.cpp:170
clang::clangd::TidyProviderRef
llvm::function_ref< void(tidy::ClangTidyOptions &, llvm::StringRef)> TidyProviderRef
A factory to modify a tidy::ClangTidyOptions that doesn't hold any state.
Definition: TidyProvider.h:29
clang::clangd::addTidyChecks
TidyProvider addTidyChecks(llvm::StringRef Checks, llvm::StringRef WarningsAsErrors)
Provider the enables a specific set of checks and warnings as errors.
Definition: TidyProvider.cpp:187
clang::clangd::combine
TidyProvider combine(std::vector< TidyProvider > Providers)
Definition: TidyProvider.cpp:266