-
-
Notifications
You must be signed in to change notification settings - Fork 719
feat(linter/plugins): add defineRule API
#13945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(linter/plugins): add defineRule API
#13945
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
e16f1ee to
988eab7
Compare
22a405c to
04075c5
Compare
988eab7 to
710d205
Compare
d083feb to
561243d
Compare
a0a8490 to
d903879
Compare
561243d to
14a9ec2
Compare
d903879 to
6934416
Compare
14a9ec2 to
5e81c2c
Compare
bf0fe86 to
1dabd2d
Compare
5e81c2c to
2a44fe0
Compare
1dabd2d to
2dc8adb
Compare
2a44fe0 to
28d072a
Compare
28d072a to
b174b4c
Compare
b174b4c to
af80c05
Compare
af80c05 to
96ef735
Compare
CodSpeed Instrumentation Performance ReportMerging #13945 will not alter performanceComparing Summary
Footnotes |
96ef735 to
490cf9e
Compare
5d678f1 to
22ff90f
Compare
Merge activity
|
Add `defineRule` method for defining rules. This is the 2nd part of the "alternative API" mentioned in #9905 (comment). ```js import { defineRule } from 'oxlint'; export default defineRule({ meta: { /* ... */ }, create(context) { // Rule implementation } }); ``` or, using the alternative `createOnce` API: ```js export default defineRule({ meta: { /* ... */ }, createOnce(context) { // Rule implementation } }); ``` When using `createOnce`, `defineRule` creates a `create` method and adds it to the rule object. So the rule remains ESLint-compatible, while getting a potential speed boost when the rule is used with Oxlint. This PR includes a test that runs an Oxlint plugin that uses `defineRule` + `createOnce` in ESLint. Not done yet: We need to export TS type defs, so the type checking benefit of `defineRule` is realized. I'll do that in a later PR. --- `defineRule` is intended to be used when defining JS plugins, so we should move it into a separate NPM package (`oxlint-tools`?), so that someone publishing a plugin to NPM doesn't need their plugin to have a dependency on `oxlint` itself, which includes large binaries. But for now, for simplicity, just include it in `oxlint` package.
TSDown 0.15.2+ breaks building `oxlint`, once a new entry point is added (which #13945 does). rolldown/tsdown#503 Pin `tsdown` dependency to 0.15.1 to work around this until fixed in TSDown.
22ff90f to
a018756
Compare
490cf9e to
3e117c6
Compare
## [1.17.0] - 2025-09-23 ### 🚀 Features - f47f978 linter/plugins: Add `definePlugin` API (#14008) (overlookmotel) - 3e117c6 linter/plugins: Add `defineRule` API (#13945) (overlookmotel) - 2dc8adb linter/plugins: Add `createOnce` API (#13944) (overlookmotel) - bef8753 linter/plugins: ESTree-compatible AST for JS plugins (#13942) (overlookmotel) - 55c2e11 editor: Add `oxc.fmt.experimental` flag (#13923) (Sysix) - a21ff54 language_server: Introduce `ServerFormatter` (#13700) (Sysix) - a14aa79 npm/oxlint: Convert to ES modules (#13876) (Boshen) - 15eb326 linter: Add `vue/no-required-prop-with-default` rule (#13613) (yefan) - 5d3ba00 linter: Add `vue/require-typed-ref` rule (#13857) (yefan) - b52389a node: Bump `engines` field to require Node.js 20.19.0+ for ESM support (#13879) (Copilot) - 8221a01 linter: Add `eslint/no-misleading-character-class` (#13365) (Sysix) - c75ae8c linter/plugins: Add options to `Context` (#13810) (overlookmotel) - 53d04dd linter: Convert `oxlint` to NAPI app (#13723) (overlookmotel) ### 🐛 Bug Fixes - 1f4be38 napi/parser: Generate `.d.mts` extension for types (#14038) (Daniel Roe) - a018756 linter/plugins: Pin `tsdown` dependency to 0.15.1 (#14005) (overlookmotel) - b8790c2 language_server: Output correct position for parser & semantic errors (#14010) (Sysix) - 4d3c6e1 linter: Support let-chains in codegen node type detection (#14006) (camc314) - a34918a linter/plugins: Avoid lint warnings compiling WASM or big-endian (#13968) (overlookmotel) - 27022ab linter/switch-case-braces: Add support for string including colon on case expression (#13687) (Lukinoh) - dd3843f linter: Set package version in `package.json` (#13890) (overlookmotel) - fa866b3 linter: Sort optimized/unoptimized diagnostics before comparison (#13850) (camc314) - fac7624 linter/plugins: Improve error for no JS plugins (#13858) (overlookmotel) ### 🚜 Refactor - bb040bc parser, linter: Replace `.mjs` files with `.js` (#14045) (overlookmotel) - b353750 linter/plugins: Remove unnecessary `Serialize` derives (#14031) (overlookmotel) - 0d48511 linter/plugins: Improve handling `Context` method calls in `createOnce` (#14032) (overlookmotel) - 36ac0fb language_server: Don't create `mpsc` channel (#14011) (Sysix) - 2e9ae3f linter: Make disable directives own the rule name (#13987) (camc314) - 6bc7664 oxlint: Run oxlint before tsgolint (#13519) (camc314) - 0c93f33 language_server: Use minimal text edit for `ServerFormatter` (#13960) (Sysix) - 823cb57 langauge_server: Move `Backend` into own file (#13955) (Sysix) - dc700f5 language_server: Introduce `LSPFileSystem` (#13731) (Sysix) - 42e2c1d linter: Remove `Rc` from `DisableDirectives` (#13924) (camc314) - ac3e9e9 napi/parser: Move JS code into `src-js` directory (#13899) (overlookmotel) - e90bfe3 linter: Remove double reference in unicorn/error-message (#13916) (camc314) - 83791a0 linter: Remove double reference in vue/jsx-no-undef (#13915) (camc314) - ebd22de linter: Remove double reference in vue/require-typed-ref (#13914) (camc314) - 873e231 language_server: Move `needs_linter_restart` to `ServerLinter` (#13834) (Sysix) - 7e0d736 linter/plugins: Rename `--experimental-js-plugins` to `--js-plugins` (#13860) (overlookmotel) - 6245c8c linter/plugins: Make `Context` properties getters (#13809) (overlookmotel) - a2342a6 linter/plugins: Import named in tests (#13807) (overlookmotel) ### 📚 Documentation - 601c876 linter: Add comment explaining why Mimalloc is feature-gated (#14037) (overlookmotel) ### ⚡ Performance - 4d04c6e linter/plugins: Flatten `LintFileResult` fields (#14033) (overlookmotel) - 06363e0 linter: Add node type codegen support for `match node.kind()` (#13736) (camchenry) - a79af0a linter: Replace `for (... of ...)` loops (#13913) (overlookmotel) - b53292d linter: Use unstable sort where possible (#13818) (sapphi-red) ### 🎨 Styling - 8083740 linter: Import `Serialize` at top level (#14030) (overlookmotel) ### 🧪 Testing - b807b6f language_server: Skip formatter test on windows (#13986) (Sysix) - 2600858 language_server: Add Tester for ServerFormatter (#13969) (Sysix) - 37aadf0 language_server: Add `test_and_snapshot_multiple_file` (#13966) (Sysix) - ad14a41 editor: Fix test setup (#13929) (Sysix) - f51240e linter/plugins: Tests for different import styles (#13859) (overlookmotel) - 407c95e linter/plugins: Check `this` is undefined in visit functions (#13811) (overlookmotel) - f023a22 linter/plugins: Include stack trace in plugin loading errors (#13808) (overlookmotel) ### 💼 Other - 0630d68 linter: Build `oxlint` locally with Mimalloc in release mode (#14034) (overlookmotel) Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>

Add
defineRulemethod for defining rules. This is the 2nd part of the "alternative API" mentioned in #9905 (comment).or, using the alternative
createOnceAPI:When using
createOnce,defineRulecreates acreatemethod and adds it to the rule object. So the rule remains ESLint-compatible, while getting a potential speed boost when the rule is used with Oxlint. This PR includes a test that runs an Oxlint plugin that usesdefineRule+createOncein ESLint.Not done yet: We need to export TS type defs, so the type checking benefit of
defineRuleis realized. I'll do that in a later PR.defineRuleis intended to be used when defining JS plugins, so we should move it into a separate NPM package (oxlint-tools?), so that someone publishing a plugin to NPM doesn't need their plugin to have a dependency onoxlintitself, which includes large binaries.But for now, for simplicity, just include it in
oxlintpackage.