Commit Graph

4 Commits

Author SHA1 Message Date
Boshen f424ac675a refactor(linter): replace declare_all_lint_rules! macro with codegen (#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)
2026-01-21 02:48:30 +00:00
Boshen 8f98fa0d4e test(rust): disable empty test and doctest targets (#17409)
## Summary

- Disable `test = false` and `doctest = false` for crates that have no tests
- Reduces CI noise from "0 passed; 0 failed" output
- Saves compilation time for empty test targets

**Affected crates:**
- `oxc_ast_macros` - lib test
- `oxc_language_server` - bin test, lib doctest
- `oxc_napi` - lib test
- `oxc_syntax` - lib doctest
- `oxc_compat_data` - bin test
- `oxc_coverage` - lib test
- `oxc_linter_codegen` - bin test
- `oxc_prettier_conformance` - lib test
- `oxc_transform_conformance` - lib test
- `vscode_docs` - bin test
- `website_common` - lib test, lib doctest

## Test plan

- [x] `cargo test` passes with no empty test suites

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2025-12-28 11:44:19 +00:00
camchenry f9bff647ee refactor(linter_codegen): improve code style for collecting nodes (#13636)
Almost pure refactor. There are some slight styling changes in the rule runner impls file, but other than that, this is just some clean up.

- Make the rule runner template string a multiline string, so it is easier to read and edit
- Move functions into the if-else detector so we don't need to pass around mutable sets of strings
- Replaced BTreeSet with a `NodeTypeSet` that abstracts over the set manipulation somewhat and offers more utilities specific to the linter codegen

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
2025-09-10 11:56:44 +08:00
camchenry a744aff1d7 perf(linter): skip rules that do not have any relevant node types (#13138)
- part of https://github.com/oxc-project/oxc/issues/12223
- supersedes stack: https://github.com/oxc-project/oxc/pull/12228

This PR adds the ability to add node type information to indicate what node types a lint rule acts on. The lint rule runner can use this information to optimize running lint rules by skipping nodes, files, or rules that don't apply.

This is a simple version that is focused on creating the framework for automatically generating the rule runner code. This is not the end of optimizations. Currently only 102 rules have node type information, while 471 rules have no node type information and will not be skipped. Adding node type information for more rules will improve performance. We may also be able to skip more nodes and files by being clever about how we use this information. For example, filtering out any rules which do not run on any node type, if the file contains no relevant node types for the rule.

- Adds a new `RuleRunner` trait which includes information needed for indicating whether a rule has node type info or not
- Adds a `oxc_linter_codegen` task which is used to generate the implementation of `RuleRunner` trait for all lint rules. This is mostly written by AI, so worth a bit of skepticism, but I've tried to manually verify the results and it looks good (just lacking more complex detection).
  - Currently, only rules that contain a single top-level `if` statement (or chain of `else if`), or a single `match` statement will have their node type info generated. This should give us a high level of confidence, since these patterns are relatively easy to verify and identify, but it's only a subset of all rules. Next steps will be to add support for `let...else`
- Adjusts the main linting loop to use the node type information to skip rules for node types that don't apply
- Updates CI to include a check for any uncommitted linter codegen changes

---

## Benchmarks

In the latest version of this PR, CodSpeed shows an up to +13% increase in linter performance across large and small files. In the real-world, I've seen a ~5-15% improvement in performance, but in some cases close to zero for very small files. In either case, there appears to be little downside and a lot of potential upside here.

<img width="769" height="242" alt="Screenshot 2025-08-24 at 9 29 30 PM" src="https://github.com/user-attachments/assets/d2c430c4-17a9-4606-85d5-c66c734975d9" />
<img width="757" height="308" alt="Screenshot 2025-08-24 at 9 30 24 PM" src="https://github.com/user-attachments/assets/5508464f-de55-4f4e-9ddd-58f215c4ce85" />
<img width="976" height="368" alt="Screenshot 2025-08-24 at 9 34 52 PM" src="https://github.com/user-attachments/assets/203f83c7-46f3-49f1-a1a8-e18f7ec8483b" />
2025-09-08 03:22:26 +00:00