mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-20 04:11:36 +08:00
feat(kconfig_verify): add space indentation check (#8962)
Signed-off-by: pengyiqiang <pengyiqiang@xiaomi.com> Co-authored-by: pengyiqiang <pengyiqiang@xiaomi.com>
This commit is contained in:
Regular → Executable
+32
-1
@@ -21,9 +21,40 @@ def verify_kconfig(kconfig_file):
|
||||
print("No warnings found.")
|
||||
|
||||
|
||||
def check_kconfig_spaces(file_path):
|
||||
"""Check for space-based indentation in a Kconfig file"""
|
||||
try:
|
||||
# Read file content to check for spaces
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
|
||||
space_indent_lines = []
|
||||
for line_num, line in enumerate(lines, 1):
|
||||
# Check for leading spaces (skip empty lines)
|
||||
stripped_line = line.lstrip()
|
||||
if stripped_line and len(line) > len(stripped_line):
|
||||
# Extract the indentation part
|
||||
indent = line[: -len(stripped_line)] if stripped_line else line
|
||||
if " " in indent:
|
||||
space_indent_lines.append((line_num, indent))
|
||||
|
||||
if space_indent_lines:
|
||||
print(f"Space-based indentation found in file {file_path}:")
|
||||
for line_num, indent in space_indent_lines:
|
||||
print(f"Line {line_num}: Indent contains {indent.count(' ')} spaces")
|
||||
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(f"No space-based indentation found in file {file_path}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error processing file {file_path}: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python check_kconfig.py <Kconfig_file>")
|
||||
print(f"Usage: python {sys.argv[0]} <Kconfig_file>")
|
||||
sys.exit(1)
|
||||
|
||||
verify_kconfig(sys.argv[1])
|
||||
check_kconfig_spaces(sys.argv[1])
|
||||
|
||||
Reference in New Issue
Block a user