You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(linter): add support for vitest/valid-title rule (#12085)
I noticed that there's already a fully working implementation of
`jest/valid-title`, and the logic is very similar. However, the vitest
rule has slightly different configuration options, so it's not quite the
same. I made the `vitest/valid-title` rule work with their specific
configuration options and unit tests.
As part of this, I added support for the vitest typecheck option so that
all the vitest-specific test scenarios would pass for this rule. This
meant adding a `VitestPluginSettings` module with `typecheck` available
as a boolean, defaulting to false.
I considered trying to reuse some of the logic from the jest rule
equivalent, but since there are subtle differences I didn't think the
refactor was worth it on a first pass. The only tradeoff is that there's
some duplicate logic between the jest / vitest rules for this.
Future consideration: The only other rule that uses `typecheck` as a
config setting in `eslint-plugin-vitest` is the `expect-expect` rule,
which we currently have listed in the
[VITEST_COMPATIBLE_JEST_RULES](https://github.com/oxc-project/oxc/blob/main/crates/oxc_linter/src/utils/mod.rs#L34).
It might be worth adding support for `typecheck` in that rule for 100%
compatibility.
----
Reference:
Vitest Config Options from `vitest/valid_title.rs`):
```ts
interface Options {
ignoreTypeOfDescribeName?: boolean;
allowArguments?: boolean;
disallowedWords?: string[];
mustNotMatch?: Partial<Record<'describe' | 'test' | 'it', string>> | string;
mustMatch?: Partial<Record<'describe' | 'test' | 'it', string>> | string;
}
```
Jest Config Options (from `jest/valid_title.rs`):
```ts
interface Options {
ignoreSpaces?: boolean;
ignoreTypeOfTestName?: boolean;
ignoreTypeOfDescribeName?: boolean;
disallowedWords?: string[];
mustNotMatch?: Partial<Record<'describe' | 'test' | 'it', string>> | string;
mustMatch?: Partial<Record<'describe' | 'test' | 'it', string>> | string;
}
```
[Vitest valid-title Rule
Docs](https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/valid-title.md)
[Jest valid-title Rule
Docs](https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/valid-title.md)
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Claude <[email protected]>
Copy file name to clipboardExpand all lines: apps/oxlint/src/snapshots/_-c fixtures__print_config__ban_rules__eslintrc.json -A all -D eqeqeq [email protected]
Copy file name to clipboardExpand all lines: crates/oxc_linter/src/snapshots/schema_json.snap
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -113,6 +113,9 @@ expression: json
113
113
"implementsReplacesDocs": false,
114
114
"exemptDestructuredRootsFromChecks": false,
115
115
"tagNamePreference": {}
116
+
},
117
+
"vitest": {
118
+
"typecheck": false
116
119
}
117
120
},
118
121
"allOf": [
@@ -538,6 +541,16 @@ expression: json
538
541
"$ref": "#/definitions/ReactPluginSettings"
539
542
}
540
543
]
544
+
},
545
+
"vitest": {
546
+
"default": {
547
+
"typecheck": false
548
+
},
549
+
"allOf": [
550
+
{
551
+
"$ref": "#/definitions/VitestPluginSettings"
552
+
}
553
+
]
541
554
}
542
555
}
543
556
},
@@ -598,6 +611,17 @@ expression: json
598
611
"type": "boolean"
599
612
}
600
613
]
614
+
},
615
+
"VitestPluginSettings": {
616
+
"description": "Configure Vitest plugin rules.\n\nSee [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest)'s\nconfiguration for a full reference.",
617
+
"type": "object",
618
+
"properties": {
619
+
"typecheck": {
620
+
"description": "Whether to enable typecheck mode for Vitest rules.\nWhen enabled, some rules will skip certain checks for describe blocks\nto accommodate TypeScript type checking scenarios.",
Copy file name to clipboardExpand all lines: npm/oxlint/configuration_schema.json
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -109,6 +109,9 @@
109
109
"implementsReplacesDocs": false,
110
110
"exemptDestructuredRootsFromChecks": false,
111
111
"tagNamePreference": {}
112
+
},
113
+
"vitest": {
114
+
"typecheck": false
112
115
}
113
116
},
114
117
"allOf": [
@@ -534,6 +537,16 @@
534
537
"$ref": "#/definitions/ReactPluginSettings"
535
538
}
536
539
]
540
+
},
541
+
"vitest": {
542
+
"default": {
543
+
"typecheck": false
544
+
},
545
+
"allOf": [
546
+
{
547
+
"$ref": "#/definitions/VitestPluginSettings"
548
+
}
549
+
]
537
550
}
538
551
}
539
552
},
@@ -594,6 +607,17 @@
594
607
"type": "boolean"
595
608
}
596
609
]
610
+
},
611
+
"VitestPluginSettings": {
612
+
"description": "Configure Vitest plugin rules.\n\nSee [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest)'s\nconfiguration for a full reference.",
613
+
"type": "object",
614
+
"properties": {
615
+
"typecheck": {
616
+
"description": "Whether to enable typecheck mode for Vitest rules.\nWhen enabled, some rules will skip certain checks for describe blocks\nto accommodate TypeScript type checking scenarios.",
0 commit comments