forked from docs/doc-exports
better formatting
This commit is contained in:
@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user