Добавить скрипт проверки отступов в исходном коде

This commit is contained in:
Vladimir Vaskov 2024-05-06 04:27:39 +03:00
parent a23e23ea86
commit 03e821a949
No known key found for this signature in database
GPG key ID: CECAF75A5D478132
5 changed files with 54 additions and 0 deletions

47
indentation_check.py Normal file
View file

@ -0,0 +1,47 @@
#!/bin/bash
import sys
import os
import re
def check_indentation(file_path, root_dir) -> list[str]:
file_err_list = []
with open(file_path, 'r') as file:
lines = file.readlines()
for i, line in enumerate(lines):
if "ind-check=skip-file" in line:
return
if re.match(r'^(?!.*(?:new|if|else| => |try|catch|switch|}|get |set |while|namespace|class|foreach|throws|ind-check=ignore| = {))(?=(?:.*?\s+\w+\s+\w+.*?){1}).*{', line):
indentation = len(re.match(r'^(\s*)', line).group(1))
if indentation != 4:
file_err_list.append (f"Indentation error in file '{file_path.replace (root_dir, "")}' at line {i+1}: \"{line.rstrip ()}\". {indentation} spaces instead of 4.")
return file_err_list
def scan_directory (directory) -> list[str]:
err_list = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.vala'):
file_path = os.path.join(root, file)
file_err_list = check_indentation (file_path, directory)
if (file_err_list):
err_list += file_err_list
return err_list
if __name__ == "__main__":
err_list = scan_directory (sys.argv[1])
print (*err_list, sep="\n", end="\n\n")
print (f"Total errors: {len (err_list)}")
if (len (err_list) != 0):
sys.exit (1)

View file

@ -1,3 +1,5 @@
// ind-check=skip-file
using Cassette.Client; using Cassette.Client;

View file

@ -1,3 +1,5 @@
// ind-check=skip-file
using Cassette.Client; using Cassette.Client;
using Cassette.Client.Cachier; using Cassette.Client.Cachier;

View file

@ -1,3 +1,4 @@
// ind-check=skip-file
// vala-lint=skip-file // vala-lint=skip-file
using Cassette.Client; using Cassette.Client;

View file

@ -1,3 +1,5 @@
// ind-check=skip-file
using Cassette.Client; using Cassette.Client;
using Cassette.Client.Cachier; using Cassette.Client.Cachier;
using Cassette.Client.YaMAPI; using Cassette.Client.YaMAPI;