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
|
|
|
|
2014-01-08 04:05:01 +08:00
|
|
|
#include "ClangTidyDiagnosticConsumer.h"
|
2014-04-29 23:20:10 +08:00
|
|
|
#include "ClangTidyOptions.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
|
|
|
|
2020-06-29 23:05:51 +08:00
|
|
|
namespace llvm {
|
|
|
|
class raw_ostream;
|
|
|
|
} // namespace llvm
|
|
|
|
|
2013-07-29 16:19:24 +08:00
|
|
|
namespace clang {
|
|
|
|
|
2020-06-29 23:05:51 +08:00
|
|
|
class ASTConsumer;
|
2013-07-29 16:19:24 +08:00
|
|
|
class CompilerInstance;
|
|
|
|
namespace tooling {
|
|
|
|
class CompilationDatabase;
|
2020-06-29 23:05:51 +08:00
|
|
|
} // namespace tooling
|
2013-07-29 16:19:24 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Returns an ASTConsumer that runs the specified clang-tidy checks.
|
2014-08-11 03:56:59 +08:00
|
|
|
std::unique_ptr<clang::ASTConsumer>
|
2021-11-02 15:14:25 +08:00
|
|
|
createASTConsumer(clang::CompilerInstance &Compiler, StringRef File);
|
2014-01-03 17:31:57 +08:00
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Get the list of enabled checks.
|
2014-09-12 16:53:36 +08:00
|
|
|
std::vector<std::string> getCheckNames();
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Get the union of options from all checks.
|
2014-09-12 16:53:36 +08:00
|
|
|
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
|
|
|
};
|
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Fills the list of check names that are enabled when the provided
|
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
|
|
|
/// 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
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Returns the effective check-specific options.
|
2014-09-12 16:53:36 +08:00
|
|
|
///
|
|
|
|
/// 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
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// 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,
|
2021-03-02 06:07:09 +08:00
|
|
|
bool ApplyAnyFix, bool EnableCheckProfile = false,
|
[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
|
|
|
llvm::StringRef StoreCheckProfile = StringRef());
|
2013-07-29 16:19:24 +08:00
|
|
|
|
2021-03-02 06:07:09 +08:00
|
|
|
/// Controls what kind of fixes clang-tidy is allowed to apply.
|
|
|
|
enum FixBehaviour {
|
|
|
|
/// Don't try to apply any fix.
|
|
|
|
FB_NoFix,
|
|
|
|
/// Only apply fixes added to warnings.
|
|
|
|
FB_Fix,
|
|
|
|
/// Apply fixes found in notes.
|
|
|
|
FB_FixNotes
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
//
|
2021-03-02 06:07:09 +08:00
|
|
|
/// Displays the found \p Errors to the users. If \p Fix is \ref FB_Fix or \ref
|
|
|
|
/// FB_FixNotes, \p 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,
|
2021-03-02 06:07:09 +08:00
|
|
|
ClangTidyContext &Context, FixBehaviour 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
|
|
|
|
Remove \brief commands from doxygen comments.
Summary:
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.
Patch produced by
for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
[This is analogous to LLVM r331272 and CFE r331834]
Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66578
llvm-svn: 369643
2019-08-22 19:32:57 +08:00
|
|
|
/// Serializes replacements into YAML and writes them to the specified
|
2014-09-04 18:31:23 +08:00
|
|
|
/// 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
|