oxc-project
oxc
BlogDocsChangelog

refactor(linter): use diagnostic codes in lint rules

#4349Merged
Comparing
don/07-18-refactor_linter_use_diagnostic_codes_in_lint_rules
(
7a75e0f
) with
main
(
5f1e070
)
CodSpeed Performance Gauge
0%
Untouched
32

Benchmarks

Passed

linter[checker.ts]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
+1%
1.4 s1.4 s
linter[cal.com.tsx]
tasks/benchmark/benches/linter.rs::linter::bench_linter
CodSpeed Performance Gauge
+1%
768.7 ms763.6 ms
transformer[cal.com.tsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
76 ms75.6 ms
sourcemap[cal.com.tsx]
tasks/benchmark/benches/sourcemap.rs::sourcemap::bench_sourcemap
CodSpeed Performance Gauge
0%
57.2 ms57.1 ms
semantic[antd.js]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
175.1 ms174.6 ms
lexer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
22.8 µs22.7 µs
transformer[checker.ts]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
170.6 ms170.2 ms
parser[cal.com.tsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
24 ms24 ms
parser[checker.ts]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
52.4 ms52.4 ms
parser[antd.js]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
103.6 ms103.5 ms
transformer[antd.js]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
298 ms297.8 ms
parser[pdf.mjs]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
17.1 ms17.1 ms
minifier[antd.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
344.4 ms344.3 ms
transformer[pdf.mjs]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
45.9 ms45.9 ms
lexer[pdf.mjs]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
3.2 ms3.2 ms
codegen[checker.ts]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
19.1 ms19.1 ms
lexer[checker.ts]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
12 ms12 ms
lexer[antd.js]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
20.1 ms20.1 ms
lexer[cal.com.tsx]
tasks/benchmark/benches/lexer.rs::lexer::bench_lexer
CodSpeed Performance Gauge
0%
5 ms5 ms
prepass[typescript.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_passes
CodSpeed Performance Gauge
0%
28 ms28 ms
isolated-declarations[vue-id.ts]
tasks/benchmark/benches/isolated_declarations.rs::transformer::bench_isolated_declarations
CodSpeed Performance Gauge
0%
379.4 ms379.4 ms
prepass[antd.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_passes
CodSpeed Performance Gauge
0%
15.8 ms15.8 ms
minifier[typescript.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
691.9 ms692.1 ms
semantic[checker.ts]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
104.3 ms104.3 ms
codegen_sourcemap[checker.ts]
tasks/benchmark/benches/codegen.rs::codegen::bench_codegen
CodSpeed Performance Gauge
0%
76.5 ms76.5 ms
transformer[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/transformer.rs::transformer::bench_transformer
CodSpeed Performance Gauge
0%
233 µs233.6 µs
minifier[react.development.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_minifier
CodSpeed Performance Gauge
0%
3.9 ms3.9 ms
prepass[react.development.js]
tasks/benchmark/benches/minifier.rs::minifier::bench_passes
CodSpeed Performance Gauge
0%
208.4 µs208.9 µs
parser[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/parser.rs::parser::bench_parser
CodSpeed Performance Gauge
0%
77 µs77.2 µs
semantic[cal.com.tsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
0%
56.1 ms56.3 ms
semantic[pdf.mjs]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
-1%
26.5 ms26.8 ms
semantic[RadixUIAdoptionSection.jsx]
tasks/benchmark/benches/semantic.rs::semantic::bench_semantic
CodSpeed Performance Gauge
-2%
107.8 µs109.9 µs

Commits

Click on a commit to change the comparison range
Base
main
5f1e070
-0.02%
refactor(linter): use diagnostic codes in lint rules (#4349) > This PR is (unfortunately) quite large, but all changes are needed in tandem for this to work properly. ## What This PR Does Updates the linter to populate diagnostics reported by rules with error codes statically derived from `RuleMeta` + `RuleEnum`. Doing so required changing how we handle vitest rules. I know @mysterven was hoping to refactor that part of the code, and I think this approach is an improvement (but could probably be cleaned up further). ## Changes ### 1. Auto-Populate Error Codes `LintContext` now sets an error code scope + error code number for diagnostics reported by lint rules. `LintContext` will not clobber existing codes set by rules, allowing for rule-specific override behavior (e.g. to use `eslint-plugin-react-hooks` as an error scope). In order to accomplish this, I had to update every diagnostic factory for every rule. While doing this I found some incorrect error messages, or messages that could be easily improved. This is where a large majority of the snapshot diffs come from. Additionally, I was able to reduce string allocations from `format!` usages in diagnostic factories, especially within jest rules. ### 2. Framework and Library Detection This PR adds `FrameworkFlags`, which specify what (if any) set of libraries and frameworks are being used by a project and/or file. They are passed in two ways: 1. `LintOptions` can specify a set of `framework_hints` that apply to the entire target codebase. Right now these are always empty, but I'm thinking in the future we could sniff `package.json`. It may be helpful for enabling/disabling default rules. 2. When `Linter` gets run on a file, framework information is sniffed from the `LintContext`. Right now, we are only checking for `vitest` imports in `ModuleRecord` and test path prefixes from `source_path`. It may be useful to do something similar for React/NextJS rules in the future. I know that [next/no-html-link-for-pages](https://nextjs.org/docs/messages/no-html-link-for-pages) could benefit greatly from this.
7a75e0f
1 year ago
by DonIsaac
© 2025 CodSpeed Technology
Home Terms Privacy Docs