Skip to content

refactor(linter): replace declare_all_lint_rules! macro with codegen#18076

Merged
graphite-app[bot] merged 1 commit intomainfrom
refactor/codegen-rules-enum
Jan 21, 2026
Merged

refactor(linter): replace declare_all_lint_rules! macro with codegen#18076
graphite-app[bot] merged 1 commit intomainfrom
refactor/codegen-rules-enum

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 16, 2026

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

  • All 916 linter tests pass
  • just lint passes
  • just ready passes
  • Verified codegen works: cargo run -p oxc_linter_codegen

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 16, 2026 11:47
@Boshen Boshen requested a review from camc314 as a code owner January 16, 2026 11:47
@github-actions github-actions bot added A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Jan 16, 2026
@Boshen Boshen force-pushed the refactor/codegen-rules-enum branch from 2e5c20f to ba70558 Compare January 16, 2026 11:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_rules procedural 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 mod statements. Run cargo run -p oxc_linter_codegen to 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.

@Boshen Boshen marked this pull request as draft January 16, 2026 11:51
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 16, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing refactor/codegen-rules-enum (1d2c18c) with main (9a15c6a)

Summary

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen Boshen force-pushed the refactor/codegen-rules-enum branch 2 times, most recently from bca7798 to 991be75 Compare January 16, 2026 12:37
@github-actions github-actions bot added the A-cli Area - CLI label Jan 16, 2026
@Boshen Boshen marked this pull request as ready for review January 16, 2026 13:05
@Boshen Boshen force-pushed the refactor/codegen-rules-enum branch from 991be75 to 1d2c18c Compare January 21, 2026 02:42
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
Copy link
Member Author

Boshen commented Jan 21, 2026

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)
@graphite-app graphite-app bot force-pushed the refactor/codegen-rules-enum branch from 1d2c18c to f424ac6 Compare January 21, 2026 02:48
@graphite-app graphite-app bot merged commit f424ac6 into main Jan 21, 2026
23 checks passed
@graphite-app graphite-app bot deleted the refactor/codegen-rules-enum branch January 21, 2026 02:54
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
@connorshea
Copy link
Member

#18322 :)

Boshen added a commit that referenced this pull request Jan 21, 2026
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>
graphite-app bot pushed a commit that referenced this pull request Jan 21, 2026
## 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants