[libc-commits] [libc] [libc] Improve the state of the lint rules (PR #135278)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Thu Apr 10 16:15:13 PDT 2025
https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/135278
The goal of this change is to update the rules such that we can run the
linter and get a clean result. For testing purposes set
`-DLLVM_LIBC_ENABLE_LINTING=ON` and run `ninja -j 1 -k 0 libc-lint`, or
pick a single `__lint__` target, such as `ninja
libc.src.stdio.sprintf.__lint__`.
BEFORE MERGING:
remove --fix from the lint target
>From 19a209d41b563e6dc9f4ffa14118c28dcfdc9ced Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Thu, 10 Apr 2025 16:11:28 -0700
Subject: [PATCH] [libc] Improve the state of the lint rules
The goal of this change is to update the rules such that we can run the
linter and get a clean result. For testing purposes set
`-DLLVM_LIBC_ENABLE_LINTING=ON` and run `ninja -j 1 -k 0 libc-lint`, or
pick a single `__lint__` target, such as `ninja
libc.src.stdio.sprintf.__lint__`.
BEFORE MERGING:
remove --fix from the lint target
---
libc/.clang-tidy | 8 ++++++++
libc/cmake/modules/LLVMLibCObjectRules.cmake | 2 +-
libc/include/.clang-tidy | 3 +++
libc/src/.clang-tidy | 2 +-
4 files changed, 13 insertions(+), 2 deletions(-)
create mode 100644 libc/include/.clang-tidy
diff --git a/libc/.clang-tidy b/libc/.clang-tidy
index dbde88928ee63..bd09aae981ba9 100644
--- a/libc/.clang-tidy
+++ b/libc/.clang-tidy
@@ -6,6 +6,8 @@ CheckOptions:
value: CamelCase
- key: readability-identifier-naming.StructCase
value: aNy_CasE
+ - key: readability-identifier-naming.StructIgnoredRegexp
+ value: "_?(_[A-Za-z0-9]+)*"
- key: readability-identifier-naming.MemberCase
value: lower_case
- key: readability-identifier-naming.MemberIgnoredRegexp
@@ -14,6 +16,10 @@ CheckOptions:
value: lower_case
- key: readability-identifier-naming.VariableIgnoredRegexp
value: "_?(_[A-Za-z0-9]+)*"
+ - key: readability-identifier-naming.ParameterCase
+ value: lower_case
+ - key: readability-identifier-naming.ParameterIgnoredRegexp
+ value: "_?(_[A-Za-z0-9]+)*"
- key: readability-identifier-naming.FunctionCase
value: lower_case
- key: readability-identifier-naming.FunctionIgnoredRegexp
@@ -26,6 +32,8 @@ CheckOptions:
value: UPPER_CASE
- key: readability-identifier-naming.ConstexprVariableCase
value: UPPER_CASE
+ - key: readability-identifier-naming.ConstexprVariableIgnoredRegexp
+ value: "is(_[A-Za-z0-9]+)*_v"
- key: readability-identifier-naming.ConstexprFunctionCase
value: lower_case
- key: readability-identifier-naming.GetConfigPerFile
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 142778d9ea1cc..c8a20341ff74f 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -355,7 +355,7 @@ function(create_entrypoint_object fq_target_name)
# Until this is fixed upstream, we use -fno-caret-diagnostics to surpress
# these.
COMMAND ${LLVM_LIBC_CLANG_TIDY}
- "--extra-arg=-fno-caret-diagnostics" --quiet
+ "--extra-arg=-fno-caret-diagnostics" --quiet --fix
# Path to directory containing compile_commands.json
-p ${PROJECT_BINARY_DIR}
${ADD_ENTRYPOINT_OBJ_SRCS}
diff --git a/libc/include/.clang-tidy b/libc/include/.clang-tidy
new file mode 100644
index 0000000000000..a6c02dd90e4d2
--- /dev/null
+++ b/libc/include/.clang-tidy
@@ -0,0 +1,3 @@
+InheritParentConfig: false
+Checks: ''
+HeaderFilterRegex: '.*'
diff --git a/libc/src/.clang-tidy b/libc/src/.clang-tidy
index 1c79b1cf6aae6..7e97dac43d38a 100644
--- a/libc/src/.clang-tidy
+++ b/libc/src/.clang-tidy
@@ -4,4 +4,4 @@ HeaderFilterRegex: '.*'
WarningsAsErrors: 'llvmlibc-*'
CheckOptions:
- key: llvmlibc-restrict-system-libc-headers.Includes
- value: '-*, linux/*, asm/*.h, asm-generic/*.h'
+ value: '-*, linux/*, asm/*.h, asm-generic/*.h. sys/syscall.h'
More information about the libc-commits
mailing list