Skip to content

Conversation

overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Sep 20, 2025

Add defineRule method for defining rules. This is the 2nd part of the "alternative API" mentioned in #9905 (comment).

import { defineRule } from 'oxlint';

export default defineRule({
  meta: { /* ... */ },
  create(context) {
    // Rule implementation
  }
});

or, using the alternative createOnce API:

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.


Incomplete. Needs tests, and we need to export TS type defs, so the type checking benefit of this API is realized.


This method 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.

Copy link
Member Author

overlookmotel commented Sep 20, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI labels Sep 20, 2025
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Sep 20, 2025
@overlookmotel overlookmotel self-assigned this Sep 20, 2025
@overlookmotel overlookmotel force-pushed the 09-20-feat_linter_plugins_add_createonce_api branch from e16f1ee to 988eab7 Compare September 21, 2025 10:03
@overlookmotel overlookmotel force-pushed the 09-20-feat_linter_plugins_add_definerule_api branch from 22a405c to 04075c5 Compare September 21, 2025 10:03
@overlookmotel overlookmotel force-pushed the 09-20-feat_linter_plugins_add_createonce_api branch from 988eab7 to 710d205 Compare September 21, 2025 10:06
@overlookmotel overlookmotel force-pushed the 09-20-feat_linter_plugins_add_definerule_api branch 2 times, most recently from d083feb to 561243d Compare September 21, 2025 10:31
@overlookmotel overlookmotel force-pushed the 09-20-feat_linter_plugins_add_createonce_api branch from a0a8490 to d903879 Compare September 21, 2025 15:00
@overlookmotel overlookmotel force-pushed the 09-20-feat_linter_plugins_add_definerule_api branch from 561243d to 14a9ec2 Compare September 21, 2025 15:00
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-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant