[clang-tools-extra] 47caa69 - [clang-tidy] Use ; as separator for HeaderFileExtensions

Jonathan Roelofs via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 9 10:33:17 PDT 2020


Author: Jonathan Roelofs
Date: 2020-03-09T11:32:44-06:00
New Revision: 47caa69120e582bf1b795ec646f069c83b0e9456

URL: https://github.com/llvm/llvm-project/commit/47caa69120e582bf1b795ec646f069c83b0e9456
DIFF: https://github.com/llvm/llvm-project/commit/47caa69120e582bf1b795ec646f069c83b0e9456.diff

LOG: [clang-tidy] Use ; as separator for HeaderFileExtensions

... and deprecate use of ',' for the same.

https://reviews.llvm.org/D75621

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
    clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
    clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
    clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
    clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
    clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
    clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
    clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
    clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
    clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
    clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
    clang-tools-extra/clang-tidy/utils/HeaderGuard.h
    clang-tools-extra/docs/ReleaseNotes.rst

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 7403762122bd..d4d3ff9af75e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -32,7 +32,8 @@ DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(StringRef Name,
       RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
         "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
   if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-                                  HeaderFileExtensions, ',')) {
+                                  HeaderFileExtensions,
+                                  utils::defaultFileExtensionDelimiters())) {
     llvm::errs() << "Invalid header file extension: "
                  << RawStringHeaderFileExtensions << "\n";
   }

diff  --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index ac0d32202d61..f06b2d036386 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -19,11 +19,12 @@ namespace bugprone {
 /// Finds dynamically initialized static variables in header files.
 ///
 /// The check supports these options:
-///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
-///     header files (The filename extensions should not contain "." prefix).
-///     "h,hh,hpp,hxx" by default.
+///   - `HeaderFileExtensions`: a semicolon-separated list of filename
+///     extensions of header files (The filename extensions should not contain
+///     "." prefix). ";h;hh;hpp;hxx" by default.
+//
 ///     For extension-less header files, using an empty string or leaving an
-///     empty string between "," if there are other filename extensions.
+///     empty string between ";" if there are other filename extensions.
 class DynamicStaticInitializersCheck : public ClangTidyCheck {
 public:
   DynamicStaticInitializersCheck(StringRef Name, ClangTidyContext *Context);

diff  --git a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
index 09eb266efb35..968adb882391 100644
--- a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.cpp
@@ -25,7 +25,8 @@ GlobalNamesInHeadersCheck::GlobalNamesInHeadersCheck(StringRef Name,
       RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
           "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
   if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-                                  HeaderFileExtensions, ',')) {
+                                  HeaderFileExtensions,
+                                  utils::defaultFileExtensionDelimiters())) {
     llvm::errs() << "Invalid header file extension: "
                  << RawStringHeaderFileExtensions << "\n";
   }

diff  --git a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
index cd69df72962e..aa569dedcdb4 100644
--- a/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
+++ b/clang-tools-extra/clang-tidy/google/GlobalNamesInHeadersCheck.h
@@ -21,11 +21,12 @@ namespace readability {
 /// Right now it only triggers on using declarations and directives.
 ///
 /// The check supports these options:
-///   - `HeaderFileExtensions`: a comma-separated list of filename extensions
-///     of header files (the filename extensions should not contain "." prefix).
-///     "h" by default.
+///   - `HeaderFileExtensions`: a semicolon-separated list of filename
+///     extensions of header files (the filename extensions should not contain
+///     "." prefix). ";h;hh;hpp;hxx" by default.
+///
 ///     For extension-less header files, using an empty string or leaving an
-///     empty string between "," if there are other filename extensions.
+///     empty string between ";" if there are other filename extensions.
 class GlobalNamesInHeadersCheck : public ClangTidyCheck {
 public:
   GlobalNamesInHeadersCheck(StringRef Name, ClangTidyContext *Context);

diff  --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
index 1c277d7f665b..fa1df281326c 100644
--- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.cpp
@@ -24,7 +24,8 @@ UnnamedNamespaceInHeaderCheck::UnnamedNamespaceInHeaderCheck(
       RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
           "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
   if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-                                  HeaderFileExtensions, ',')) {
+                                  HeaderFileExtensions,
+                                  utils::defaultFileExtensionDelimiters())) {
     llvm::errs() << "Invalid header file extension: "
                  << RawStringHeaderFileExtensions << "\n";
   }

