Skip to content

Commit 3e042b9

Browse files
committed
feat(linter): add schema for typescript/no-misused-promises (#23306)
1 parent da212d1 commit 3e042b9

4 files changed

Lines changed: 242 additions & 5 deletions

File tree

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export type FileFrom = "file";
228228
export type NameSpecifier = string | string[];
229229
export type LibFrom = "lib";
230230
export type PackageFrom = "package";
231+
export type ChecksVoidReturn = boolean | ChecksVoidReturnOptions;
231232
/**
232233
* Represents the different ways `allowConstantLoopConditions` can be specified in JSON.
233234
* Can be:
@@ -1326,7 +1327,7 @@ export interface DummyRuleMap {
13261327
| [AllowWarnDeny]
13271328
| [AllowWarnDeny, NoMeaninglessVoidOperatorConfig];
13281329
"typescript/no-misused-new"?: RuleNoConfig;
1329-
"typescript/no-misused-promises"?: DummyRule;
1330+
"typescript/no-misused-promises"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoMisusedPromisesConfig];
13301331
"typescript/no-misused-spread"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoMisusedSpreadConfig];
13311332
"typescript/no-mixed-enums"?: RuleNoConfig;
13321333
"typescript/no-namespace"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, NoNamespace];
@@ -4768,6 +4769,49 @@ export interface NoMeaninglessVoidOperatorConfig {
47684769
*/
47694770
checkNever?: boolean;
47704771
}
4772+
export interface NoMisusedPromisesConfig {
4773+
/**
4774+
* Whether to check if Promises are used in conditionals.
4775+
* When true, disallows using Promises in conditions where a boolean is expected.
4776+
*/
4777+
checksConditionals?: boolean;
4778+
/**
4779+
* Whether to check if Promises are used in spread syntax.
4780+
* When true, disallows spreading Promise values.
4781+
*/
4782+
checksSpreads?: boolean;
4783+
/**
4784+
* Configuration for checking if Promises are returned in contexts expecting void.
4785+
* Can be a boolean to enable/disable all checks, or an object for granular control.
4786+
*/
4787+
checksVoidReturn?: ChecksVoidReturn;
4788+
}
4789+
export interface ChecksVoidReturnOptions {
4790+
/**
4791+
* Whether to check Promise-returning functions passed as arguments to void-returning functions.
4792+
*/
4793+
arguments?: boolean;
4794+
/**
4795+
* Whether to check Promise-returning functions in JSX attributes expecting void.
4796+
*/
4797+
attributes?: boolean;
4798+
/**
4799+
* Whether to check Promise-returning methods that override void-returning inherited methods.
4800+
*/
4801+
inheritedMethods?: boolean;
4802+
/**
4803+
* Whether to check Promise-returning functions assigned to object properties expecting void.
4804+
*/
4805+
properties?: boolean;
4806+
/**
4807+
* Whether to check Promise values returned from void-returning functions.
4808+
*/
4809+
returns?: boolean;
4810+
/**
4811+
* Whether to check Promise-returning functions assigned to variables typed as void-returning.
4812+
*/
4813+
variables?: boolean;
4814+
}
47714815
export interface NoMisusedSpreadConfig {
47724816
/**
47734817
* An array of type or value specifiers that are allowed to be spread

‎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; 44] = [
16+
const NO_VERIFIED_VALID_SCHEMA: [&str; 43] = [
1717
"eslint/func-name-matching",
1818
"eslint/no-restricted-globals",
1919
"eslint/no-restricted-imports",
@@ -50,7 +50,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 44] = [
5050
"typescript/no-empty-object-type",
5151
"typescript/no-duplicate-type-constituents",
5252
"typescript/no-invalid-void-type",
53-
"typescript/no-misused-promises",
5453
"typescript/no-restricted-types",
5554
"unicorn/filename-case",
5655
"unicorn/import-style",

‎npm/oxlint/configuration_schema.json‎

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,58 @@
891891
},
892892
"additionalProperties": false
893893
},
894+
"ChecksVoidReturn": {
895+
"anyOf": [
896+
{
897+
"type": "boolean"
898+
},
899+
{
900+
"$ref": "#/definitions/ChecksVoidReturnOptions"
901+
}
902+
]
903+
},
904+
"ChecksVoidReturnOptions": {
905+
"type": "object",
906+
"properties": {
907+
"arguments": {
908+
"description": "Whether to check Promise-returning functions passed as arguments to void-returning functions.",
909+
"default": true,
910+
"type": "boolean",
911+
"markdownDescription": "Whether to check Promise-returning functions passed as arguments to void-returning functions."
912+
},
913+
"attributes": {
914+
"description": "Whether to check Promise-returning functions in JSX attributes expecting void.",
915+
"default": true,
916+
"type": "boolean",
917+
"markdownDescription": "Whether to check Promise-returning functions in JSX attributes expecting void."
918+
},
919+
"inheritedMethods": {
920+
"description": "Whether to check Promise-returning methods that override void-returning inherited methods.",
921+
"default": true,
922+
"type": "boolean",
923+
"markdownDescription": "Whether to check Promise-returning methods that override void-returning inherited methods."
924+
},
925+
"properties": {
926+
"description": "Whether to check Promise-returning functions assigned to object properties expecting void.",
927+
"default": true,
928+
"type": "boolean",
929+
"markdownDescription": "Whether to check Promise-returning functions assigned to object properties expecting void."
930+
},
931+
"returns": {
932+
"description": "Whether to check Promise values returned from void-returning functions.",
933+
"default": true,
934+
"type": "boolean",
935+
"markdownDescription": "Whether to check Promise values returned from void-returning functions."
936+
},
937+
"variables": {
938+
"description": "Whether to check Promise-returning functions assigned to variables typed as void-returning.",
939+
"default": true,
940+
"type": "boolean",
941+
"markdownDescription": "Whether to check Promise-returning functions assigned to variables typed as void-returning."
942+
}
943+
},
944+
"additionalProperties": false
945+
},
894946
"ClassLiteralPropertyStyleOption": {
895947
"oneOf": [
896948
{
@@ -6484,7 +6536,24 @@
64846536
"$ref": "#/definitions/RuleNoConfig"
64856537
},
64866538
"typescript/no-misused-promises": {
6487-
"$ref": "#/definitions/DummyRule"
6539+
"anyOf": [
6540+
{
6541+
"$ref": "#/definitions/AllowWarnDeny"
6542+
},
6543+
{
6544+
"type": "array",
6545+
"items": [
6546+
{
6547+
"$ref": "#/definitions/AllowWarnDeny"
6548+
},
6549+
{
6550+
"$ref": "#/definitions/NoMisusedPromisesConfig"
6551+
}
6552+
],
6553+
"maxItems": 2,
6554+
"minItems": 1
6555+
}
6556+
]
64886557
},
64896558
"typescript/no-misused-spread": {
64906559
"anyOf": [
@@ -12049,6 +12118,34 @@
1204912118
},
1205012119
"additionalProperties": false
1205112120
},
12121+
"NoMisusedPromisesConfig": {
12122+
"type": "object",
12123+
"properties": {
12124+
"checksConditionals": {
12125+
"description": "Whether to check if Promises are used in conditionals.\nWhen true, disallows using Promises in conditions where a boolean is expected.",
12126+
"default": true,
12127+
"type": "boolean",
12128+
"markdownDescription": "Whether to check if Promises are used in conditionals.\nWhen true, disallows using Promises in conditions where a boolean is expected."
12129+
},
12130+
"checksSpreads": {
12131+
"description": "Whether to check if Promises are used in spread syntax.\nWhen true, disallows spreading Promise values.",
12132+
"default": true,
12133+
"type": "boolean",
12134+
"markdownDescription": "Whether to check if Promises are used in spread syntax.\nWhen true, disallows spreading Promise values."
12135+
},
12136+
"checksVoidReturn": {
12137+
"description": "Configuration for checking if Promises are returned in contexts expecting void.\nCan be a boolean to enable/disable all checks, or an object for granular control.",
12138+
"default": true,
12139+
"allOf": [
12140+
{
12141+
"$ref": "#/definitions/ChecksVoidReturn"
12142+
}
12143+
],
12144+
"markdownDescription": "Configuration for checking if Promises are returned in contexts expecting void.\nCan be a boolean to enable/disable all checks, or an object for granular control."
12145+
}
12146+
},
12147+
"additionalProperties": false
12148+
},
1205212149
"NoMisusedSpreadConfig": {
1205312150
"type": "object",
1205412151
"properties": {

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

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,58 @@ expression: json
895895
},
896896
"additionalProperties": false
897897
},
898+
"ChecksVoidReturn": {
899+
"anyOf": [
900+
{
901+
"type": "boolean"
902+
},
903+
{
904+
"$ref": "#/definitions/ChecksVoidReturnOptions"
905+
}
906+
]
907+
},
908+
"ChecksVoidReturnOptions": {
909+
"type": "object",
910+
"properties": {
911+
"arguments": {
912+
"description": "Whether to check Promise-returning functions passed as arguments to void-returning functions.",
913+
"default": true,
914+
"type": "boolean",
915+
"markdownDescription": "Whether to check Promise-returning functions passed as arguments to void-returning functions."
916+
},
917+
"attributes": {
918+
"description": "Whether to check Promise-returning functions in JSX attributes expecting void.",
919+
"default": true,
920+
"type": "boolean",
921+
"markdownDescription": "Whether to check Promise-returning functions in JSX attributes expecting void."
922+
},
923+
"inheritedMethods": {
924+
"description": "Whether to check Promise-returning methods that override void-returning inherited methods.",
925+
"default": true,
926+
"type": "boolean",
927+
"markdownDescription": "Whether to check Promise-returning methods that override void-returning inherited methods."
928+
},
929+
"properties": {
930+
"description": "Whether to check Promise-returning functions assigned to object properties expecting void.",
931+
"default": true,
932+
"type": "boolean",
933+
"markdownDescription": "Whether to check Promise-returning functions assigned to object properties expecting void."
934+
},
935+
"returns": {
936+
"description": "Whether to check Promise values returned from void-returning functions.",
937+
"default": true,
938+
"type": "boolean",
939+
"markdownDescription": "Whether to check Promise values returned from void-returning functions."
940+
},
941+
"variables": {
942+
"description": "Whether to check Promise-returning functions assigned to variables typed as void-returning.",
943+
"default": true,
944+
"type": "boolean",
945+
"markdownDescription": "Whether to check Promise-returning functions assigned to variables typed as void-returning."
946+
}
947+
},
948+
"additionalProperties": false
949+
},
898950
"ClassLiteralPropertyStyleOption": {
899951
"oneOf": [
900952
{
@@ -6488,7 +6540,24 @@ expression: json
64886540
"$ref": "#/definitions/RuleNoConfig"
64896541
},
64906542
"typescript/no-misused-promises": {
6491-
"$ref": "#/definitions/DummyRule"
6543+
"anyOf": [
6544+
{
6545+
"$ref": "#/definitions/AllowWarnDeny"
6546+
},
6547+
{
6548+
"type": "array",
6549+
"items": [
6550+
{
6551+
"$ref": "#/definitions/AllowWarnDeny"
6552+
},
6553+
{
6554+
"$ref": "#/definitions/NoMisusedPromisesConfig"
6555+
}
6556+
],
6557+
"maxItems": 2,
6558+
"minItems": 1
6559+
}
6560+
]
64926561
},
64936562
"typescript/no-misused-spread": {
64946563
"anyOf": [
@@ -12053,6 +12122,34 @@ expression: json
1205312122
},
1205412123
"additionalProperties": false
1205512124
},
12125+
"NoMisusedPromisesConfig": {
12126+
"type": "object",
12127+
"properties": {
12128+
"checksConditionals": {
12129+
"description": "Whether to check if Promises are used in conditionals.\nWhen true, disallows using Promises in conditions where a boolean is expected.",
12130+
"default": true,
12131+
"type": "boolean",
12132+
"markdownDescription": "Whether to check if Promises are used in conditionals.\nWhen true, disallows using Promises in conditions where a boolean is expected."
12133+
},
12134+
"checksSpreads": {
12135+
"description": "Whether to check if Promises are used in spread syntax.\nWhen true, disallows spreading Promise values.",
12136+
"default": true,
12137+
"type": "boolean",
12138+
"markdownDescription": "Whether to check if Promises are used in spread syntax.\nWhen true, disallows spreading Promise values."
12139+
},
12140+
"checksVoidReturn": {
12141+
"description": "Configuration for checking if Promises are returned in contexts expecting void.\nCan be a boolean to enable/disable all checks, or an object for granular control.",
12142+
"default": true,
12143+
"allOf": [
12144+
{
12145+
"$ref": "#/definitions/ChecksVoidReturn"
12146+
}
12147+
],
12148+
"markdownDescription": "Configuration for checking if Promises are returned in contexts expecting void.\nCan be a boolean to enable/disable all checks, or an object for granular control."
12149+
}
12150+
},
12151+
"additionalProperties": false
12152+
},
1205612153
"NoMisusedSpreadConfig": {
1205712154
"type": "object",
1205812155
"properties": {

0 commit comments

Comments
 (0)