[clang-tools-extra] Extend support for specifying languages and version in add_new_check.py (PR #100129)

2025-02-26 Thread Marco C. via cfe-commits

Marcondiro wrote:

Hello @njames93,
After this PR, the class derived from `ClangTidyCheck` created by the script 
`add_new_check.py` overrides `isLanguageVersionSupported` by default, 
restricting the check's scope to `LangOpts.CPlusPlus` code.

Running `clang-tidy/add_new_check.py readability awesome-function-names` 
generates:
```c++
// clang-tools-extra/clang-tidy/readability/AwesomeFunctionNamesCheck.h
class AwesomeFunctionNamesCheck : public ClangTidyCheck {
public:
  [...]
  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
  }
};
```

Is this behavior expected?
If so, 
[`clang-tools-extra/docs/clang-tidy/Contributing.rst`](https://clang.llvm.org/extra/clang-tidy/Contributing.html)
 could be updated accordingly. (It definitely didn't take me a while to figure 
out why my check wasn't working on C code :smile: )

Thank you!

https://github.com/llvm/llvm-project/pull/100129
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread Marco C. via cfe-commits

https://github.com/Marcondiro created 
https://github.com/llvm/llvm-project/pull/129209

This reflects the add_new_check.py changes: isLanguageVersionSupported is now 
overridden by default by the script

The changes were instroduced in https://github.com/llvm/llvm-project/pull/100129

Thanks

>From 83444c3b639c944cf79868988954305e829bdab0 Mon Sep 17 00:00:00 2001
From: Marcondiro <46560192+marcond...@users.noreply.github.com>
Date: Fri, 28 Feb 2025 09:34:30 +0100
Subject: [PATCH] [clang-tidy] Contributing.rst update snippet and docs

This reflects the add_new_check.py changes: isLanguageVersionSupported
is now overridden by default by the script
---
 .../docs/clang-tidy/Contributing.rst   | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 4f1df8d11..ed28df0e9887a 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -171,9 +171,7 @@ Let's see in more detail at the check class definition:
 
   #include "../ClangTidyCheck.h"
 
-  namespace clang {
-  namespace tidy {
-  namespace readability {
+  namespace clang::tidy::readability {
 
   ...
   class AwesomeFunctionNamesCheck : public ClangTidyCheck {
@@ -182,11 +180,12 @@ Let's see in more detail at the check class definition:
 : ClangTidyCheck(Name, Context) {}
 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+bool isLanguageVersionSupported(const LangOptions &LangOpts) const 
override {
+  return LangOpts.CPlusPlus;
+}
   };
 
-  } // namespace readability
-  } // namespace tidy
-  } // namespace clang
+  } // namespace clang::tidy::readability
 
   ...
 
@@ -203,6 +202,10 @@ for more information) that will find the pattern in the 
AST that we want to
 inspect. The results of the matching are passed to the ``check`` method, which
 can further inspect them and report diagnostics.
 
+By default, the new check applies only to C++ code. If it should apply under 
+different language options, be sure to update the 
``isLanguageVersionSupported``
+method accordingly.
+
 .. code-block:: c++
 
   using namespace ast_matchers;
@@ -231,9 +234,6 @@ override the method ``registerPPCallbacks``.  The 
``add_new_check.py`` script
 does not generate an override for this method in the starting point for your
 new check.
 
-If your check applies only under a specific set of language options, be sure
-to override the method ``isLanguageVersionSupported`` to reflect that.
-
 Check development tips
 --
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread Marco C. via cfe-commits

https://github.com/Marcondiro updated 
https://github.com/llvm/llvm-project/pull/129209

>From afe211ecfa254e12fdf448afe992ed1b2a7d Mon Sep 17 00:00:00 2001
From: Marcondiro <46560192+marcond...@users.noreply.github.com>
Date: Fri, 28 Feb 2025 09:34:30 +0100
Subject: [PATCH] [clang-tidy] Contributing.rst update snippet and docs

This reflects the add_new_check.py changes: isLanguageVersionSupported
is now overridden by default by the script
---
 .../docs/clang-tidy/Contributing.rst| 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 4f1df8d11..9611c655886f2 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -149,6 +149,9 @@ After choosing the module and the name for the check, run 
the
 ``clang-tidy/add_new_check.py`` script to create the skeleton of the check and
 plug it to :program:`clang-tidy`. It's the recommended way of adding new 
checks.
 
+By default, the new check will apply only to C++ code. If it should apply under
+different language options, use the ``--language`` script's parameter.
+
 If we want to create a `readability-awesome-function-names`, we would run:
 
 .. code-block:: console
@@ -171,9 +174,7 @@ Let's see in more detail at the check class definition:
 
   #include "../ClangTidyCheck.h"
 
-  namespace clang {
-  namespace tidy {
-  namespace readability {
+  namespace clang::tidy::readability {
 
   ...
   class AwesomeFunctionNamesCheck : public ClangTidyCheck {
@@ -182,11 +183,12 @@ Let's see in more detail at the check class definition:
 : ClangTidyCheck(Name, Context) {}
 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+bool isLanguageVersionSupported(const LangOptions &LangOpts) const 
override {
+  return LangOpts.CPlusPlus;
+}
   };
 
-  } // namespace readability
-  } // namespace tidy
-  } // namespace clang
+  } // namespace clang::tidy::readability
 
   ...
 
@@ -231,9 +233,6 @@ override the method ``registerPPCallbacks``.  The 
``add_new_check.py`` script
 does not generate an override for this method in the starting point for your
 new check.
 
-If your check applies only under a specific set of language options, be sure
-to override the method ``isLanguageVersionSupported`` to reflect that.
-
 Check development tips
 --
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread Marco C. via cfe-commits

https://github.com/Marcondiro updated 
https://github.com/llvm/llvm-project/pull/129209

>From fbd2aa34805c3415f66410ae282f0ceeb7bd7b64 Mon Sep 17 00:00:00 2001
From: Marcondiro <46560192+marcond...@users.noreply.github.com>
Date: Fri, 28 Feb 2025 09:34:30 +0100
Subject: [PATCH] [clang-tidy] Contributing.rst update snippet and docs

This reflects the add_new_check.py changes: isLanguageVersionSupported
is now overridden by default by the script
---
 .../docs/clang-tidy/Contributing.rst| 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 4f1df8d11..9611c655886f2 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -149,6 +149,9 @@ After choosing the module and the name for the check, run 
the
 ``clang-tidy/add_new_check.py`` script to create the skeleton of the check and
 plug it to :program:`clang-tidy`. It's the recommended way of adding new 
checks.
 
+By default, the new check will apply only to C++ code. If it should apply under
+different language options, use the ``--language`` script's parameter.
+
 If we want to create a `readability-awesome-function-names`, we would run:
 
 .. code-block:: console
@@ -171,9 +174,7 @@ Let's see in more detail at the check class definition:
 
   #include "../ClangTidyCheck.h"
 
-  namespace clang {
-  namespace tidy {
-  namespace readability {
+  namespace clang::tidy::readability {
 
   ...
   class AwesomeFunctionNamesCheck : public ClangTidyCheck {
@@ -182,11 +183,12 @@ Let's see in more detail at the check class definition:
 : ClangTidyCheck(Name, Context) {}
 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+bool isLanguageVersionSupported(const LangOptions &LangOpts) const 
override {
+  return LangOpts.CPlusPlus;
+}
   };
 
-  } // namespace readability
-  } // namespace tidy
-  } // namespace clang
+  } // namespace clang::tidy::readability
 
   ...
 
@@ -231,9 +233,6 @@ override the method ``registerPPCallbacks``.  The 
``add_new_check.py`` script
 does not generate an override for this method in the starting point for your
 new check.
 
-If your check applies only under a specific set of language options, be sure
-to override the method ``isLanguageVersionSupported`` to reflect that.
-
 Check development tips
 --
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread Marco C. via cfe-commits


@@ -203,6 +202,10 @@ for more information) that will find the pattern in the 
AST that we want to
 inspect. The results of the matching are passed to the ``check`` method, which
 can further inspect them and report diagnostics.
 
+By default, the new check applies only to C++ code. If it should apply under 
+different language options, be sure to update the 
``isLanguageVersionSupported``

Marcondiro wrote:

Yes, good point, fixed

https://github.com/llvm/llvm-project/pull/129209
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread Marco C. via cfe-commits

https://github.com/Marcondiro updated 
https://github.com/llvm/llvm-project/pull/129209

>From 58972d1e22af7306ae3583a487cb9bf466714b58 Mon Sep 17 00:00:00 2001
From: Marcondiro <46560192+marcond...@users.noreply.github.com>
Date: Fri, 28 Feb 2025 09:34:30 +0100
Subject: [PATCH] [clang-tidy] Contributing.rst update snippet and docs

This reflects the add_new_check.py changes: isLanguageVersionSupported
is now overridden by default by the script
---
 .../docs/clang-tidy/Contributing.rst| 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 4f1df8d11..9611c655886f2 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -149,6 +149,9 @@ After choosing the module and the name for the check, run 
the
 ``clang-tidy/add_new_check.py`` script to create the skeleton of the check and
 plug it to :program:`clang-tidy`. It's the recommended way of adding new 
checks.
 
+By default, the new check will apply only to C++ code. If it should apply under
+different language options, use the ``--language`` script's parameter.
+
 If we want to create a `readability-awesome-function-names`, we would run:
 
 .. code-block:: console
@@ -171,9 +174,7 @@ Let's see in more detail at the check class definition:
 
   #include "../ClangTidyCheck.h"
 
-  namespace clang {
-  namespace tidy {
-  namespace readability {
+  namespace clang::tidy::readability {
 
   ...
   class AwesomeFunctionNamesCheck : public ClangTidyCheck {
@@ -182,11 +183,12 @@ Let's see in more detail at the check class definition:
 : ClangTidyCheck(Name, Context) {}
 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+bool isLanguageVersionSupported(const LangOptions &LangOpts) const 
override {
+  return LangOpts.CPlusPlus;
+}
   };
 
-  } // namespace readability
-  } // namespace tidy
-  } // namespace clang
+  } // namespace clang::tidy::readability
 
   ...
 
@@ -231,9 +233,6 @@ override the method ``registerPPCallbacks``.  The 
``add_new_check.py`` script
 does not generate an override for this method in the starting point for your
 new check.
 
-If your check applies only under a specific set of language options, be sure
-to override the method ``isLanguageVersionSupported`` to reflect that.
-
 Check development tips
 --
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread Marco C. via cfe-commits

Marcondiro wrote:

@carlosgalvezp I do not have the ability to merge the PR, could you do it? 
thanks!

https://github.com/llvm/llvm-project/pull/129209
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Contributing.rst update snippet and docs (PR #129209)

2025-02-28 Thread Marco C. via cfe-commits

https://github.com/Marcondiro updated 
https://github.com/llvm/llvm-project/pull/129209

>From c1bb0f84852e223a83638384188e4858877ec89e Mon Sep 17 00:00:00 2001
From: Marcondiro <46560192+marcond...@users.noreply.github.com>
Date: Fri, 28 Feb 2025 09:34:30 +0100
Subject: [PATCH] [clang-tidy] Contributing.rst update snippet and docs

This reflects the add_new_check.py changes: isLanguageVersionSupported
is now overridden by default by the script
---
 .../docs/clang-tidy/Contributing.rst| 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/clang-tools-extra/docs/clang-tidy/Contributing.rst 
b/clang-tools-extra/docs/clang-tidy/Contributing.rst
index 4f1df8d11..9611c655886f2 100644
--- a/clang-tools-extra/docs/clang-tidy/Contributing.rst
+++ b/clang-tools-extra/docs/clang-tidy/Contributing.rst
@@ -149,6 +149,9 @@ After choosing the module and the name for the check, run 
the
 ``clang-tidy/add_new_check.py`` script to create the skeleton of the check and
 plug it to :program:`clang-tidy`. It's the recommended way of adding new 
checks.
 
+By default, the new check will apply only to C++ code. If it should apply under
+different language options, use the ``--language`` script's parameter.
+
 If we want to create a `readability-awesome-function-names`, we would run:
 
 .. code-block:: console
@@ -171,9 +174,7 @@ Let's see in more detail at the check class definition:
 
   #include "../ClangTidyCheck.h"
 
-  namespace clang {
-  namespace tidy {
-  namespace readability {
+  namespace clang::tidy::readability {
 
   ...
   class AwesomeFunctionNamesCheck : public ClangTidyCheck {
@@ -182,11 +183,12 @@ Let's see in more detail at the check class definition:
 : ClangTidyCheck(Name, Context) {}
 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+bool isLanguageVersionSupported(const LangOptions &LangOpts) const 
override {
+  return LangOpts.CPlusPlus;
+}
   };
 
-  } // namespace readability
-  } // namespace tidy
-  } // namespace clang
+  } // namespace clang::tidy::readability
 
   ...
 
@@ -231,9 +233,6 @@ override the method ``registerPPCallbacks``.  The 
``add_new_check.py`` script
 does not generate an override for this method in the starting point for your
 new check.
 
-If your check applies only under a specific set of language options, be sure
-to override the method ``isLanguageVersionSupported`` to reflect that.
-
 Check development tips
 --
 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits