-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1a86119
Showing
8 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
BasedOnStyle: LLVM | ||
UseTab: Never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.h linguist-language=C++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build/ | ||
.idea/ | ||
.vscode/ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.20) | ||
project(ClangTidyPlugin C CXX) | ||
find_package(LLVM REQUIRED) | ||
find_package(Clang REQUIRED) | ||
add_library(ClangTidyPlugin MODULE MyClangTidyPluginModule.cpp MyCheck.cpp) | ||
target_compile_features(ClangTidyPlugin PRIVATE cxx_std_17) | ||
target_include_directories(ClangTidyPlugin PRIVATE ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS}) | ||
target_link_libraries(ClangTidyPlugin PRIVATE clangTidy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "MyCheck.h" | ||
|
||
namespace clang::tidy::MyPlugin { | ||
|
||
using namespace ast_matchers; | ||
|
||
MyCheck::MyCheck(StringRef Name, ClangTidyContext *Context) | ||
: ClangTidyCheck(Name, Context) {} | ||
|
||
void MyCheck::registerMatchers(MatchFinder *Finder) { | ||
Finder->addMatcher( | ||
callExpr(callee(functionDecl(hasName("foo")))).bind("fooCall"), this); | ||
} | ||
|
||
void MyCheck::check(const MatchFinder::MatchResult &Result) { | ||
const auto *fooCall = Result.Nodes.getNodeAs<CallExpr>("fooCall"); | ||
if (!fooCall) { | ||
return; | ||
} | ||
diag(fooCall->getBeginLoc(), "Calling deprecated API foo() is discouraged"); | ||
} | ||
|
||
} // namespace clang::tidy::MyPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <clang-tidy/ClangTidyCheck.h> | ||
|
||
namespace clang::tidy::MyPlugin { | ||
|
||
class MyCheck : public ClangTidyCheck { | ||
public: | ||
explicit MyCheck(StringRef Name, ClangTidyContext *Context); | ||
|
||
void registerMatchers(ast_matchers::MatchFinder *Finder) override; | ||
void check(const ast_matchers::MatchFinder::MatchResult &Result) override; | ||
}; | ||
|
||
} // namespace clang::tidy::MyPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <clang-tidy/ClangTidyModule.h> | ||
#include <clang-tidy/ClangTidyModuleRegistry.h> | ||
|
||
#include "MyCheck.h" | ||
|
||
namespace clang::tidy::MyPlugin { | ||
|
||
class MyClangTidyPluginModule : public ClangTidyModule { | ||
public: | ||
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { | ||
CheckFactories.registerCheck<MyCheck>("my-check"); | ||
} | ||
}; | ||
|
||
[[maybe_unused]] static ClangTidyModuleRegistry::Add<MyClangTidyPluginModule> | ||
X("my-module", "Adds checks in my plugin."); | ||
|
||
} // namespace clang::tidy::MyPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
void foo(); | ||
void bar(); | ||
|
||
void host() { foo(); } |