Make workflow scripts easier to read by avoiding variable names not explicit
This commit is contained in:
@@ -31,8 +31,8 @@ def to_snake_case(filename: str) -> str:
|
||||
for root, dirs, files in os.walk('.', topdown=True):
|
||||
rel_root = os.path.relpath(root, '.')
|
||||
if any(
|
||||
rel_root == ex or rel_root.startswith(f"{ex}{os.sep}")
|
||||
for ex in EXCLUDED_DIRS
|
||||
rel_root == excluded or rel_root.startswith(f"{excluded}{os.sep}")
|
||||
for excluded in EXCLUDED_DIRS
|
||||
):
|
||||
dirs[:] = []
|
||||
continue
|
||||
@@ -48,16 +48,16 @@ for root, dirs, files in os.walk('.', topdown=True):
|
||||
invalid_dirs.append((rel_root, suggested_rel))
|
||||
|
||||
# Validate subdirectories
|
||||
for d in list(dirs):
|
||||
rel_path = os.path.join(rel_root, d) if rel_root != '.' else d
|
||||
for dir in list(dirs):
|
||||
rel_path = os.path.join(rel_root, dir) if rel_root != '.' else dir
|
||||
if any(
|
||||
rel_path == ex or rel_path.startswith(f"{ex}{os.sep}")
|
||||
for ex in EXCLUDED_DIRS
|
||||
rel_path == excluded or rel_path.startswith(f"{excluded}{os.sep}")
|
||||
for excluded in EXCLUDED_DIRS
|
||||
):
|
||||
dirs.remove(d)
|
||||
dirs.remove(dir)
|
||||
continue
|
||||
if not _BASE_PATTERN.match(d):
|
||||
suggestion = to_snake_case(d)
|
||||
if not _BASE_PATTERN.match(dir):
|
||||
suggestion = to_snake_case(dir)
|
||||
suggested_rel = os.path.join(rel_root, suggestion) if rel_root != '.' else suggestion
|
||||
invalid_dirs.append((rel_path, suggested_rel))
|
||||
|
||||
|
||||
@@ -39,15 +39,15 @@ MESSAGES = {
|
||||
|
||||
for root, dirs, files in os.walk('.', topdown=True):
|
||||
rel_root = os.path.relpath(root, '.')
|
||||
if any(rel_root == ex or rel_root.startswith(f"{ex}{os.sep}") for ex in EXCLUDED_DIRS):
|
||||
if any(rel_root == excluded or rel_root.startswith(f"{excluded}{os.sep}") for excluded in EXCLUDED_DIRS):
|
||||
dirs[:] = []
|
||||
continue
|
||||
for fname in files:
|
||||
if fname.endswith('.gd'):
|
||||
path = os.path.join(root, fname)
|
||||
try:
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
with open(path, 'r', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
except Exception as e:
|
||||
issues.append((path, 0, 'error', f'Could not read file: {e}'))
|
||||
continue
|
||||
@@ -55,41 +55,41 @@ for root, dirs, files in os.walk('.', topdown=True):
|
||||
stripped = line.strip()
|
||||
if stripped.startswith('#') or not stripped:
|
||||
continue
|
||||
m = re.match(r"class_name\s+([A-Za-z0-9_]+)", stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_class = re.match(r"class_name\s+([A-Za-z0-9_]+)", stripped)
|
||||
if match_class:
|
||||
name = match_class.group(1)
|
||||
if not PASCAL_CASE.match(name):
|
||||
issues.append((path, idx, 'class', name))
|
||||
m = re.match(r"func\s+([A-Za-z0-9_]+)\s*(\([^)]*\))?", stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_func = re.match(r"func\s+([A-Za-z0-9_]+)\s*(\([^)]*\))?", stripped)
|
||||
if match_func:
|
||||
name = match_func.group(1)
|
||||
if not SNAKE_CASE.match(name):
|
||||
issues.append((path, idx, 'function', name))
|
||||
params = m.group(2)
|
||||
params = match_func.group(2)
|
||||
if params:
|
||||
params = params.strip('()')
|
||||
for param in split_params(params):
|
||||
param_name = param.split(':')[0].split('=')[0].strip()
|
||||
if param_name and not SNAKE_CASE.match(param_name):
|
||||
issues.append((path, idx, 'variable', param_name))
|
||||
m = re.match(r"(?:@export\s+)?var\s+([A-Za-z0-9_]+)", stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_export = re.match(r"(?:@export\s+)?var\s+([A-Za-z0-9_]+)", stripped)
|
||||
if match_export:
|
||||
name = match_export.group(1)
|
||||
if not SNAKE_CASE.match(name):
|
||||
issues.append((path, idx, 'variable', name))
|
||||
m = re.match(r"const\s+([A-Za-z0-9_]+)", stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_const = re.match(r"const\s+([A-Za-z0-9_]+)", stripped)
|
||||
if match_const:
|
||||
name = match_const.group(1)
|
||||
if not UPPER_SNAKE_CASE.match(name):
|
||||
issues.append((path, idx, 'constant', name))
|
||||
m = re.match(r"signal\s+([A-Za-z0-9_]+)", stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_signal = re.match(r"signal\s+([A-Za-z0-9_]+)", stripped)
|
||||
if match_signal:
|
||||
name = match_signal.group(1)
|
||||
if not SNAKE_CASE.match(name):
|
||||
issues.append((path, idx, 'signal', name))
|
||||
m = re.match(r"for\s+([A-Za-z0-9_]+)(?:\s*:\s*[^\s]+)?\s+in\b", stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_for = re.match(r"for\s+([A-Za-z0-9_]+)(?:\s*:\s*[^\s]+)?\s+in\b", stripped)
|
||||
if match_for:
|
||||
name = match_for.group(1)
|
||||
if not SNAKE_CASE.match(name):
|
||||
issues.append((path, idx, 'variable', name))
|
||||
|
||||
|
||||
@@ -49,15 +49,15 @@ for root, dirs, files in os.walk('.', topdown=True):
|
||||
if stripped.startswith('#') or not stripped:
|
||||
continue
|
||||
|
||||
m = VAR_PATTERN.match(stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_var = VAR_PATTERN.match(stripped)
|
||||
if match_var:
|
||||
name = match_var.group(1)
|
||||
if len(name) == 1:
|
||||
single_char_vars.append((path, idx, name))
|
||||
|
||||
m = FUNC_PATTERN.match(stripped)
|
||||
if m:
|
||||
params = m.group(1)
|
||||
match_func = FUNC_PATTERN.match(stripped)
|
||||
if match_func:
|
||||
params = match_func.group(1)
|
||||
if params:
|
||||
params = params.strip('()')
|
||||
for param in split_params(params):
|
||||
@@ -65,9 +65,9 @@ for root, dirs, files in os.walk('.', topdown=True):
|
||||
if param_name and len(param_name) == 1:
|
||||
single_char_vars.append((path, idx, param_name))
|
||||
|
||||
m = FOR_PATTERN.match(stripped)
|
||||
if m:
|
||||
name = m.group(1)
|
||||
match_for = FOR_PATTERN.match(stripped)
|
||||
if match_for:
|
||||
name = match_for.group(1)
|
||||
if len(name) == 1:
|
||||
single_char_vars.append((path, idx, name))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user