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:
VIFEX
2025-10-02 03:11:04 +08:00
committed by GitHub
parent 0ba7cb5ea6
commit 376d14ef16
Regular → Executable
+32 -1
View File
@@ -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])