[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
thorsten-klein wrote: Thanks a lot for your review @vbvictor! I have resolved your review findings. What do you think about the option's name? Is `AllowNoNamespaceComments` fine for you or shall I rename to `AllowOmittingNamespaceComments` (or any other suggestion)? https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 608ceb0bb475aad65abb55a1dd02bf84d62ec99c Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowNoNamespaceComments added for google-readability-namespace-comments. When true, the check will allow that namespace comments are ommitted entirely. The check only fails if a namespace comment is present but does not match. Default is `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 ++- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 7 ++ .../checks/llvm/namespace-comment.rst | 8 ++ ...ility-namespace-comments-missing-c++17.cpp | 55 +++ ...readability-namespace-comments-missing.cpp | 91 +++ 6 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-c++17.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 120ec02e9ad7dc..fd306d5b5fb08b 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -28,11 +28,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowNoNamespaceComments(Options.get("AllowNoNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowNoNamespaceComments", AllowNoNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -141,6 +143,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -159,6 +162,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -184,6 +189,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowNoNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd8..1ecb37fdd8d5da 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowNoNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index cc5f64a3f9fa32..e41e7719988b14 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -402,6 +402,13 @@ Changes in existing checks ` check to use correct template type in ``std::min`` and ``std::max`` when operand is integer literal. +- Improved :doc:`google-readability-namespace-comments + ` that permits + omitting namespace comments entirely. With this option enabled, the check + only fails if a namespace comment is present but does not match namespace + definition. + + Removed checks ^^ diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst inde
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein created https://github.com/llvm/llvm-project/pull/124265 new option AllowNoNamespaceComments for `google-readability-namespace-comments.AllowNoNamespaceComments` is added. Ref: #124264 When true, the check will allow that no namespace comment is present. If a namespace comment is added but it is not matching, the check will fail. Default is `false` >From 70cb3de61ae28220c556522249d1db9b93eaec85 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowNoNamespaceComments for google-readability-namespace-comments is added. When true, the check will allow that no namespace comment is present. If a namespace comment is added but it is not matching, the check will fail. Default is `false` --- .../readability/NamespaceCommentCheck.cpp | 12 ++- .../readability/NamespaceCommentCheck.h | 1 + .../checks/llvm/namespace-comment.rst | 7 ++ ...ility-namespace-comments-missing-c++17.cpp | 59 ...readability-namespace-comments-missing.cpp | 91 +++ 5 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-c++17.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 120ec02e9ad7dc..fd306d5b5fb08b 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -28,11 +28,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowNoNamespaceComments(Options.get("AllowNoNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowNoNamespaceComments", AllowNoNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -141,6 +143,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -159,6 +162,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -184,6 +189,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowNoNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd8..1ecb37fdd8d5da 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowNoNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af3..f722800bebc460 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst @@ -39,3 +39,10 @@ Options An unsigned integer specifying the number of spaces before the comment closing a namespace definition. Default is `1U`. + + +.. option:: AllowNoNamespaceComments + + When true, the check will allow that no nam
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 15a8d29ef422afe853adeb1fd66e5218d9ebfa34 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowNoNamespaceComments added for google-readability-namespace-comments. When true, the check will allow that namespace comments are ommitted entirely. The check only fails if a namespace comment is present but does not match. Default is `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 ++- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 6 ++ .../checks/llvm/namespace-comment.rst | 8 ++ ...ility-namespace-comments-missing-c++17.cpp | 59 ...readability-namespace-comments-missing.cpp | 91 +++ 6 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-c++17.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 120ec02e9ad7dc..fd306d5b5fb08b 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -28,11 +28,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowNoNamespaceComments(Options.get("AllowNoNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowNoNamespaceComments", AllowNoNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -141,6 +143,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -159,6 +162,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -184,6 +189,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowNoNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd8..1ecb37fdd8d5da 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowNoNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index cc5f64a3f9fa32..6896b41300be77 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -402,6 +402,12 @@ Changes in existing checks ` check to use correct template type in ``std::min`` and ``std::max`` when operand is integer literal. +- Improved :doc:`google-readability-namespace-comments + ` that permits + omitting namespace comments entirely. With this option enabled, the check + only fails if a namespace comment is present but does not match. + + Removed checks ^^ diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af3..a5773
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein edited https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein edited https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
@@ -287,6 +287,11 @@ Changes in existing checks ` check to report a location even when the member location is not valid. +- Improved :doc:`google-readability-namespace-comments + ` check to + add an option ``AllowNoNamespaceComments``, that permits thorsten-klein wrote: I made it consistent to already existing ReleaseNote entry. Ref: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/docs/ReleaseNotes.rst?plain=1#L334 > - Improved :doc:`modernize-use-integer-sign-comparison ` check to add an option ``EnableQtSupport``, that makes C++17 ``q20::cmp_*`` alternative available for Qt-based applications. Shall I really use single back-tick or keep it consistent with double back-ticks as already existing? https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From bade51bc7f0135e5c74cc64ee851a17813c6820f Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowNoNamespaceComments added for google-readability-namespace-comments. When true, the check will allow that namespace comments are ommitted entirely. The check only fails if a namespace comment is present but does not match. Default is `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 ++- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 5 + .../checks/llvm/namespace-comment.rst | 6 ++ ...ility-namespace-comments-missing-c++17.cpp | 55 +++ ...readability-namespace-comments-missing.cpp | 91 +++ 6 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-c++17.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 120ec02e9ad7dc..fd306d5b5fb08b 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -28,11 +28,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowNoNamespaceComments(Options.get("AllowNoNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowNoNamespaceComments", AllowNoNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -141,6 +143,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -159,6 +162,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -184,6 +189,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowNoNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd8..1ecb37fdd8d5da 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowNoNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index cc5f64a3f9fa32..915ceaf56c3cb7 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -287,6 +287,11 @@ Changes in existing checks ` check to report a location even when the member location is not valid. +- Improved :doc:`google-readability-namespace-comments + ` check to + add an option ``AllowNoNamespaceComments``, that permits + omitting namespace comments entirely. + - Improved :doc:`misc-definitions-in-headers ` check by rewording the diagnostic note that suggests adding ``inline``. diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
thorsten-klein wrote: @EugeneZelenko What do you think about some additional option `EnforceNoNamespaceComments` in order to enforce that no namespace comment is present? If you like the idea, I could create some additional PR for introducing this option. https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 9f3bc5021e6da87fa9a8db60b513acb87ed6b02f Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowNoNamespaceComments added for google-readability-namespace-comments. When true, the check will allow that namespace comments are ommitted entirely. The check only fails if a namespace comment is present but does not match. Default is `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 ++- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 5 + .../checks/llvm/namespace-comment.rst | 6 ++ ...ility-namespace-comments-missing-c++17.cpp | 55 +++ ...readability-namespace-comments-missing.cpp | 91 +++ 6 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-c++17.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 120ec02e9ad7dc..3d24ed5337c124 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -28,11 +28,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowNoNamespaceComments(Options.get("AllowNoNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowNoNamespaceComments", AllowNoNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -141,6 +143,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -159,6 +162,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -184,6 +189,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if (!hasComment && AllowNoNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd8..1ecb37fdd8d5da 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowNoNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index cc5f64a3f9fa32..fe2323e0e76d58 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -287,6 +287,11 @@ Changes in existing checks ` check to report a location even when the member location is not valid. +- Improved :doc:`google-readability-namespace-comments + ` check to add an + option `AllowNoNamespaceComments`, that permits omitting namespace comments + entirely. + - Improved :doc:`misc-definitions-in-headers ` check by rewording the diagnostic note that suggests adding ``inline``. diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af3
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From b1bfe0682f9889ae792ada546d3e4f1cd86acf69 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When true, the check will accept if no namespace comment is present. The check will only fail if a namespace comment is specified which is different than expeced. Defaults to `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 ++- .../readability/NamespaceCommentCheck.h | 1 + .../checks/llvm/namespace-comment.rst | 8 ++ ...ility-namespace-comments-missing-c++17.cpp | 59 ...readability-namespace-comments-missing.cpp | 91 +++ 5 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-c++17.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af..3c2c20fb9731b 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst @@ -39,3 +39,11 @@ Options An unsigned integer specifying the number of spaces before the comment closing a namespace definition. Default is `1U`. + + +.. option:: AllowOmittingNamespaceComments + + When true, the check will accept if no namespace comment is present. + The check will only fail if a namespace comment is specified which is + different than expeced. Defaults to `false`. + diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-c
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 9a2171658093b791e08f0f2b93e132be3a4419f5 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When `true`, the check will accept if no namespace comment is present. The check will only fail if the specified namespace comment is different than expected. Defaults to `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 - .../readability/NamespaceCommentCheck.h | 1 + .../checks/llvm/namespace-comment.rst | 7 + ...ace-comments-missing-nested-namespaces.cpp | 23 ...readability-namespace-comments-missing.cpp | 27 +++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af..6e17eac214463 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst @@ -39,3 +39,10 @@ Options An unsigned integer specifying the number of spaces before the comment closing a namespace definition. Default is `1U`. + +.. option:: AllowOmittingNamespaceComments + + When `true`, the check will accept if no namespace comment is present. + The check will only fail if the specified namespace comment is different + than expected. Defaults to `false`. + diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readabili
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 4f44b9294bf290332faf3223d17999565cbea4d4 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When `true`, the check will accept if no namespace comment is present. The check will only fail if the specified namespace comment is different than expected. Default is `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 +- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 10 + .../checks/llvm/namespace-comment.rst | 7 ...ace-comments-missing-nested-namespaces.cpp | 32 +++ ...readability-namespace-comments-missing.cpp | 40 +++ 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e0f81a032c38d..bb3a3b39fb8bc 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -187,6 +187,16 @@ Changes in existing checks ` check by fixing a false positive where ``strerror`` was flagged as MT-unsafe. +- Improved :doc:`google-readability-namespace-comments + ` check by adding + the option `AllowOmittingNamespaceComments` to accept if a namespace comment + is omitted entirely. + +- Improved :doc:`llvm-namespace-comment + ` check by adding the option + `AllowOmittingNamespaceComments` to accept if a namespace comment is omitted + entirely. + - Improved :doc:`misc-const-correctness `
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 150cb66b9e440d9ed2019b5ceb9a26ed8c21942b Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When `true`, the check will accept if no namespace comment is present. The check will only fail if the specified namespace comment is different than expected. Defaults to `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 +- .../readability/NamespaceCommentCheck.h | 1 + .../checks/llvm/namespace-comment.rst | 7 ...ace-comments-missing-nested-namespaces.cpp | 32 +++ ...readability-namespace-comments-missing.cpp | 40 +++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst index be90260be73af..6e17eac214463 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comment.rst @@ -39,3 +39,10 @@ Options An unsigned integer specifying the number of spaces before the comment closing a namespace definition. Default is `1U`. + +.. option:: AllowOmittingNamespaceComments + + When `true`, the check will accept if no namespace comment is present. + The check will only fail if the specified namespace comment is different + than expected. Defaults to `false`. + diff --git a/clang-tools-extra/test/clang-tidy/checkers/google/readability-na
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein edited https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
@@ -187,6 +187,11 @@ Changes in existing checks ` check by fixing a false positive where ``strerror`` was flagged as MT-unsafe. +- Improved :doc:`google-readability-namespace-comments thorsten-klein wrote: I will add another ReleaseNotes entry. Shall I run the tests for this `llvm-namespace-comment` check as well (e.g. a separate `RUN`)? https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From a683a7b33fe9b2e06e5116261b8decf233d72d67 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When `true`, the check will accept if no namespace comment is present. The check will only fail if the specified namespace comment is different than expected. Defaults to `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 +- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 10 + .../checks/llvm/namespace-comment.rst | 7 ...ace-comments-missing-nested-namespaces.cpp | 32 +++ ...readability-namespace-comments-missing.cpp | 40 +++ 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e0f81a032c38d..bb3a3b39fb8bc 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -187,6 +187,16 @@ Changes in existing checks ` check by fixing a false positive where ``strerror`` was flagged as MT-unsafe. +- Improved :doc:`google-readability-namespace-comments + ` check by adding + the option `AllowOmittingNamespaceComments` to accept if a namespace comment + is omitted entirely. + +- Improved :doc:`llvm-namespace-comment + ` check by adding the option + `AllowOmittingNamespaceComments` to accept if a namespace comment is omitted + entirely. + - Improved :doc:`misc-const-correctness
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
@@ -187,6 +187,11 @@ Changes in existing checks ` check by fixing a false positive where ``strerror`` was flagged as MT-unsafe. +- Improved :doc:`google-readability-namespace-comments thorsten-klein wrote: > Shall I run the tests for this llvm-namespace-comment check as well (e.g. a > separate RUN)? OK. This does not make sense. Then google and llvm checks would be mixed in one .cpp file. And additionally the `CHECK-MESSAGES` is not compatible. https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From a6556aebc4f70be5e8be805fd009589fa7e0dc22 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When `true`, the check will accept if no namespace comment is present. The check will only fail if the specified namespace comment is different than expected. Defaults to `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 +- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 5 +++ .../checks/llvm/namespace-comment.rst | 7 ...ace-comments-missing-nested-namespaces.cpp | 32 +++ ...readability-namespace-comments-missing.cpp | 40 +++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e0f81a032c38d..f17b86b5de13e 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -187,6 +187,11 @@ Changes in existing checks ` check by fixing a false positive where ``strerror`` was flagged as MT-unsafe. +- Improved :doc:`google-readability-namespace-comments + ` check by adding + the option `AllowOmittingNamespaceComments` to accept if a namespace comment + is omitted entirely. + - Improved :doc:`misc-const-correctness ` check by adding the option `AllowedTypes`, that excludes specified types from const-correctness diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 6bbb691e844e51b40e38958c22678bb066d301f5 Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When `true`, the check will accept if no namespace comment is present. The check will only fail if the specified namespace comment is different than expected. Default is `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 +- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 10 + .../checks/llvm/namespace-comment.rst | 6 +++ ...ace-comments-missing-nested-namespaces.cpp | 32 +++ ...readability-namespace-comments-missing.cpp | 40 +++ 6 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e0f81a032c38d..bb3a3b39fb8bc 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -187,6 +187,16 @@ Changes in existing checks ` check by fixing a false positive where ``strerror`` was flagged as MT-unsafe. +- Improved :doc:`google-readability-namespace-comments + ` check by adding + the option `AllowOmittingNamespaceComments` to accept if a namespace comment + is omitted entirely. + +- Improved :doc:`llvm-namespace-comment + ` check by adding the option + `AllowOmittingNamespaceComments` to accept if a namespace comment is omitted + entirely. + - Improved :doc:`misc-const-correctness `
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
https://github.com/thorsten-klein updated https://github.com/llvm/llvm-project/pull/124265 >From 0c0f9a860e060eecb23a541f478772a3f7b2731c Mon Sep 17 00:00:00 2001 From: "Klein, Thorsten (GDE-EDSI1)" Date: Fri, 24 Jan 2025 13:46:24 +0100 Subject: [PATCH] added option AllowNoNamespaceComments for google-readability-namespace-comments new option AllowOmittingNamespaceComments for google-readability-namespace-comments is added. When `true`, the check will accept if no namespace comment is present. The check will only fail if the specified namespace comment is different than expected. Defaults to `false`. --- .../readability/NamespaceCommentCheck.cpp | 12 +- .../readability/NamespaceCommentCheck.h | 1 + clang-tools-extra/docs/ReleaseNotes.rst | 5 +++ .../checks/llvm/namespace-comment.rst | 7 ...ace-comments-missing-nested-namespaces.cpp | 32 +++ ...readability-namespace-comments-missing.cpp | 40 +++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing-nested-namespaces.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/google/readability-namespace-comments-missing.cpp diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp index 64dc941569a96..12e52d6afad56 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp @@ -27,11 +27,13 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name, "namespace( +(((inline )|([a-zA-Z0-9_:]))+))?\\.? *(\\*/)?$", llvm::Regex::IgnoreCase), ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)), - SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)) {} + SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)), + AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {} void NamespaceCommentCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "ShortNamespaceLines", ShortNamespaceLines); Options.store(Opts, "SpacesBeforeComments", SpacesBeforeComments); + Options.store(Opts, "AllowOmittingNamespaceComments", AllowOmittingNamespaceComments); } void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) { @@ -140,6 +142,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { SourceRange OldCommentRange(AfterRBrace, AfterRBrace); std::string Message = "%0 not terminated with a closing comment"; + bool hasComment = false; // Try to find existing namespace closing comment on the same line. if (Tok.is(tok::comment) && NextTokenIsOnSameLine) { @@ -158,6 +161,8 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { return; } + hasComment = true; + // Otherwise we need to fix the comment. NeedLineBreak = Comment.starts_with("/*"); OldCommentRange = @@ -183,6 +188,11 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) { ND->isAnonymousNamespace() ? "anonymous namespace" : ("namespace '" + *NamespaceNameAsWritten + "'"); + // If no namespace comment is allowed + if(!hasComment && AllowOmittingNamespaceComments) { +return; + } + std::string Fix(SpacesBeforeComments, ' '); Fix.append("// namespace"); if (!ND->isAnonymousNamespace()) diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h index 7607d37b1b2fd..8edd77213f779 100644 --- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h +++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.h @@ -34,6 +34,7 @@ class NamespaceCommentCheck : public ClangTidyCheck { llvm::Regex NamespaceCommentPattern; const unsigned ShortNamespaceLines; const unsigned SpacesBeforeComments; + const bool AllowOmittingNamespaceComments; llvm::SmallVector Ends; }; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index e0f81a032c38d..160a87e9943cc 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -187,6 +187,11 @@ Changes in existing checks ` check by fixing a false positive where ``strerror`` was flagged as MT-unsafe. +- Improved :doc:`google-readability-namespace-comments + ` check by adding + the option `AllowOmittingNamespaceComments` to accept if no namespace comment + is specified. + - Improved :doc:`misc-const-correctness ` check by adding the option `AllowedTypes`, that excludes specified types from const-correctness diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/namespace-comme
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
thorsten-klein wrote: My e-mail address is now public 👍 https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] added option `google-readability-namespace-comments.AllowNoNamespaceComments` (PR #124265)
thorsten-klein wrote: I have no access to a computer today. I can fix tomorrow, if it has not been fixed before. https://github.com/llvm/llvm-project/pull/124265 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits