From cf38dbaabbfa81649bc6a53fca348c7afd6f2220 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Thu, 2 Apr 2026 12:55:01 +0000 Subject: [PATCH] better formatting --- .gitea/workflows/underscore-check.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/underscore-check.py b/.gitea/workflows/underscore-check.py index 772dfb09c..74faf1395 100755 --- a/.gitea/workflows/underscore-check.py +++ b/.gitea/workflows/underscore-check.py @@ -80,23 +80,38 @@ def check_underscore_violations(text): def get_context_line(content, line_num, chars=50): """Get context around the violation.""" + lines = content.split('\n') if line_num < 1 or line_num > len(lines): return "" + line = lines[line_num - 1] - # Find the violation in the line + pattern = r'\b([A-Za-z0-9]+)_\b(?![A-Za-z0-9])' match = re.search(pattern, line) + if match: + # Calculate start and end positions for context window start = max(0, match.start() - chars) end = min(len(line), match.end() + chars) + + # Extract the context context = line[start:end] + if start > 0: context = "..." + context + if end < len(line): context = context + "..." + return context - return line[:chars*2] + "..." if len(line) > chars*2 else line + + # If no match found, return a shortened version of the line + max_length = chars * 2 + if len(line) > max_length: + return line[:max_length] + "..." + + return line def main(): @@ -165,13 +180,13 @@ def main(): with open('violations.json', 'w') as f: json.dump(all_violations, f, indent=2) - print(f"\n❌ Found {len(all_violations)} violation(s):") + print(f"\nFound {len(all_violations)} violation(s):") for v in all_violations: print(f" {v['file']}:{v['line']} - '{v['word']}' in context: {v['context']}") sys.exit(1) else: - print("\n✅ No violations found") + print("\nNo violations found") sys.exit(0)