[clang-tools-extra] [clang-tidy][NFC] fix formatting of `namespace-comment-check` (PR #143305)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 8 04:15:10 PDT 2025
https://github.com/vbvictor created https://github.com/llvm/llvm-project/pull/143305
Fixed formatting and codestyle issues in `namespace-comment-check`
Follow up to https://github.com/llvm/llvm-project/pull/124265.
>From 69518ec57cfae7840469fd05b97a413c10945cb2 Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Sun, 8 Jun 2025 14:11:43 +0300
Subject: [PATCH] [clang-tidy][nfc] fix formatting of namespace-comment-check
---
.../readability/NamespaceCommentCheck.cpp | 20 ++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
index 12e52d6afad56..c04bf361c40ca 100644
--- a/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamespaceCommentCheck.cpp
@@ -28,12 +28,14 @@ NamespaceCommentCheck::NamespaceCommentCheck(StringRef Name,
llvm::Regex::IgnoreCase),
ShortNamespaceLines(Options.get("ShortNamespaceLines", 1U)),
SpacesBeforeComments(Options.get("SpacesBeforeComments", 1U)),
- AllowOmittingNamespaceComments(Options.get("AllowOmittingNamespaceComments", false)) {}
+ 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);
+ Options.store(Opts, "AllowOmittingNamespaceComments",
+ AllowOmittingNamespaceComments);
}
void NamespaceCommentCheck::registerMatchers(MatchFinder *Finder) {
@@ -108,7 +110,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
// Currently for nested namespace (n1::n2::...) the AST matcher will match foo
// then bar instead of a single match. So if we got a nested namespace we have
// to skip the next ones.
- for (const auto &EndOfNameLocation : Ends) {
+ for (const SourceLocation &EndOfNameLocation : Ends) {
if (Sources.isBeforeInTranslationUnit(ND->getLocation(), EndOfNameLocation))
return;
}
@@ -142,7 +144,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;
+ bool HasComment = false;
// Try to find existing namespace closing comment on the same line.
if (Tok.is(tok::comment) && NextTokenIsOnSameLine) {
@@ -161,7 +163,7 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
- hasComment = true;
+ HasComment = true;
// Otherwise we need to fix the comment.
NeedLineBreak = Comment.starts_with("/*");
@@ -185,13 +187,13 @@ void NamespaceCommentCheck::check(const MatchFinder::MatchResult &Result) {
}
std::string NamespaceNameForDiag =
- ND->isAnonymousNamespace() ? "anonymous namespace"
- : ("namespace '" + *NamespaceNameAsWritten + "'");
+ ND->isAnonymousNamespace()
+ ? "anonymous namespace"
+ : ("namespace '" + *NamespaceNameAsWritten + "'");
// If no namespace comment is allowed
- if(!hasComment && AllowOmittingNamespaceComments) {
+ if (!HasComment && AllowOmittingNamespaceComments)
return;
- }
std::string Fix(SpacesBeforeComments, ' ');
Fix.append("// namespace");
More information about the cfe-commits
mailing list