refactor(linter): replace declare_all_lint_rules! macro with codegen#18076
refactor(linter): replace declare_all_lint_rules! macro with codegen#18076graphite-app[bot] merged 1 commit intomainfrom
declare_all_lint_rules! macro with codegen#18076Conversation
2e5c20f to
ba70558
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors the linter rule registration system by replacing the declare_all_lint_rules! procedural macro with checked-in generated code. The generated rules_enum.rs file (~16K lines) provides better IDE support by making the code visible to rust-analyzer, with a small trade-off of ~17% slower dev builds and ~2% slower release builds.
Changes:
- Added codegen logic to generate RuleEnum and all related implementations
- Updated rule parser to scan module declarations instead of macro invocations
- Replaced macro invocation with re-exports from generated code
- Deleted the
declare_all_lint_rulesprocedural macro
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tasks/linter_codegen/src/rules_enum.rs | New codegen module that generates RuleEnum and all trait implementations |
| tasks/linter_codegen/src/rules.rs | Updated parser to extract rules by scanning module declarations |
| tasks/linter_codegen/src/main.rs | Added generate_rules_enum_file() function to orchestrate codegen |
| crates/oxc_macros/src/lib.rs | Removed the declare_all_lint_rules macro export |
| crates/oxc_macros/src/declare_all_lint_rules.rs | Deleted the entire proc-macro implementation |
| crates/oxc_linter/src/rules.rs | Replaced macro invocation with re-exports from generated code |
| crates/oxc_linter/src/lib.rs | Added pub mod rules_enum to the generated module |
Comments suppressed due to low confidence (1)
crates/oxc_linter/src/rules.rs:3
- This comment is now outdated since the macro at the bottom has been removed. The comment should be updated to reference the codegen instead, e.g., 'New rules need be added to these
modstatements. Runcargo run -p oxc_linter_codegento regenerate the RuleEnum.'
//! New rules need to be added to these `mod` statements.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
bca7798 to
991be75
Compare
991be75 to
1d2c18c
Compare
Merge activity
|
#18076) ## Summary - Replace the `declare_all_lint_rules\!` proc-macro with checked-in codegen - The generated `rules_enum.rs` file (~16K lines) provides better IDE support since the code is visible to rust-analyzer - Run `cargo run -p oxc_linter_codegen` to regenerate - Uses `quote\!` macro for clean, maintainable code generation ### Changes - **New**: `tasks/linter_codegen/src/rules_enum.rs` - generates `RuleEnum` using `quote\!` macro - **Modified**: `tasks/linter_codegen/src/main.rs` - added `generate_rules_enum_file()` - **Modified**: `tasks/linter_codegen/src/rules.rs` - updated parser to scan module declarations - **Modified**: `tasks/linter_codegen/Cargo.toml` - added `quote` and `proc-macro2` dependencies - **Modified**: `crates/oxc_linter/src/rules.rs` - replaced macro invocation with re-exports, updated module docs - **Modified**: `crates/oxc_linter/src/lib.rs` - added `pub mod rules_enum` to generated module, added clippy expects - **Deleted**: `crates/oxc_macros/src/declare_all_lint_rules.rs` - removed proc-macro ### Adding new rules 1. Add the rule module to `crates/oxc_linter/src/rules.rs` 2. Run `cargo run -p oxc_linter_codegen` to regenerate `RuleEnum` ### Build time comparison | Mode | main | this PR | Change | |------|------|---------|--------| | Dev | 26.80s | 31.39s | +17% | | Release | 3m 32s | 3m 37s | +2% | The slight increase is expected since rustc now parses the 1.1MB generated file instead of expanding a proc-macro. The tradeoff is better IDE support. ## Test plan - [x] All 916 linter tests pass - [x] `just lint` passes - [x] `just ready` passes - [x] Verified codegen works: `cargo run -p oxc_linter_codegen` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1d2c18c to
f424ac6
Compare
|
#18322 :) |
1. Remove obsolete `declare_all_lint_rules!` macro handling from `add_rules_entry` - The macro was removed in #18076, now rules are registered via module declarations - The `RuleEnum` is generated by `oxc_linter_codegen` which is already called after 2. Fix `find_unsupported_rule` to respect the specified plugin - Previously `key.contains(kebab_rule)` matched any plugin's rule with the same name - Now correctly checks only the specified plugin (e.g., `eslint/dot-notation` not `vue/dot-notation`) Closes #18322 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## Summary - Remove obsolete `declare_all_lint_rules!` macro handling from `add_rules_entry` - the macro was removed in #18076 - Fix `find_unsupported_rule` to respect the specified plugin instead of matching any plugin's rule with the same name ## Test plan - [x] `cargo test -p rulegen` passes - [x] `cargo run -p rulegen dot-notation` now correctly creates `eslint/dot-notation` instead of failing with `vue/dot-notation` unsupported error Closes #18322 🤖 Generated with [Claude Code](https://claude.ai/claude-code)
Summary
declare_all_lint_rules\!proc-macro with checked-in codegenrules_enum.rsfile (~16K lines) provides better IDE support since the code is visible to rust-analyzercargo run -p oxc_linter_codegento regeneratequote\!macro for clean, maintainable code generationChanges
tasks/linter_codegen/src/rules_enum.rs- generatesRuleEnumusingquote\!macrotasks/linter_codegen/src/main.rs- addedgenerate_rules_enum_file()tasks/linter_codegen/src/rules.rs- updated parser to scan module declarationstasks/linter_codegen/Cargo.toml- addedquoteandproc-macro2dependenciescrates/oxc_linter/src/rules.rs- replaced macro invocation with re-exports, updated module docscrates/oxc_linter/src/lib.rs- addedpub mod rules_enumto generated module, added clippy expectscrates/oxc_macros/src/declare_all_lint_rules.rs- removed proc-macroAdding new rules
crates/oxc_linter/src/rules.rscargo run -p oxc_linter_codegento regenerateRuleEnumBuild time comparison
The slight increase is expected since rustc now parses the 1.1MB generated file instead of expanding a proc-macro. The tradeoff is better IDE support.
Test plan
just lintpassesjust readypassescargo run -p oxc_linter_codegen🤖 Generated with Claude Code