Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: Add pre-commit hook to enforce ldr- prefix for CSS classes

LearningCircuit9907d5232313
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 00be2b8adc..07e871a444 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -89,3 +89,9 @@ repos:
language: script
files: \.(html|js|css|py)$
description: "Ensure no external CDN URLs or external resources are referenced in the codebase"
+ - id: check-css-class-prefix
+ name: Check CSS class names have ldr- prefix
+ entry: .pre-commit-hooks/check-css-class-prefix.py
+ language: script
+ files: \.(css|html|js|jsx|ts|tsx|mjs)$
+ description: "Ensure all LDR-specific CSS classes are prefixed with 'ldr-' to prevent conflicts"
diff --git a/.pre-commit-hooks/check-css-class-prefix.py b/.pre-commit-hooks/check-css-class-prefix.py
new file mode 100755
index 0000000000..c34f4cbe7f
--- /dev/null
+++ b/.pre-commit-hooks/check-css-class-prefix.py
@@ -0,0 +1,260 @@
+#!/usr/bin/env python3
+"""
+Pre-commit hook to ensure all LDR-specific CSS class names are prefixed with 'ldr-'.
+This prevents CSS class name conflicts when Vite bundles CSS from dependencies.
+"""
+
+import re
+import sys
+from pathlib import Path
+from typing import List, Tuple
+
+# Allowed prefixes and patterns that don't need ldr- prefix
+ALLOWED_PATTERNS = {
+ # Bootstrap and common framework classes
+ r"^(btn|btn-.*|col|col-.*|row|container|container-.*|form|form-.*|modal|modal-.*|dropdown|dropdown-.*)$",
+ r"^(navbar|navbar-.*|nav|nav-.*|alert|alert-.*|badge|badge-.*|card|card-.*)$",
+ r"^(table|table-.*|list-group|list-group-.*|input-group|input-group-.*)$",
+ r"^(text-.*|bg-.*|border|border-.*|rounded|rounded-.*|shadow|shadow-.*)$",
+ r"^(d-.*|flex-.*|justify-content-.*|align-items-.*|align-self-.*)$",
+ r"^(m-\d+|mt-\d+|mb-\d+|ml-\d+|mr-\d+|mx-\d+|my-\d+|ms-\d+|me-\d+)$",
+ r"^(p-\d+|pt-\d+|pb-\d+|pl-\d+|pr-\d+|px-\d+|py-\d+|ps-\d+|pe-\d+)$",
+ r"^(w-.*|h-.*|mw-.*|mh-.*|min-vw-.*|min-vh-.*|vw-.*|vh-.*)$",
+ r"^(position-.*|top-.*|bottom-.*|start-.*|end-.*|translate-.*)$",
+ r"^(fs-\d+|fw-.*|fst-.*|lh-.*|font-monospace|text-decoration-.*)$",
+ r"^(visible|invisible|overflow-.*|user-select-.*|pe-none|pe-auto)$",
+ r"^(active|disabled|show|hide|collapse|collapsed|fade|fadeIn|fadeOut)$",
+ # Tailwind CSS classes (if used)
+ r"^(sm:|md:|lg:|xl:|2xl:|hover:|focus:|active:|dark:)",
+ # Common utility classes
+ r"^(clearfix|sr-only|sr-only-focusable|visually-hidden)$",
+ r"^(spinner|spinner-.*|placeholder|placeholder-.*)$",
+ # HTML5 semantic classes (often used by frameworks)
+ r"^(header|footer|main|section|article|aside|nav|figure)$",
+ # Common state classes
+ r"^(is-.*|has-.*|was-.*)$",
+ # Font Awesome and icon classes
+ r"^(fa|fa-.*|fas|far|fab|fal|fad|icon|icon-.*)$",
+ # Material Design classes
+ r"^(mdc-.*|mat-.*|material-icons)$",
+ # Already prefixed with ldr-
+ r"^ldr-",
+}
+
+
+def is_allowed_class(class_name: str) -> bool:
+ """Check if a class name is allowed without ldr- prefix."""
+ # Remove any leading/trailing whitespace
+ class_name = class_name.strip()
+
+ # Empty class names are invalid
+ if not class_name:
+ return False
+
+ # Check against allowed patterns
+ for pattern in ALLOWED_PATTERNS:
+ if re.match(pattern, class_name, re.IGNORECASE):
+ return True
+
+ return False
+
+
+def check_css_file(file_path: Path) -> List[Tuple[int, str, str]]:
+ """Check CSS file for non-prefixed class definitions."""
+ errors = []
+
+ try:
+ content = file_path.read_text()
+ lines = content.split("\n")
+
+ # Pattern to match CSS class definitions
+ # Matches: .classname { or .classname:hover { or .classname.other {
+ class_pattern = re.compile(r"\.([a-zA-Z][a-zA-Z0-9\-_]*)")
+
+ for line_num, line in enumerate(lines, 1):
+ # Skip comments
+ if "/*" in line or "*/" in line or line.strip().startswith("//"):
+ continue
+
+ matches = class_pattern.findall(line)
+ for class_name in matches:
+ if not is_allowed_class(class_name):
+ errors.append(
+ (
+ line_num,
+ class_name,
+ f"CSS class '.{class_name}' should be prefixed with 'ldr-'",
+ )
+ )
+
+ except Exception as e:
+ print(f"Error reading {file_path}: {e}", file=sys.stderr)
+
+ return errors
+
+
+def check_html_file(file_path: Path) -> List[Tuple[int, str, str]]:
+ """Check HTML file for non-prefixed class usage."""
+ errors = []
+
+ try:
+ content = file_path.read_text()
+ lines = content.split("\n")
+
+ # Pattern to match class attributes in HTML
+ # Matches: class="..." or class='...'
+ class_attr_pattern = re.compile(
+ r'class\s*=\s*["\']([^"\']*)["\']', re.IGNORECASE
+ )
+
+ for line_num, line in enumerate(lines, 1):
+ # Skip HTML comments
+ if "<!--" in line or "-->" in line:
+ continue
+
+ # Skip Jinja2 template comments
+ if "{#" in line or "#}" in line:
+ continue
+
+ matches = class_attr_pattern.findall(line)
+ for class_attr in matches:
+ # Split multiple classes
+ classes = class_attr.split()
+ for class_name in classes:
+ # Skip Jinja2 variables and expressions
+ if "{{" in class_name or "{%" in class_name:
+ continue
+
+ if not is_allowed_class(class_name):
+ errors.append(
+ (
+ line_num,
+ class_name,
+ f"HTML class '{class_name}' should be prefixed with 'ldr-'",
+ )
+ )
+
+ except Exception as e:
+ print(f"Error reading {file_path}: {e}", file=sys.stderr)
+
+ return errors
+
+
+def check_js_file(file_path: Path) -> List[Tuple[int, str, str]]:
+ """Check JavaScript file for non-prefixed class usage."""
+ errors = []
+
+ try:
+ content = file_path.read_text()
+ lines = content.split("\n")
+
+ # Patterns to match class usage in JavaScript
+ patterns = [
+ # classList.add('classname')
+ re.compile(
+ r'classList\.(add|remove|toggle|contains)\s*\(\s*["\']([^"\']+)["\']'
+ ),
+ # className = 'classname' or className: 'classname'
+ re.compile(r'className\s*[:=]\s*["\']([^"\']+)["\']'),
+ # getElementsByClassName('classname')
+ re.compile(r'getElementsByClassName\s*\(\s*["\']([^"\']+)["\']'),
+ # querySelector('.classname')
+ re.compile(r'querySelector(?:All)?\s*\(\s*["\']\.([^"\']+)["\']'),
+ # jQuery $('.classname')
+ re.compile(r'\$\s*\(\s*["\']\.([^"\']+)["\']'),
+ # hasClass('classname'), addClass('classname'), removeClass('classname')
+ re.compile(
+ r'\.(hasClass|addClass|removeClass|toggleClass)\s*\(\s*["\']([^"\']+)["\']'
+ ),
+ ]
+
+ for line_num, line in enumerate(lines, 1):
+ # Skip comments
+ if "//" in line or "/*" in line or "*/" in line:
+ # Simple comment detection (not perfect but good enough)
+ comment_start = line.find("//")
+ if comment_start >= 0:
+ line = line[:comment_start]
+
+ for pattern in patterns:
+ matches = pattern.findall(line)
+ for match in matches:
+ # Handle different capture groups
+ if isinstance(match, tuple):
+ # For patterns with multiple groups, get the class name
+ class_name = match[-1] if len(match) > 1 else match[0]
+ else:
+ class_name = match
+
+ # Split multiple classes if present
+ classes = class_name.split()
+ for cls in classes:
+ if not is_allowed_class(cls):
+ errors.append(
+ (
+ line_num,
+ cls,
+ f"JavaScript class '{cls}' should be prefixed with 'ldr-'",
+ )
+ )
+
+ except Exception as e:
+ print(f"Error reading {file_path}: {e}", file=sys.stderr)
+
+ return errors
+
+
+def main():
+ """Main function to check files passed as arguments."""
+ if len(sys.argv) < 2:
+ print("No files to check")
+ return 0
+
+ has_errors = False
+
+ for file_arg in sys.argv[1:]:
+ file_path = Path(file_arg)
+
+ # Skip if file doesn't exist or is in node_modules
+ if not file_path.exists() or "node_modules" in str(file_path):
+ continue
+
+ # Skip vendor/third-party files
+ if any(
+ vendor in str(file_path)
+ for vendor in ["vendor", "dist", "build", "lib", "libs"]
+ ):
+ continue
+
+ errors = []
+
+ # Check based on file extension
+ if file_path.suffix == ".css":
+ errors = check_css_file(file_path)
+ elif file_path.suffix in [".html", ".htm"]:
+ errors = check_html_file(file_path)
+ elif file_path.suffix in [".js", ".jsx", ".ts", ".tsx", ".mjs"]:
+ errors = check_js_file(file_path)
+
+ if errors:
+ has_errors = True
+ print(f"\n❌ CSS class prefix errors in {file_path}:")
+ for line_num, class_name, message in errors:
+ print(f" Line {line_num}: {message}")
+
+ if has_errors:
+ print("\n" + "=" * 60)
+ print("CSS Class Naming Convention:")
+ print(" All LDR-specific CSS classes must be prefixed with 'ldr-'")
+ print(
+ " This prevents conflicts when Vite bundles CSS from dependencies"
+ )
+ print(" Example: .custom-button → .ldr-custom-button")
+ print("=" * 60)
+ return 1
+
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())