Skip to content

Commit e0d0f78

Browse files
beanscgcamc314Sysix
authored
feat(linter): verify promise/no-callback-in-promise schema (#23141)
## Summary - verify the `promise/no-callback-in-promise` config schema - remove the rule from `NO_VERIFIED_VALID_SCHEMA` - regenerate the oxlint JSON schema, website schema snapshot, and generated TypeScript config type Part of #22955. ## Verification - `cargo test -p oxc_linter no_callback_in_promise --lib` - `cargo test -p website_linter schema_json` - `cargo run -p website_linter schema-json > /tmp/oxc_no_callback_schema.json && cmp /tmp/oxc_no_callback_schema.json npm/oxlint/configuration_schema.json` - `cargo fmt --check` - `git diff --check` --------- Signed-off-by: Cameron <[email protected]> Co-authored-by: Bean Labs <[email protected]> Co-authored-by: Cameron <[email protected]> Co-authored-by: Alexander S. <[email protected]>
1 parent de2d23b commit e0d0f78

6 files changed

Lines changed: 93 additions & 16 deletions

File tree

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ export interface DummyRuleMap {
11231123
"promise/always-return"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, AlwaysReturnConfig];
11241124
"promise/avoid-new"?: RuleNoConfig;
11251125
"promise/catch-or-return"?: DummyRule;
1126-
"promise/no-callback-in-promise"?: DummyRule;
1126+
"promise/no-callback-in-promise"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoCallbackInPromiseConfig];
11271127
"promise/no-multiple-resolved"?: RuleNoConfig;
11281128
"promise/no-nesting"?: RuleNoConfig;
11291129
"promise/no-new-statics"?: RuleNoConfig;
@@ -3804,6 +3804,16 @@ export interface AlwaysReturnConfig {
38043804
*/
38053805
ignoreLastCallback?: boolean;
38063806
}
3807+
export interface NoCallbackInPromiseConfig {
3808+
/**
3809+
* List of callback function names to allow within Promise `then` and `catch` methods.
3810+
*/
3811+
exceptions?: string[];
3812+
/**
3813+
* Boolean as to whether callbacks in timeout functions like `setTimeout` will err.
3814+
*/
3815+
timeoutsErr?: boolean;
3816+
}
38073817
export interface NoPromiseInCallbackConfig {
38083818
/**
38093819
* Whether or not to exempt function declarations. Defaults to `false`.

crates/oxc_linter/src/rules/promise/no_callback_in_promise.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ fn no_callback_in_promise_diagnostic(span: Span) -> OxcDiagnostic {
2121
pub struct NoCallbackInPromise(Box<NoCallbackInPromiseConfig>);
2222

2323
#[derive(Debug, Clone, JsonSchema, Deserialize)]
24-
#[serde(rename_all = "camelCase", default)]
24+
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
2525
pub struct NoCallbackInPromiseConfig {
2626
/// List of callback function names to check for within Promise `then` and `catch` methods.
27+
#[serde(skip)]
2728
callbacks: Vec<CompactStr>,
2829
/// List of callback function names to allow within Promise `then` and `catch` methods.
2930
exceptions: Vec<CompactStr>,

crates/oxc_linter/src/utils/schemars.rs

Lines changed: 1 addition & 2 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; 68] = [
16+
const NO_VERIFIED_VALID_SCHEMA: [&str; 67] = [
1717
"eslint/func-name-matching",
1818
"eslint/no-restricted-globals",
1919
"eslint/no-restricted-imports",
@@ -39,7 +39,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 68] = [
3939
"node/callback-return",
4040
"oxc/no-async-endpoint-handlers",
4141
"promise/catch-or-return",
42-
"promise/no-callback-in-promise",
4342
"promise/param-names",
4443
"react/exhaustive-deps",
4544
"react/jsx-curly-brace-presence",

npm/oxlint/configuration_schema.json

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4758,7 +4758,24 @@
47584758
"$ref": "#/definitions/DummyRule"
47594759
},
47604760
"promise/no-callback-in-promise": {
4761-
"$ref": "#/definitions/DummyRule"
4761+
"anyOf": [
4762+
{
4763+
"$ref": "#/definitions/AllowWarnDeny"
4764+
},
4765+
{
4766+
"type": "array",
4767+
"items": [
4768+
{
4769+
"$ref": "#/definitions/AllowWarnDeny"
4770+
},
4771+
{
4772+
"$ref": "#/definitions/NoCallbackInPromiseConfig"
4773+
}
4774+
],
4775+
"maxItems": 2,
4776+
"minItems": 1
4777+
}
4778+
]
47624779
},
47634780
"promise/no-multiple-resolved": {
47644781
"$ref": "#/definitions/RuleNoConfig"
@@ -10113,6 +10130,27 @@
1011310130
},
1011410131
"additionalProperties": false
1011510132
},
10133+
"NoCallbackInPromiseConfig": {
10134+
"type": "object",
10135+
"properties": {
10136+
"exceptions": {
10137+
"description": "List of callback function names to allow within Promise `then` and `catch` methods.",
10138+
"default": [],
10139+
"type": "array",
10140+
"items": {
10141+
"type": "string"
10142+
},
10143+
"markdownDescription": "List of callback function names to allow within Promise `then` and `catch` methods."
10144+
},
10145+
"timeoutsErr": {
10146+
"description": "Boolean as to whether callbacks in timeout functions like `setTimeout` will err.",
10147+
"default": false,
10148+
"type": "boolean",
10149+
"markdownDescription": "Boolean as to whether callbacks in timeout functions like `setTimeout` will err."
10150+
}
10151+
},
10152+
"additionalProperties": false
10153+
},
1011610154
"NoCommonjs": {
1011710155
"type": "object",
1011810156
"properties": {
@@ -14248,4 +14286,4 @@
1424814286
}
1424914287
},
1425014288
"markdownDescription": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```\n\n`oxlint.config.ts`\n\n```ts\nimport { defineConfig } from \"oxlint\";\n\nexport default defineConfig({\nplugins: [\"import\", \"typescript\", \"unicorn\"],\nenv: {\n\"browser\": true\n},\nglobals: {\n\"foo\": \"readonly\"\n},\nsettings: {\nreact: {\nversion: \"18.2.0\"\n},\ncustom: { option: true }\n},\nrules: {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\noverrides: [\n{\nfiles: [\"*.test.ts\", \"*.spec.ts\"],\nrules: {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n});\n```"
14251-
}
14289+
}

tasks/website_linter/src/rules/snapshots/docs_rule_pages.snap

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -947,15 +947,6 @@ Promise.resolve()
947947

948948
This rule accepts a configuration object with the following properties:
949949

950-
### callbacks
951-
952-
type: `string[]`
953-
954-
default: `["callback", "cb", "done", "next"]`
955-
956-
List of callback function names to check for within Promise `then` and `catch` methods.
957-
958-
959950
### exceptions
960951

961952
type: `string[]`

tasks/website_linter/src/snapshots/schema_json.snap

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4762,7 +4762,24 @@ expression: json
47624762
"$ref": "#/definitions/DummyRule"
47634763
},
47644764
"promise/no-callback-in-promise": {
4765-
"$ref": "#/definitions/DummyRule"
4765+
"anyOf": [
4766+
{
4767+
"$ref": "#/definitions/AllowWarnDeny"
4768+
},
4769+
{
4770+
"type": "array",
4771+
"items": [
4772+
{
4773+
"$ref": "#/definitions/AllowWarnDeny"
4774+
},
4775+
{
4776+
"$ref": "#/definitions/NoCallbackInPromiseConfig"
4777+
}
4778+
],
4779+
"maxItems": 2,
4780+
"minItems": 1
4781+
}
4782+
]
47664783
},
47674784
"promise/no-multiple-resolved": {
47684785
"$ref": "#/definitions/RuleNoConfig"
@@ -10117,6 +10134,27 @@ expression: json
1011710134
},
1011810135
"additionalProperties": false
1011910136
},
10137+
"NoCallbackInPromiseConfig": {
10138+
"type": "object",
10139+
"properties": {
10140+
"exceptions": {
10141+
"description": "List of callback function names to allow within Promise `then` and `catch` methods.",
10142+
"default": [],
10143+
"type": "array",
10144+
"items": {
10145+
"type": "string"
10146+
},
10147+
"markdownDescription": "List of callback function names to allow within Promise `then` and `catch` methods."
10148+
},
10149+
"timeoutsErr": {
10150+
"description": "Boolean as to whether callbacks in timeout functions like `setTimeout` will err.",
10151+
"default": false,
10152+
"type": "boolean",
10153+
"markdownDescription": "Boolean as to whether callbacks in timeout functions like `setTimeout` will err."
10154+
}
10155+
},
10156+
"additionalProperties": false
10157+
},
1012010158
"NoCommonjs": {
1012110159
"type": "object",
1012210160
"properties": {

0 commit comments

Comments
 (0)