feat: becwright init#6
Conversation
init detects the repo's languages (Python / JS / TS) and writes a starter .bec/rules.yaml with matching rules, then installs the pre-commit hook — one command to go from install to enforcing. Refuses to overwrite an existing rules.yaml unless --force. Docs and command tables updated.
📝 WalkthroughWalkthroughAdds a new Changesbecwright init command
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_init.py (1)
21-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the section banner comments.
The test function names already describe these groups, so these comments don’t add complexity-oriented context. As per coding guidelines, "
**/*.{py,yaml,yml,toml}: Reserve comments for complex code only; do not add comments that merely restate obvious behavior."Also applies to: 36-36, 52-52, 69-69
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_init.py` at line 21, Remove the section banner comments from the test module; the grouped test function names already make the sections clear. Delete the banner-style comments in the affected test blocks in tests/test_init.py and keep the tests as-is otherwise.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/becwright/cli.py`:
- Around line 79-83: The traversal in cli.py still walks into skipped
directories before filtering files, so update the root.rglob("*") logic in the
init path to prune directories like node_modules, .venv, .git, and dist before
descending. Adjust the walking logic around the existing _SKIP_DIRS check so
directory entries are removed from traversal rather than only skipped after path
inspection, using the same root-relative part matching in the CLI init flow.
---
Nitpick comments:
In `@tests/test_init.py`:
- Line 21: Remove the section banner comments from the test module; the grouped
test function names already make the sections clear. Delete the banner-style
comments in the affected test blocks in tests/test_init.py and keep the tests
as-is otherwise.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 2789fe1a-9c94-4a13-b951-3572fcfc6a9a
📒 Files selected for processing (9)
CLAUDE.mdREADME.es.mdREADME.mddocumentation/architecture.es.mddocumentation/architecture.mddocumentation/usage.es.mddocumentation/usage.mdsrc/becwright/cli.pytests/test_init.py
| for path in root.rglob("*"): | ||
| if not path.is_file(): | ||
| continue | ||
| if any(part in _SKIP_DIRS for part in path.relative_to(root).parts): | ||
| continue |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Prune skipped directories before walking into them.
Line 79 still descends through node_modules, .venv, .git, dist, and similar directories; the Line 82 filter only ignores files after traversal. On large repos, becwright init can become unexpectedly slow.
⚙️ Proposed fix
+import os
+
_SKIP_DIRS = {".git", "node_modules", ".venv", "venv", "__pycache__", "dist", "build", ".tox"}
_EXT_LANG = {".py": "python", ".js": "js", ".ts": "ts"}
+_LANG_ORDER = ("python", "js", "ts")
def _detect_languages(root: Path) -> list[str]:
found: set[str] = set()
- for path in root.rglob("*"):
- if not path.is_file():
- continue
- if any(part in _SKIP_DIRS for part in path.relative_to(root).parts):
- continue
- lang = _EXT_LANG.get(path.suffix)
- if lang:
- found.add(lang)
- return [lang for lang in ("python", "js", "ts") if lang in found]
+ for _, dirnames, filenames in os.walk(root):
+ dirnames[:] = [name for name in dirnames if name not in _SKIP_DIRS]
+ for filename in filenames:
+ lang = _EXT_LANG.get(Path(filename).suffix)
+ if lang:
+ found.add(lang)
+ if len(found) == len(_LANG_ORDER):
+ break
+ return [lang for lang in _LANG_ORDER if lang in found]📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| for path in root.rglob("*"): | |
| if not path.is_file(): | |
| continue | |
| if any(part in _SKIP_DIRS for part in path.relative_to(root).parts): | |
| continue | |
| import os | |
| _SKIP_DIRS = {".git", "node_modules", ".venv", "venv", "__pycache__", "dist", "build", ".tox"} | |
| _EXT_LANG = {".py": "python", ".js": "js", ".ts": "ts"} | |
| _LANG_ORDER = ("python", "js", "ts") | |
| def _detect_languages(root: Path) -> list[str]: | |
| found: set[str] = set() | |
| for _, dirnames, filenames in os.walk(root): | |
| dirnames[:] = [name for name in dirnames if name not in _SKIP_DIRS] | |
| for filename in filenames: | |
| lang = _EXT_LANG.get(Path(filename).suffix) | |
| if lang: | |
| found.add(lang) | |
| if len(found) == len(_LANG_ORDER): | |
| break | |
| return [lang for lang in _LANG_ORDER if lang in found] |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/becwright/cli.py` around lines 79 - 83, The traversal in cli.py still
walks into skipped directories before filtering files, so update the
root.rglob("*") logic in the init path to prune directories like node_modules,
.venv, .git, and dist before descending. Adjust the walking logic around the
existing _SKIP_DIRS check so directory entries are removed from traversal rather
than only skipped after path inspection, using the same root-relative part
matching in the CLI init flow.
Adds a
becwright initcommand to remove the 'blank page' friction after install..bec/rules.yamlwith matching rules (secrets for any language; debug/eval for Python; debugger/console for JS/TS)..bec/rules.yamlunless--force.Note: while writing this, becwright's own
no-dangerous-evalself-rule flagged the new code, because the scaffolding text contained the literaleval()/exec()— a false positive of a text check on documentation. Reworded so the engine source stays clean. Dogfooding caught it.Summary by CodeRabbit
New Features
initcommand to set up a project by generating a starter.bec/rules.yamland installing the pre-commit hook.Bug Fixes
.bec/rules.yamlunless forced.