feat(linter/plugins): add parserOptions.lang option to RuleTester#16688
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. |
There was a problem hiding this comment.
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
langfield toParserOptionsinterface withLanguagetype ("js" | "jsx" | "ts" | "tsx" | "dts") - Modified filename generation logic to use
langoption for determining file extension when filename is not explicitly provided - Renamed
DEFAULT_PATHconstant toDEFAULT_FILENAME_BASEto 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.
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: [], }); ```
fadb424 to
563eab7
Compare
…#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: [], }); ```
…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: [], }); ```

Add
parserOptions.langtoRuleTester, as a more direct way to set language of code than setting filename.Accepted values for
lang:"js","jsx","ts","tsx","dts".