2013-07-29 16:19:24 +08:00
|
|
|
//===--- ClangTidy.h - clang-tidy -------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-07-29 16:19:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-10 00:52:33 +08:00
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
|
2013-07-29 16:19:24 +08:00
|
|
|
|
2019-03-25 20:36:30 +08:00
|
|
|
#include "ClangTidyCheck.h"
|
2014-01-08 04:05:01 +08:00
|
|
|
#include "ClangTidyDiagnosticConsumer.h"
|
2014-04-29 23:20:10 +08:00
|
|
|
#include "ClangTidyOptions.h"
|
2014-09-12 16:53:36 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2014-06-05 21:31:45 +08:00
|
|
|
#include <memory>
|
2014-05-09 20:24:09 +08:00
|
|
|
#include <vector>
|
2013-07-29 16:19:24 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
|
|
|
|
class CompilerInstance;
|
|
|
|
namespace tooling {
|
|
|
|
class CompilationDatabase;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace tidy {
|
|
|
|
|
2014-01-03 17:31:57 +08:00
|
|
|
class ClangTidyCheckFactories;
|
|
|
|
|
|
|
|
class ClangTidyASTConsumerFactory {
|
|
|
|
public:
|
2019-03-22 21:42:48 +08:00
|
|
|
ClangTidyASTConsumerFactory(
|
|
|
|
ClangTidyContext &Context,
|
|
|
|
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS = nullptr);
|
2014-01-03 17:31:57 +08:00
|
|
|
|
|
|
|
/// \brief Returns an ASTConsumer that runs the specified clang-tidy checks.
|
2014-08-11 03:56:59 +08:00
|
|
|
std::unique_ptr<clang::ASTConsumer>
|
|
|
|
CreateASTConsumer(clang::CompilerInstance &Compiler, StringRef File);
|
2014-01-03 17:31:57 +08:00
|
|
|
|
|
|
|
/// \brief Get the list of enabled checks.
|
2014-09-12 16:53:36 +08:00
|
|
|
std::vector<std::string> getCheckNames();
|
|
|
|
|
|
|
|
/// \brief Get the union of options from all checks.
|
|
|
|
ClangTidyOptions::OptionMap getCheckOptions();
|
2014-01-03 17:31:57 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
ClangTidyContext &Context;
|
2019-03-22 21:42:48 +08:00
|
|
|
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS;
|
2014-03-09 17:24:40 +08:00
|
|
|
std::unique_ptr<ClangTidyCheckFactories> CheckFactories;
|
2014-01-03 17:31:57 +08:00
|
|
|
};
|
|
|
|
|
Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).
Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.
Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2444
llvm-svn: 197717
2013-12-20 03:57:05 +08:00
|
|
|
/// \brief Fills the list of check names that are enabled when the provided
|
|
|
|
/// filters are applied.
|
[clang-tidy] Add a flag to enable alpha checkers
Summary: The alpha checkers can already be enabled using the clang driver, this allows them to be enabled using the clang-tidy as well. This can make it easier to test the alpha checkers with projects which already support the compile_commands.json. It will also allow more people to give feedback and patches about the alpha checkers since they can run it as part of clang tidy checks.
Reviewers: aaron.ballman, hokein, ilya-biryukov, alexfh, lebedev.ri, xbolva00
Reviewed By: aaron.ballman, alexfh, lebedev.ri, xbolva00
Subscribers: xbolva00, NoQ, dcoughlin, lebedev.ri, xazax.hun, cfe-commits
Patch by Paul Fultz II!
Differential Revision: https://reviews.llvm.org/D46159
llvm-svn: 332609
2018-05-17 22:04:27 +08:00
|
|
|
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
|
|
|
|
bool AllowEnablingAnalyzerAlphaCheckers);
|
Clang-tidy: added --disable-checks, --list-checks options.
Summary:
Allow disabling checks by regex. By default, disable alpha.* checks,
that are not particularly good tested (e.g. IdempotentOperationChecker, see
http://llvm-reviews.chandlerc.com/D2427).
Fixed a bug, that would disable all analyzer checks, when using a regex more
strict, than 'clang-analyzer-', for example --checks='clang-analyzer-deadcode-'.
Added --list-checks to list all enabled checks. This is useful to test specific
values in --checks/--disable-checks.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits, klimek
Differential Revision: http://llvm-reviews.chandlerc.com/D2444
llvm-svn: 197717
2013-12-20 03:57:05 +08:00
|
|
|
|
2014-09-12 16:53:36 +08:00
|
|
|
/// \brief Returns the effective check-specific options.
|
|
|
|
///
|
|
|
|
/// The method configures ClangTidy with the specified \p Options and collects
|
|
|
|
/// effective options from all created checks. The returned set of options
|
|
|
|
/// includes default check-specific options for all keys not overridden by \p
|
|
|
|
/// Options.
|
[clang-tidy] Add a flag to enable alpha checkers
Summary: The alpha checkers can already be enabled using the clang driver, this allows them to be enabled using the clang-tidy as well. This can make it easier to test the alpha checkers with projects which already support the compile_commands.json. It will also allow more people to give feedback and patches about the alpha checkers since they can run it as part of clang tidy checks.
Reviewers: aaron.ballman, hokein, ilya-biryukov, alexfh, lebedev.ri, xbolva00
Reviewed By: aaron.ballman, alexfh, lebedev.ri, xbolva00
Subscribers: xbolva00, NoQ, dcoughlin, lebedev.ri, xazax.hun, cfe-commits
Patch by Paul Fultz II!
Differential Revision: https://reviews.llvm.org/D46159
llvm-svn: 332609
2018-05-17 22:04:27 +08:00
|
|
|
ClangTidyOptions::OptionMap
|
|
|
|
getCheckOptions(const ClangTidyOptions &Options,
|
|
|
|
bool AllowEnablingAnalyzerAlphaCheckers);
|
2014-09-12 16:53:36 +08:00
|
|
|
|
2013-07-29 16:19:24 +08:00
|
|
|
/// \brief Run a set of clang-tidy checks on a set of files.
|
2014-10-24 01:23:20 +08:00
|
|
|
///
|
2018-05-09 04:24:45 +08:00
|
|
|
/// \param EnableCheckProfile If provided, it enables check profile collection
|
|
|
|
/// in MatchFinder, and will contain the result of the profile.
|
[clang-tidy] Store checks profiling info as JSON files
Summary:
Continuation of D46504.
Example output:
```
$ clang-tidy -enable-check-profile -store-check-profile=. -checks=-*,readability-function-size source.cpp
$ # Note that there won't be timings table printed to the console.
$ cat *.json
{
"file": "/path/to/source.cpp",
"timestamp": "2018-05-16 16:13:18.717446360",
"profile": {
"time.clang-tidy.readability-function-size.wall": 1.0421266555786133e+00,
"time.clang-tidy.readability-function-size.user": 9.2088400000005421e-01,
"time.clang-tidy.readability-function-size.sys": 1.2418899999999974e-01
}
}
```
There are two arguments that control profile storage:
* `-store-check-profile=<prefix>`
By default reports are printed in tabulated format to stderr. When this option
is passed, these per-TU profiles are instead stored as JSON.
If the prefix is not an absolute path, it is considered to be relative to the
directory from where you have run :program:`clang-tidy`. All `.` and `..`
patterns in the path are collapsed, and symlinks are resolved.
Example:
Let's suppose you have a source file named `example.cpp`, located in
`/source` directory.
* If you specify `-store-check-profile=/tmp`, then the profile will be saved
to `/tmp/<timestamp>-example.cpp.json`
* If you run :program:`clang-tidy` from within `/foo` directory, and specify
`-store-check-profile=.`, then the profile will still be saved to
`/foo/<timestamp>-example.cpp.json`
Reviewers: alexfh, sbenza, george.karpenkov, NoQ, aaron.ballman
Reviewed By: alexfh, george.karpenkov, aaron.ballman
Subscribers: Quuxplusone, JonasToth, aaron.ballman, llvm-commits, rja, Eugene.Zelenko, xazax.hun, mgrang, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D46602
llvm-svn: 334101
2018-06-06 23:07:51 +08:00
|
|
|
/// \param StoreCheckProfile If provided, and EnableCheckProfile is true,
|
|
|
|
/// the profile will not be output to stderr, but will instead be stored
|
|
|
|
/// as a JSON file in the specified directory.
|
[clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC
Summary:
Currently ClangTidyContext::diag() sends the diagnostics to a
DiagnosticsEngine, which probably delegates to a ClangTidyDiagnosticsConsumer,
which is supposed to go back and populate ClangTidyContext::Errors.
After this patch, the diagnostics are stored in the ClangTidyDiagnosticsConsumer
itself and can be retrieved from there.
Why?
- the round-trip from context -> engine -> consumer -> context is confusing
and makes it harder to establish layering between these things.
- context does too many things, and makes it hard to use clang-tidy as a library
- everyone who actually wants the diagnostics has access to the ClangTidyDiagnosticsConsumer
The most natural implementation (ClangTidyDiagnosticsConsumer::take()
finalizes diagnostics) causes a test failure: clang-tidy-run-with-database.cpp
asserts that clang-tidy exits successfully when trying to process a file
that doesn't exist.
In clang-tidy today, this happens because finish() is never called, so the
diagnostic is never flushed. This looks like a bug to me.
For now, this patch carefully preserves that behavior, but I'll ping the
authors to see whether it's deliberate and worth preserving.
Reviewers: hokein
Subscribers: xazax.hun, cfe-commits, alexfh
Differential Revision: https://reviews.llvm.org/D53953
llvm-svn: 345961
2018-11-02 18:01:59 +08:00
|
|
|
std::vector<ClangTidyError>
|
|
|
|
runClangTidy(clang::tidy::ClangTidyContext &Context,
|
|
|
|
const tooling::CompilationDatabase &Compilations,
|
|
|
|
ArrayRef<std::string> InputFiles,
|
2019-03-22 21:42:48 +08:00
|
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> BaseFS,
|
[clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC
Summary:
Currently ClangTidyContext::diag() sends the diagnostics to a
DiagnosticsEngine, which probably delegates to a ClangTidyDiagnosticsConsumer,
which is supposed to go back and populate ClangTidyContext::Errors.
After this patch, the diagnostics are stored in the ClangTidyDiagnosticsConsumer
itself and can be retrieved from there.
Why?
- the round-trip from context -> engine -> consumer -> context is confusing
and makes it harder to establish layering between these things.
- context does too many things, and makes it hard to use clang-tidy as a library
- everyone who actually wants the diagnostics has access to the ClangTidyDiagnosticsConsumer
The most natural implementation (ClangTidyDiagnosticsConsumer::take()
finalizes diagnostics) causes a test failure: clang-tidy-run-with-database.cpp
asserts that clang-tidy exits successfully when trying to process a file
that doesn't exist.
In clang-tidy today, this happens because finish() is never called, so the
diagnostic is never flushed. This looks like a bug to me.
For now, this patch carefully preserves that behavior, but I'll ping the
authors to see whether it's deliberate and worth preserving.
Reviewers: hokein
Subscribers: xazax.hun, cfe-commits, alexfh
Differential Revision: https://reviews.llvm.org/D53953
llvm-svn: 345961
2018-11-02 18:01:59 +08:00
|
|
|
bool EnableCheckProfile = false,
|
|
|
|
llvm::StringRef StoreCheckProfile = StringRef());
|
2013-07-29 16:19:24 +08:00
|
|
|
|
|
|
|
// FIXME: This interface will need to be significantly extended to be useful.
|
|
|
|
// FIXME: Implement confidence levels for displaying/fixing errors.
|
|
|
|
//
|
|
|
|
/// \brief Displays the found \p Errors to the users. If \p Fix is true, \p
|
2016-12-01 02:06:42 +08:00
|
|
|
/// Errors containing fixes are automatically applied and reformatted. If no
|
|
|
|
/// clang-format configuration file is found, the given \P FormatStyle is used.
|
[clang-tidy] Get ClangTidyContext out of the business of storing diagnostics. NFC
Summary:
Currently ClangTidyContext::diag() sends the diagnostics to a
DiagnosticsEngine, which probably delegates to a ClangTidyDiagnosticsConsumer,
which is supposed to go back and populate ClangTidyContext::Errors.
After this patch, the diagnostics are stored in the ClangTidyDiagnosticsConsumer
itself and can be retrieved from there.
Why?
- the round-trip from context -> engine -> consumer -> context is confusing
and makes it harder to establish layering between these things.
- context does too many things, and makes it hard to use clang-tidy as a library
- everyone who actually wants the diagnostics has access to the ClangTidyDiagnosticsConsumer
The most natural implementation (ClangTidyDiagnosticsConsumer::take()
finalizes diagnostics) causes a test failure: clang-tidy-run-with-database.cpp
asserts that clang-tidy exits successfully when trying to process a file
that doesn't exist.
In clang-tidy today, this happens because finish() is never called, so the
diagnostic is never flushed. This looks like a bug to me.
For now, this patch carefully preserves that behavior, but I'll ping the
authors to see whether it's deliberate and worth preserving.
Reviewers: hokein
Subscribers: xazax.hun, cfe-commits, alexfh
Differential Revision: https://reviews.llvm.org/D53953
llvm-svn: 345961
2018-11-02 18:01:59 +08:00
|
|
|
void handleErrors(llvm::ArrayRef<ClangTidyError> Errors,
|
|
|
|
ClangTidyContext &Context, bool Fix,
|
2018-01-23 20:31:06 +08:00
|
|
|
unsigned &WarningsAsErrorsCount,
|
2018-10-10 21:27:25 +08:00
|
|
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS);
|
2013-07-29 16:19:24 +08:00
|
|
|
|
2014-09-04 18:31:23 +08:00
|
|
|
/// \brief Serializes replacements into YAML and writes them to the specified
|
|
|
|
/// output stream.
|
2017-01-03 22:36:13 +08:00
|
|
|
void exportReplacements(StringRef MainFilePath,
|
|
|
|
const std::vector<ClangTidyError> &Errors,
|
2014-09-04 18:31:23 +08:00
|
|
|
raw_ostream &OS);
|
|
|
|
|
2013-07-29 16:19:24 +08:00
|
|
|
} // end namespace tidy
|
|
|
|
} // end namespace clang
|
|
|
|
|
2015-03-10 00:52:33 +08:00
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H
|