Skip to content

Commit 123d4f4

Browse files
committed
feat(linter): add schema for jest/vitest/valid-expect (#23185)
related #22955
1 parent 46c8a21 commit 123d4f4

5 files changed

Lines changed: 174 additions & 10 deletions

File tree

‎apps/oxlint/src-js/package/config.generated.ts‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ export interface DummyRuleMap {
836836
"jest/require-to-throw-message"?: RuleNoConfig;
837837
"jest/require-top-level-describe"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, RequireTopLevelDescribeConfig];
838838
"jest/valid-describe-callback"?: RuleNoConfig;
839-
"jest/valid-expect"?: DummyRule;
839+
"jest/valid-expect"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, ValidExpectConfig];
840840
"jest/valid-expect-in-promise"?: RuleNoConfig;
841841
"jest/valid-title"?: DummyRule;
842842
"jsdoc/check-access"?: RuleNoConfig;
@@ -1593,7 +1593,7 @@ export interface DummyRuleMap {
15931593
| [AllowWarnDeny]
15941594
| [AllowWarnDeny, RequireTopLevelDescribeConfig];
15951595
"vitest/valid-describe-callback"?: RuleNoConfig;
1596-
"vitest/valid-expect"?: DummyRule;
1596+
"vitest/valid-expect"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, ValidExpectConfig];
15971597
"vitest/valid-expect-in-promise"?: RuleNoConfig;
15981598
"vitest/valid-title"?: DummyRule;
15991599
"vitest/warn-todo"?: RuleNoConfig;
@@ -2254,6 +2254,24 @@ export interface RequireTopLevelDescribeConfig {
22542254
*/
22552255
maxNumberOfTopLevelDescribes?: number;
22562256
}
2257+
export interface ValidExpectConfig {
2258+
/**
2259+
* When `true`, async assertions must be awaited in all contexts (not just return statements).
2260+
*/
2261+
alwaysAwait?: boolean;
2262+
/**
2263+
* List of matchers that are considered async and therefore require awaiting (e.g. `toResolve`, `toReject`).
2264+
*/
2265+
asyncMatchers?: string[];
2266+
/**
2267+
* Maximum number of arguments `expect` should be called with.
2268+
*/
2269+
maxArgs?: number;
2270+
/**
2271+
* Minimum number of arguments `expect` should be called with.
2272+
*/
2273+
minArgs?: number;
2274+
}
22572275
export interface CheckTagNamesConfig {
22582276
/**
22592277
* Additional tag names to allow.

‎crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ expect(Promise.resolve('Hi!')).resolves.toBe('Hi!');
5252
";
5353

5454
#[derive(Debug, Clone, JsonSchema)]
55-
#[serde(rename_all = "camelCase", default)]
55+
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
5656
pub struct ValidExpectConfig {
5757
/// List of matchers that are considered async and therefore require awaiting (e.g. `toResolve`, `toReject`).
5858
async_matchers: Vec<String>,

‎crates/oxc_linter/src/utils/schemars.rs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::rules::RuleEnum;
1313
/// These should return the DummyRule struct/schema instead of the actual rule struct/schema,
1414
/// until we verify that the rule's schema is valid and can be generated by schemars.
1515
#[cfg(feature = "ruledocs")]
16-
const NO_VERIFIED_VALID_SCHEMA: [&str; 70] = [
16+
const NO_VERIFIED_VALID_SCHEMA: [&str; 68] = [
1717
"eslint/func-name-matching",
1818
"eslint/no-restricted-globals",
1919
"eslint/no-restricted-imports",
@@ -23,7 +23,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 70] = [
2323
"jest/no-restricted-jest-methods",
2424
"jest/no-restricted-matchers",
2525
"jest/prefer-lowercase-title",
26-
"jest/valid-expect",
2726
"jest/valid-title",
2827
"jsdoc/require-param",
2928
"jsx_a11y/alt-text",
@@ -81,7 +80,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 70] = [
8180
"vitest/no-restricted-vi-methods",
8281
"vitest/prefer-import-in-mock",
8382
"vitest/prefer-lowercase-title",
84-
"vitest/valid-expect",
8583
"vitest/valid-title",
8684
"vue/define-props-destructuring",
8785
];

‎npm/oxlint/configuration_schema.json‎

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,24 @@
24742474
"$ref": "#/definitions/RuleNoConfig"
24752475
},
24762476
"jest/valid-expect": {
2477-
"$ref": "#/definitions/DummyRule"
2477+
"anyOf": [
2478+
{
2479+
"$ref": "#/definitions/AllowWarnDeny"
2480+
},
2481+
{
2482+
"type": "array",
2483+
"items": [
2484+
{
2485+
"$ref": "#/definitions/AllowWarnDeny"
2486+
},
2487+
{
2488+
"$ref": "#/definitions/ValidExpectConfig"
2489+
}
2490+
],
2491+
"maxItems": 2,
2492+
"minItems": 1
2493+
}
2494+
]
24782495
},
24792496
"jest/valid-expect-in-promise": {
24802497
"$ref": "#/definitions/RuleNoConfig"
@@ -7763,7 +7780,24 @@
77637780
"$ref": "#/definitions/RuleNoConfig"
77647781
},
77657782
"vitest/valid-expect": {
7766-
"$ref": "#/definitions/DummyRule"
7783+
"anyOf": [
7784+
{
7785+
"$ref": "#/definitions/AllowWarnDeny"
7786+
},
7787+
{
7788+
"type": "array",
7789+
"items": [
7790+
{
7791+
"$ref": "#/definitions/AllowWarnDeny"
7792+
},
7793+
{
7794+
"$ref": "#/definitions/ValidExpectConfig"
7795+
}
7796+
],
7797+
"maxItems": 2,
7798+
"minItems": 1
7799+
}
7800+
]
77677801
},
77687802
"vitest/valid-expect-in-promise": {
77697803
"$ref": "#/definitions/RuleNoConfig"
@@ -14076,6 +14110,46 @@
1407614110
},
1407714111
"additionalProperties": false
1407814112
},
14113+
"ValidExpectConfig": {
14114+
"type": "object",
14115+
"properties": {
14116+
"alwaysAwait": {
14117+
"description": "When `true`, async assertions must be awaited in all contexts (not just return statements).",
14118+
"default": false,
14119+
"type": "boolean",
14120+
"markdownDescription": "When `true`, async assertions must be awaited in all contexts (not just return statements)."
14121+
},
14122+
"asyncMatchers": {
14123+
"description": "List of matchers that are considered async and therefore require awaiting (e.g. `toResolve`, `toReject`).",
14124+
"default": [
14125+
"toResolve",
14126+
"toReject"
14127+
],
14128+
"type": "array",
14129+
"items": {
14130+
"type": "string"
14131+
},
14132+
"markdownDescription": "List of matchers that are considered async and therefore require awaiting (e.g. `toResolve`, `toReject`)."
14133+
},
14134+
"maxArgs": {
14135+
"description": "Maximum number of arguments `expect` should be called with.",
14136+
"default": 1,
14137+
"type": "integer",
14138+
"format": "uint",
14139+
"minimum": 0.0,
14140+
"markdownDescription": "Maximum number of arguments `expect` should be called with."
14141+
},
14142+
"minArgs": {
14143+
"description": "Minimum number of arguments `expect` should be called with.",
14144+
"default": 1,
14145+
"type": "integer",
14146+
"format": "uint",
14147+
"minimum": 0.0,
14148+
"markdownDescription": "Minimum number of arguments `expect` should be called with."
14149+
}
14150+
},
14151+
"additionalProperties": false
14152+
},
1407914153
"ValidTypeof": {
1408014154
"type": "object",
1408114155
"properties": {

‎tasks/website_linter/src/snapshots/schema_json.snap‎

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,7 +2478,24 @@ expression: json
24782478
"$ref": "#/definitions/RuleNoConfig"
24792479
},
24802480
"jest/valid-expect": {
2481-
"$ref": "#/definitions/DummyRule"
2481+
"anyOf": [
2482+
{
2483+
"$ref": "#/definitions/AllowWarnDeny"
2484+
},
2485+
{
2486+
"type": "array",
2487+
"items": [
2488+
{
2489+
"$ref": "#/definitions/AllowWarnDeny"
2490+
},
2491+
{
2492+
"$ref": "#/definitions/ValidExpectConfig"
2493+
}
2494+
],
2495+
"maxItems": 2,
2496+
"minItems": 1
2497+
}
2498+
]
24822499
},
24832500
"jest/valid-expect-in-promise": {
24842501
"$ref": "#/definitions/RuleNoConfig"
@@ -7767,7 +7784,24 @@ expression: json
77677784
"$ref": "#/definitions/RuleNoConfig"
77687785
},
77697786
"vitest/valid-expect": {
7770-
"$ref": "#/definitions/DummyRule"
7787+
"anyOf": [
7788+
{
7789+
"$ref": "#/definitions/AllowWarnDeny"
7790+
},
7791+
{
7792+
"type": "array",
7793+
"items": [
7794+
{
7795+
"$ref": "#/definitions/AllowWarnDeny"
7796+
},
7797+
{
7798+
"$ref": "#/definitions/ValidExpectConfig"
7799+
}
7800+
],
7801+
"maxItems": 2,
7802+
"minItems": 1
7803+
}
7804+
]
77717805
},
77727806
"vitest/valid-expect-in-promise": {
77737807
"$ref": "#/definitions/RuleNoConfig"
@@ -14080,6 +14114,46 @@ expression: json
1408014114
},
1408114115
"additionalProperties": false
1408214116
},
14117+
"ValidExpectConfig": {
14118+
"type": "object",
14119+
"properties": {
14120+
"alwaysAwait": {
14121+
"description": "When `true`, async assertions must be awaited in all contexts (not just return statements).",
14122+
"default": false,
14123+
"type": "boolean",
14124+
"markdownDescription": "When `true`, async assertions must be awaited in all contexts (not just return statements)."
14125+
},
14126+
"asyncMatchers": {
14127+
"description": "List of matchers that are considered async and therefore require awaiting (e.g. `toResolve`, `toReject`).",
14128+
"default": [
14129+
"toResolve",
14130+
"toReject"
14131+
],
14132+
"type": "array",
14133+
"items": {
14134+
"type": "string"
14135+
},
14136+
"markdownDescription": "List of matchers that are considered async and therefore require awaiting (e.g. `toResolve`, `toReject`)."
14137+
},
14138+
"maxArgs": {
14139+
"description": "Maximum number of arguments `expect` should be called with.",
14140+
"default": 1,
14141+
"type": "integer",
14142+
"format": "uint",
14143+
"minimum": 0.0,
14144+
"markdownDescription": "Maximum number of arguments `expect` should be called with."
14145+
},
14146+
"minArgs": {
14147+
"description": "Minimum number of arguments `expect` should be called with.",
14148+
"default": 1,
14149+
"type": "integer",
14150+
"format": "uint",
14151+
"minimum": 0.0,
14152+
"markdownDescription": "Minimum number of arguments `expect` should be called with."
14153+
}
14154+
},
14155+
"additionalProperties": false
14156+
},
1408314157
"ValidTypeof": {
1408414158
"type": "object",
1408514159
"properties": {

0 commit comments

Comments
 (0)