diff  --git a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
index 025637d08d4e..52af823e6a0e 100644
--- a/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
+++ b/clang-tools-extra/clang-tidy/google/UnnamedNamespaceInHeaderCheck.h
@@ -20,11 +20,12 @@ namespace build {
 /// Finds anonymous namespaces in headers.
 ///
 /// The check supports these options:
-///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
-///     header files (The filename extensions should not contain "." prefix).
-///     "h,hh,hpp,hxx" by default.
+///   - `HeaderFileExtensions`: a semicolon-separated list of filename
+///     extensions of header files (The filename extensions should not contain
+///     "." prefix). ";h;hh;hpp;hxx" by default.
+///
 ///     For extension-less header files, using an empty string or leaving an
-///     empty string between "," if there are other filename extensions.
+///     empty string between ";" if there are other filename extensions.
 ///
 /// https://google.github.io/styleguide/cppguide.html#Namespaces
 ///

diff  --git a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
index d759a638cc2e..23f12fd6860a 100644
--- a/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
+++ b/clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
@@ -19,11 +19,12 @@ namespace llvm_check {
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/llvm-header-guard.html
 /// The check supports these options:
-///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
-///     header files (The filename extension should not contain "." prefix).
-///     ",h,hh,hpp,hxx" by default.
+///   - `HeaderFileExtensions`: a semicolon-separated list of filename
+///     extensions of header files (The filename extension should not contain
+///     "." prefix). ";h;hh;hpp;hxx" by default.
+///
 ///     For extension-less header files, using an empty string or leaving an
-///     empty string between "," if there are other filename extensions.
+///     empty string between ";" if there are other filename extensions.
 class LLVMHeaderGuardCheck : public utils::HeaderGuardCheck {
 public:
   LLVMHeaderGuardCheck(StringRef Name, ClangTidyContext *Context);

diff  --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
index 6d743bf51765..6b4618ea042c 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -34,7 +34,8 @@ DefinitionsInHeadersCheck::DefinitionsInHeadersCheck(StringRef Name,
       RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
           "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
   if (!utils::parseFileExtensions(RawStringHeaderFileExtensions,
-                                  HeaderFileExtensions, ',')) {
+                                  HeaderFileExtensions,
+                                  utils::defaultFileExtensionDelimiters())) {
     // FIXME: Find a more suitable way to handle invalid configuration
     // options.
     llvm::errs() << "Invalid header file extension: "

diff  --git a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
index 48abe799bc84..239b7d1c1d92 100644
--- a/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
+++ b/clang-tools-extra/clang-tidy/misc/DefinitionsInHeadersCheck.h
@@ -22,11 +22,12 @@ namespace misc {
 /// The check supports these options:
 ///   - `UseHeaderFileExtension`: Whether to use file extension to distinguish
 ///     header files. True by default.
-///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
-///     header files (The filename extension should not contain "." prefix).
-///     ",h,hh,hpp,hxx" by default.
+///   - `HeaderFileExtensions`: a semicolon-separated list of filename
+///     extensions of header files (The filename extension should not contain
+///     "." prefix). ";h;hh;hpp;hxx" by default.
+///
 ///     For extension-less header files, using an empty string or leaving an
-///     empty string between "," if there are other filename extensions.
+///     empty string between ";" if there are other filename extensions.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/misc-definitions-in-headers.html

diff  --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
index c016a72362c5..d6f4b2ae3f7c 100644
--- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.cpp
@@ -33,9 +33,16 @@ bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
 }
 
 bool parseFileExtensions(StringRef AllFileExtensions,
-                         FileExtensionsSet &FileExtensions, char Delimiter) {
+                         FileExtensionsSet &FileExtensions,
+                         StringRef Delimiters) {
   SmallVector<StringRef, 5> Suffixes;
-  AllFileExtensions.split(Suffixes, Delimiter);
+  for (char Delimiter : Delimiters) {
+    if (AllFileExtensions.contains(Delimiter)) {
+      AllFileExtensions.split(Suffixes, Delimiter);
+      break;
+    }
+  }
+
   FileExtensions.clear();
   for (StringRef Suffix : Suffixes) {
     StringRef Extension = Suffix.trim();

diff  --git a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
index f83d357946c4..4b7810430427 100644
--- a/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/FileExtensionsUtils.h
@@ -34,11 +34,16 @@ bool isSpellingLocInHeaderFile(SourceLocation Loc, SourceManager &SM,
 
 /// Returns recommended default value for the list of header file
 /// extensions.
-inline StringRef defaultHeaderFileExtensions() { return ",h,hh,hpp,hxx"; }
+inline StringRef defaultHeaderFileExtensions() { return ";h;hh;hpp;hxx"; }
+
+/// Returns recommended default value for the list of file extension
+/// delimiters.
+inline StringRef defaultFileExtensionDelimiters() { return ",;"; }
 
 /// Parses header file extensions from a semicolon-separated list.
 bool parseFileExtensions(StringRef AllFileExtensions,
-                         FileExtensionsSet &FileExtensions, char Delimiter);
+                         FileExtensionsSet &FileExtensions,
+                         StringRef Delimiters);
 
 /// Decides whether a file has one of the specified file extensions.
 bool isFileExtension(StringRef FileName,

diff  --git a/clang-tools-extra/clang-tidy/utils/HeaderGuard.h b/clang-tools-extra/clang-tidy/utils/HeaderGuard.h
index cc3cafdeece9..7ce54f42865d 100644
--- a/clang-tools-extra/clang-tidy/utils/HeaderGuard.h
+++ b/clang-tools-extra/clang-tidy/utils/HeaderGuard.h
@@ -18,11 +18,12 @@ namespace utils {
 
 /// Finds and fixes header guards.
 /// The check supports these options:
-///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
-///     header files (The filename extension should not contain "." prefix).
-///     ",h,hh,hpp,hxx" by default.
+///   - `HeaderFileExtensions`: a semicolon-separated list of filename
+///     extensions of header files (The filename extension should not contain
+///     "." prefix). ";h;hh;hpp;hxx" by default.
+///
 ///     For extension-less header files, using an empty string or leaving an
-///     empty string between "," if there are other filename extensions.
+///     empty string between ";" if there are other filename extensions.
 class HeaderGuardCheck : public ClangTidyCheck {
 public:
   HeaderGuardCheck(StringRef Name, ClangTidyContext *Context)
@@ -30,7 +31,8 @@ class HeaderGuardCheck : public ClangTidyCheck {
         RawStringHeaderFileExtensions(Options.getLocalOrGlobal(
             "HeaderFileExtensions", utils::defaultHeaderFileExtensions())) {
     utils::parseFileExtensions(RawStringHeaderFileExtensions,
-                               HeaderFileExtensions, ',');
+                               HeaderFileExtensions,
+                               utils::defaultFileExtensionDelimiters());
   }
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
                            Preprocessor *ModuleExpanderPP) override;

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 0350962c5c86..3a58649ea985 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -125,6 +125,11 @@ Changes in existing checks
   check now detects in class initializers and constructor initializers which
   are deemed to be redundant.
 
+- Checks supporting the ``HeaderFileExtensions`` flag now support ``;`` as a
+  delimiter in addition to ``,``, with the latter being deprecated as of this
+  release. This simplifies how one specifies the options on the command line:
+  ``--config="{CheckOptions: [{ key: HeaderFileExtensions, value: h;;hpp;hxx }]}"``
+
 Renamed checks
 ^^^^^^^^^^^^^^
 


        


More information about the cfe-commits mailing list