[libc-commits] [libc] 43e2f7c - [libc] update tidy rules to fix variable formatting

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Dec 7 10:49:51 PST 2021


Author: Michael Jones
Date: 2021-12-07T10:49:45-08:00
New Revision: 43e2f7cd248acf799bf97af2388940c9c39151e0

URL: https://github.com/llvm/llvm-project/commit/43e2f7cd248acf799bf97af2388940c9c39151e0
DIFF: https://github.com/llvm/llvm-project/commit/43e2f7cd248acf799bf97af2388940c9c39151e0.diff

LOG: [libc] update tidy rules to fix variable formatting

This commit changes the clang-tidy rules for LLVM-libc to follow the new
format. The next commit applies these rules to the codebase.

The rules are as follows:

CamelCase for classes
lower_case for variables
lower_case for functions
UPPER_CASE for constexpr variables

There are also some exceptions, but the most important one is that any
function or variable that starts with an underscore is exempt from the
formatting.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D114301

Added: 
    libc/src/__support/CPP/.clang-tidy

Modified: 
    libc/CMakeLists.txt
    libc/cmake/modules/LLVMLibCObjectRules.cmake
    libc/src/.clang-tidy

Removed: 
    


################################################################################
diff  --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index a683bcc8c3761..7275ce42560ca 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -55,6 +55,12 @@ if(LLVM_LIBC_ENABLE_LINTING)
   if("clang-tools-extra" IN_LIST LLVM_ENABLE_PROJECTS
              AND "clang" IN_LIST LLVM_ENABLE_PROJECTS)
     add_custom_target(lint-libc)
+    if(NOT EXISTS "${LIBC_BUILD_DIR}/.clang-tidy")
+      # add a no-op clang tidy file for the build directory so that the tidy 
+      # rules don't attempt to format the generated code.
+      file(WRITE ${LIBC_BUILD_DIR}/.clang-tidy "#InheritParentConfig: false
+      Checks: cppcoreguidelines-avoid-goto")
+    endif()
   else()
     message(FATAL_ERROR "
       'clang' and 'clang-tools-extra' are required in LLVM_ENABLE_PROJECTS to

diff  --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 69ec2160f1c0d..68dcbc6851624 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -232,6 +232,7 @@ function(add_entrypoint_object target_name)
       # these.
       COMMAND $<TARGET_FILE:clang-tidy>
               "--extra-arg=-fno-caret-diagnostics" --quiet
+              "--export-fixes=${CMAKE_CURRENT_BINARY_DIR}/${target_name}.yaml"
               # Path to directory containing compile_commands.json
               -p ${PROJECT_BINARY_DIR}
               ${ADD_ENTRYPOINT_OBJ_SRCS}

diff  --git a/libc/src/.clang-tidy b/libc/src/.clang-tidy
index 29f78fdfbcbae..606e69632d7d0 100644
--- a/libc/src/.clang-tidy
+++ b/libc/src/.clang-tidy
@@ -1,6 +1,24 @@
-Checks: '-*,llvmlibc-*'
+Checks: '-*,llvmlibc-*,readability-identifier-naming'
 HeaderFilterRegex: '.*'
 WarningsAsErrors: 'llvmlibc-*'
 CheckOptions:
   - key:             llvmlibc-restrict-system-libc-headers.Includes
     value:           '-*, linux/*, asm/*.h, asm-generic/*.h'
+  - key:             readability-identifier-naming.ClassCase
+    value:           CamelCase
+  - key:             readability-identifier-naming.StructCase
+    value:           aNy_CasE
+  - key:             readability-identifier-naming.MemberCase
+    value:           lower_case
+  - key:             readability-identifier-naming.VariableCase
+    value:           lower_case
+  - key:             readability-identifier-naming.VariableIgnoredRegexp
+    value:           "^_[A-Za-z0-9_]+$"
+  - key:             readability-identifier-naming.FunctionCase
+    value:           lower_case
+  - key:             readability-identifier-naming.FunctionIgnoredRegexp
+    value:           "^_[A-Za-z0-9_]+$"
+  - key:             readability-identifier-naming.ConstexprVariableCase
+    value:           UPPER_CASE
+  - key:             readability-identifier-naming.GetConfigPerFile
+    value:           true

diff  --git a/libc/src/__support/CPP/.clang-tidy b/libc/src/__support/CPP/.clang-tidy
new file mode 100644
index 0000000000000..29f78fdfbcbae
--- /dev/null
+++ b/libc/src/__support/CPP/.clang-tidy
@@ -0,0 +1,6 @@
+Checks: '-*,llvmlibc-*'
+HeaderFilterRegex: '.*'
+WarningsAsErrors: 'llvmlibc-*'
+CheckOptions:
+  - key:             llvmlibc-restrict-system-libc-headers.Includes
+    value:           '-*, linux/*, asm/*.h, asm-generic/*.h'


        


More information about the libc-commits mailing list