Skip to content

feat(init): map a file line cap from CLAUDE.md to max_lines#45

Merged
DataDave-Dev merged 2 commits into
mainfrom
feat/from-claude-md-max-lines
Jul 1, 2026
Merged

feat(init): map a file line cap from CLAUDE.md to max_lines#45
DataDave-Dev merged 2 commits into
mainfrom
feat/from-claude-md-max-lines

Conversation

@DataDave-Dev

@DataDave-Dev DataDave-Dev commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Why

Follow-up to the three agnostic checks (#44): connect the most common — and
unambiguous — one to --from-claude-md. "Files under 800 lines" is in most
CLAUDE.md files (becwright's own included), and it's deterministic.

What

--from-claude-md now extracts a per-file line cap from the prose and emits
a max_lines rule:

From CLAUDE.md: 2 enforceable rule(s) derived —
  no-hardcoded-secrets  (matched: "hardcod")
  max-file-lines        (matched: "800 lines")

The tricky part is the functions-vs-files trap: a CLAUDE.md often says
"functions < 50 lines, files < 800 lines". The 50 is function length, which needs
an AST and becwright can't enforce. So the regex anchors the number to a
file/module/archivo/módulo mention (EN/ES, both orders) and bounds it to
50..5000 — "functions must be under 50 lines" maps to nothing, as it should.
Emitted as a warning (a big file shouldn't hard-block adoption).

Scope

filename and require are intentionally not auto-mapped: they're too
parametric/semantic for a keyword table (auto-generating them would ship noisy
repo-wide rules). They stay available for manual authoring and are the natural
job of the agent/MCP layer (see design doc). This keeps the CLI's mapping honest.

Test plan

  • _max_lines_cap extracts the cap (EN/ES, both word orders)
  • Ignores function-length rules (no file/module anchor) and out-of-range numbers
  • _rules_from_claude_md emits a max_lines --max N rule (warning)
  • End-to-end: init picks up "800 lines", skips "functions under 50 lines"
  • Full suite: 192 passed; dogfooded

Summary by CodeRabbit

  • New Features

    • becwright init --from-claude-md can now infer and apply a per-file line limit from CLAUDE.md when it’s stated in natural language.
    • It also ignores function-length guidance that can’t be enforced automatically.
  • Documentation

    • Updated setup guides in English and Spanish to explain the new line-limit behavior and how it works with --baseline.
  • Tests

    • Added coverage for detecting file-line limits, handling unsupported statements, and generating the new check.

--from-claude-md now extracts a per-file line cap (e.g. 'files under 800
lines') and emits a max_lines rule for it. The regex anchors the number to a
file/module mention so a 'functions < 50 lines' rule — which needs an AST and
becwright cannot enforce — is not mistaken for a file cap; the cap is bounded to
50..5000. Emitted as a warning.
@DataDave-Dev
DataDave-Dev merged commit 9a5c737 into main Jul 1, 2026
3 checks passed
@DataDave-Dev
DataDave-Dev deleted the feat/from-claude-md-max-lines branch July 1, 2026 16:56
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 815498bf-88b4-44fe-a09f-e9dae40c2452

📥 Commits

Reviewing files that changed from the base of the PR and between 1fc00b6 and 0d4b0ad.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • documentation/usage.es.md
  • documentation/usage.md
  • src/becwright/cli.py
  • tests/test_init.py

📝 Walkthrough

Walkthrough

This PR extends becwright init --from-claude-md to also derive a per-file line cap (max_lines) from CLAUDE.md text, adding regex-based parsing and a new max-file-lines warning rule. Documentation, changelog, and tests are updated accordingly.

Changes

Max-file-lines rule derivation

Layer / File(s) Summary
Line-cap parsing and rule generation
src/becwright/cli.py
Adds re import, a compiled regex _FILE_LINE_CAP and helper _max_lines_cap() to extract a numeric per-file line cap from multilingual CLAUDE.md phrasing, and extends _rules_from_claude_md to append a max-file-lines warning rule invoking becwright run max_lines --max <cap>.
Tests for line-cap parsing and rule mapping
tests/test_init.py
Adds tests verifying _max_lines_cap extraction (including localized phrasing), exclusion of function-length statements, bound validation, and correct max-file-lines rule generation via _rules_from_claude_md.
Documentation and changelog updates
CHANGELOG.md, documentation/usage.md, documentation/usage.es.md
Updates the changelog entry and English/Spanish usage docs to describe the new max_lines cap detection and the ignoring of unenforceable function-length rules.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related PRs

  • DataDave-Dev/becwright#16: Both PRs modify src/becwright/cli.py's rule generation to invoke becwright run ..., with the new max-file-lines rule depending on the run command plumbing introduced there.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/from-claude-md-max-lines

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant