Skip to content

Enforce maximum line limit per file (512 lines) #95

@ywatanabe1989

Description

@ywatanabe1989

Summary

Large files tend to have more bugs and are harder to maintain. We should enforce a maximum line limit per file using pre-tool-use hooks.

Line Limits (from hook)

File Type Max Lines
Python (.py), Shell (.sh), Elisp (.el) 512
TypeScript/JavaScript (.ts, .tsx, .js, .jsx) 512
CSS (.css) 512
HTML (.html, .htm) 1024
Markdown (.md) 512

Hook Implementation

The pre-tool-use hook at .claude/hooks/pre-tool-use/limit_line_numbers.sh:

# Thresholds (in lines)
THRESHOLD_TS=512
THRESHOLD_PY=512
THRESHOLD_CSS=512
THRESHOLD_HTML=1024
THRESHOLD_MARKDOWN=512

Behavior:

  • Blocks file writes/edits that would exceed the threshold
  • Allows incremental reduction (shrinking files already over limit)
  • Skips test files (tests/, test_*.py, *_test.py)
  • Guides refactoring via REFACTORING.md

Current Violations (>1000 lines)

  • src/scitex/canvas/editor/flask_editor/templates/_scripts.py (4933 lines)
  • src/scitex/plt/utils/_collect_figure_metadata.py (3384 lines)
  • src/scitex/canvas/editor/_dearpygui_editor.py (1976 lines)
  • src/scitex/scholar/core/Scholar.py (1857 lines)
  • src/scitex/ai/classification/reporters/_SingleClassificationReporter.py (1778 lines)
  • src/scitex/scholar/storage/_LibraryManager.py (1725 lines)
  • src/scitex/canvas/editor/flask_editor/_core.py (1688 lines)
  • src/scitex/canvas/editor/flask_editor/templates/_styles.py (1658 lines)
  • src/scitex/plt/utils/_hitmap.py (1643 lines)
  • src/scitex/ai/classification/timeseries/_TimeSeriesSlidingWindowSplit.py (1640 lines)

Action Items

  • Enable hook in .claude/settings.local.json
  • Create sub-issues for each file needing refactoring
  • Document exceptions (auto-generated code, templates)

Benefits

  • Improved readability and maintainability
  • Easier code reviews
  • Reduced bug density
  • Better separation of concerns

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions