Skip to content

feat(linter/plugins): add parserOptions.lang option to RuleTester#16688

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-10-feat_linter_plugins_add_parseroptions.lang_option_to_ruletester_
Dec 10, 2025
Merged

feat(linter/plugins): add parserOptions.lang option to RuleTester#16688
graphite-app[bot] merged 1 commit intomainfrom
12-10-feat_linter_plugins_add_parseroptions.lang_option_to_ruletester_

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Dec 10, 2025

Add parserOptions.lang to RuleTester, as a more direct way to set language of code than setting filename.

Accepted values for lang: "js", "jsx", "ts", "tsx", "dts".

const tester = new RuleTester({
  languageOptions: {
    parserOptions: {
      lang: "ts",
    },
  },
});

tester.run("my-rule", rule, {
  valid: [
    // No parsing error
    "let s: string;",
  ],
  invalid: [],
});

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins C-enhancement Category - New feature or request labels Dec 10, 2025
Copy link
Copy Markdown
Member Author


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.

Copy link
Copy Markdown
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 adds a parserOptions.lang option to the RuleTester class, providing a more direct way to specify the language variant of test code without relying on filename extensions. The supported language values are "js", "jsx", "ts", "tsx", and "dts".

Key Changes:

  • Added lang field to ParserOptions interface with Language type ("js" | "jsx" | "ts" | "tsx" | "dts")
  • Modified filename generation logic to use lang option for determining file extension when filename is not explicitly provided
  • Renamed DEFAULT_PATH constant to DEFAULT_FILENAME_BASE to reflect that it's now used as a base for dynamic filename generation
  • Added comprehensive test coverage for all language variants across different configuration levels (global, RuleTester instance, and individual test case)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/oxlint/src-js/package/rule_tester.ts Implements the lang option handling: updates ParserOptions interface, adds logic to generate default filenames based on lang value, and extracts lang from languageOptions.parserOptions in getParseOptions() function
apps/oxlint/test/rule_tester.test.ts Adds comprehensive test coverage with 770+ lines of tests covering all five language variants, configuration override scenarios (global, RuleTester-level, test case-level), and mixed language test cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel overlookmotel self-assigned this Dec 10, 2025
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 10, 2025
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 10, 2025

Merge activity

…#16688)

Add `parserOptions.lang` to `RuleTester`, as a more direct way to set language of code than setting filename.

Accepted values for `lang`: `"js"`, `"jsx"`, `"ts"`, `"tsx"`, `"dts"`.

```js
const tester = new RuleTester({
  languageOptions: {
    parserOptions: {
      lang: "ts",
    },
  },
});

tester.run("my-rule", rule, {
  valid: [
    // No parsing error
    "let s: string;",
  ],
  invalid: [],
});
```
@graphite-app graphite-app bot force-pushed the 12-10-feat_linter_plugins_add_parseroptions.lang_option_to_ruletester_ branch from fadb424 to 563eab7 Compare December 10, 2025 11:10
@graphite-app graphite-app bot merged commit 563eab7 into main Dec 10, 2025
18 checks passed
@graphite-app graphite-app bot deleted the 12-10-feat_linter_plugins_add_parseroptions.lang_option_to_ruletester_ branch December 10, 2025 11:16
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 10, 2025
Copilot AI pushed a commit that referenced this pull request Dec 10, 2025
…#16688)

Add `parserOptions.lang` to `RuleTester`, as a more direct way to set language of code than setting filename.

Accepted values for `lang`: `"js"`, `"jsx"`, `"ts"`, `"tsx"`, `"dts"`.

```js
const tester = new RuleTester({
  languageOptions: {
    parserOptions: {
      lang: "ts",
    },
  },
});

tester.run("my-rule", rule, {
  valid: [
    // No parsing error
    "let s: string;",
  ],
  invalid: [],
});
```
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
…oxc-project#16688)

Add `parserOptions.lang` to `RuleTester`, as a more direct way to set language of code than setting filename.

Accepted values for `lang`: `"js"`, `"jsx"`, `"ts"`, `"tsx"`, `"dts"`.

```js
const tester = new RuleTester({
  languageOptions: {
    parserOptions: {
      lang: "ts",
    },
  },
});

tester.run("my-rule", rule, {
  valid: [
    // No parsing error
    "let s: string;",
  ],
  invalid: [],
});
```
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 A-linter-plugins Area - Linter JS plugins C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants