Another attempt at fixing external numpad detection. I *think* some of them send numlock state with every event. If that's the case, this should fix it.
This commit is contained in:
@@ -43,11 +43,18 @@ if [ -n "$STAGED_PYTHON_FILES" ]; then
|
||||
|
||||
for file in $STAGED_PYTHON_FILES; do
|
||||
if [ -f "$file" ]; then
|
||||
# Check for unterminated strings (the main issue from the email)
|
||||
if grep -n 'f".*{$' "$file" >/dev/null 2>&1; then
|
||||
echo -e "${RED}✗ $file: Potential unterminated f-string${NC}"
|
||||
# Check for broken f-strings (multiline issues that cause syntax errors)
|
||||
# Pattern 1: f-string with opening brace at end of line (likely broken across lines)
|
||||
if grep -n 'f"[^"]*{[^}]*$' "$file" >/dev/null 2>&1; then
|
||||
echo -e "${RED}✗ $file: Potential broken multiline f-string${NC}"
|
||||
grep -n 'f"[^"]*{[^}]*$' "$file" | head -3
|
||||
ISSUES_FOUND=1
|
||||
fi
|
||||
|
||||
# Pattern 2: Lines that end with just an opening brace (common in broken f-strings)
|
||||
if grep -n '^\s*[^#]*{$' "$file" >/dev/null 2>&1; then
|
||||
echo -e "${YELLOW}⚠ $file: Lines ending with lone opening brace (check f-strings)${NC}"
|
||||
fi
|
||||
|
||||
# Check for missing imports that are commonly used
|
||||
if grep -q 'debug\.DebugLevel\.' "$file" && ! grep -q 'from.*debug' "$file" && ! grep -q 'import.*debug' "$file"; then
|
||||
@@ -110,7 +117,7 @@ if [ -n "$STAGED_PYTHON_FILES" ]; then
|
||||
for file in $STAGED_PYTHON_FILES; do
|
||||
if [ -f "$file" ]; then
|
||||
# Check for potential passwords, keys, tokens
|
||||
if grep -i -E '(password|passwd|pwd|key|token|secret|api_key).*=.*["\'][^"\']{8,}["\']' "$file" >/dev/null 2>&1; then
|
||||
if grep -i -E '(password|passwd|pwd|key|token|secret|api_key).*=.*["'"'"'][^"'"'"']{8,}["'"'"']' "$file" >/dev/null 2>&1; then
|
||||
echo -e "${RED}✗ $file: Potential hardcoded secret detected${NC}"
|
||||
SECRETS_FOUND=1
|
||||
fi
|
||||
@@ -126,7 +133,7 @@ else
|
||||
fi
|
||||
|
||||
# Summary
|
||||
echo -e "\n${'='*50}"
|
||||
echo -e "\n=================================================="
|
||||
if [ $VALIDATION_FAILED -eq 0 ]; then
|
||||
echo -e "${GREEN}✓ All pre-commit validations passed${NC}"
|
||||
echo -e "${GREEN}Commit allowed to proceed${NC}"
|
||||
|
@@ -13,6 +13,7 @@ Usage:
|
||||
|
||||
import ast
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import argparse
|
||||
import tempfile
|
||||
@@ -24,13 +25,34 @@ class SyntaxValidator:
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
self.fixed = []
|
||||
|
||||
|
||||
def check_fstring_issues(self, content):
|
||||
"""Check for common f-string formatting issues that cause syntax errors."""
|
||||
issues = []
|
||||
lines = content.split('\n')
|
||||
|
||||
for i, line in enumerate(lines, 1):
|
||||
# Check for f-strings that appear to be broken across lines
|
||||
# Pattern: f"some text {
|
||||
if re.search(r'f"[^"]*{[^}]*$', line.strip()):
|
||||
issues.append(f"Line {i}: Potential broken multiline f-string")
|
||||
|
||||
return issues
|
||||
|
||||
def validate_file(self, filepath):
|
||||
"""Validate syntax of a single Python file."""
|
||||
try:
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
|
||||
# Check for specific f-string issues before AST parsing
|
||||
fstring_issues = self.check_fstring_issues(content)
|
||||
if fstring_issues:
|
||||
# Create a synthetic syntax error for f-string issues
|
||||
error_msg = f"F-string issues: {'; '.join(fstring_issues)}"
|
||||
self.errors.append((filepath, SyntaxError(error_msg), content))
|
||||
return False, content
|
||||
|
||||
# Parse with AST (catches syntax errors)
|
||||
ast.parse(content, filename=str(filepath))
|
||||
return True, content
|
||||
|
Reference in New Issue
Block a user