mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
feat(linter): add schema for typescript/no-unnecessary-condition (#23305)
The upstream rule has an option we do not to support:
```
/** Whether to not error when running with a tsconfig that has strictNullChecks turned. */
allowRuleToRunWithoutStrictNullChecksIKnowWhatIAmDoing?: boolean;
```
https://typescript-eslint.io/rules/no-unnecessary-condition/
This commit is contained in:
1 parent
f8f0d38eb3
commit
da212d1d1d
4 files changed
+144
-5
No files matched your search
@@ -228,6 +228,14 @@ export type FileFrom = "file";
|
||||
export type NameSpecifier = string | string[];
|
||||
export type LibFrom = "lib";
|
||||
export type PackageFrom = "package";
|
||||
/**
|
||||
* Represents the different ways `allowConstantLoopConditions` can be specified in JSON.
|
||||
* Can be:
|
||||
* - `true` or `false`
|
||||
* - A string enum (`"never"`, `"always"`, `"only-allowed-literals"`)
|
||||
*/
|
||||
export type AllowConstantLoopConditions = boolean | AllowConstantLoopConditionsMode;
|
||||
export type AllowConstantLoopConditionsMode = "never" | "always" | "only-allowed-literals";
|
||||
export type Modifier =
|
||||
| "private"
|
||||
| "private readonly"
|
||||
@@ -1333,7 +1341,10 @@ export interface DummyRuleMap {
|
||||
| AllowWarnDeny
|
||||
| [AllowWarnDeny]
|
||||
| [AllowWarnDeny, NoUnnecessaryBooleanLiteralCompareConfig];
|
||||
"typescript/no-unnecessary-condition"?: DummyRule;
|
||||
"typescript/no-unnecessary-condition"?:
|
||||
| AllowWarnDeny
|
||||
| [AllowWarnDeny]
|
||||
| [AllowWarnDeny, NoUnnecessaryConditionConfig];
|
||||
"typescript/no-unnecessary-parameter-property-assignment"?: RuleNoConfig;
|
||||
"typescript/no-unnecessary-qualifier"?: RuleNoConfig;
|
||||
"typescript/no-unnecessary-template-expression"?: RuleNoConfig;
|
||||
@@ -4882,6 +4893,17 @@ export interface NoUnnecessaryBooleanLiteralCompareConfig {
|
||||
*/
|
||||
allowComparingNullableBooleansToTrue?: boolean;
|
||||
}
|
||||
export interface NoUnnecessaryConditionConfig {
|
||||
/**
|
||||
* Whether to allow constant loop conditions.
|
||||
* `true` is treated as `"always"`, `false` as `"never"`.
|
||||
*/
|
||||
allowConstantLoopConditions?: AllowConstantLoopConditions;
|
||||
/**
|
||||
* Whether to check type predicate functions.
|
||||
*/
|
||||
checkTypePredicates?: boolean;
|
||||
}
|
||||
export interface NoUnnecessaryTypeAssertionConfig {
|
||||
/**
|
||||
* Whether to check literal const assertions like `'foo' as const`.
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::rules::RuleEnum;
|
||||
/// These should return the DummyRule struct/schema instead of the actual rule struct/schema,
|
||||
/// until we verify that the rule's schema is valid and can be generated by schemars.
|
||||
#[cfg(feature = "ruledocs")]
|
||||
const NO_VERIFIED_VALID_SCHEMA: [&str; 45] = [
|
||||
const NO_VERIFIED_VALID_SCHEMA: [&str; 44] = [
|
||||
"eslint/func-name-matching",
|
||||
"eslint/no-restricted-globals",
|
||||
"eslint/no-restricted-imports",
|
||||
@@ -51,7 +51,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 45] = [
|
||||
"typescript/no-duplicate-type-constituents",
|
||||
"typescript/no-invalid-void-type",
|
||||
"typescript/no-misused-promises",
|
||||
"typescript/no-unnecessary-condition",
|
||||
"typescript/no-restricted-types",
|
||||
"unicorn/filename-case",
|
||||
"unicorn/import-style",
|
||||
|
||||
@@ -291,6 +291,26 @@
|
||||
"all"
|
||||
]
|
||||
},
|
||||
"AllowConstantLoopConditions": {
|
||||
"description": "Represents the different ways `allowConstantLoopConditions` can be specified in JSON.\nCan be:\n- `true` or `false`\n- A string enum (`\"never\"`, `\"always\"`, `\"only-allowed-literals\"`)",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/AllowConstantLoopConditionsMode"
|
||||
}
|
||||
],
|
||||
"markdownDescription": "Represents the different ways `allowConstantLoopConditions` can be specified in JSON.\nCan be:\n- `true` or `false`\n- A string enum (`\"never\"`, `\"always\"`, `\"only-allowed-literals\"`)"
|
||||
},
|
||||
"AllowConstantLoopConditionsMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"never",
|
||||
"always",
|
||||
"only-allowed-literals"
|
||||
]
|
||||
},
|
||||
"AllowKind": {
|
||||
"description": "Kinds of functions that can be allowed to be empty.",
|
||||
"oneOf": [
|
||||
@@ -6585,7 +6605,24 @@
|
||||
]
|
||||
},
|
||||
"typescript/no-unnecessary-condition": {
|
||||
"$ref": "#/definitions/DummyRule"
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AllowWarnDeny"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"$ref": "#/definitions/AllowWarnDeny"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NoUnnecessaryConditionConfig"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
"minItems": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"typescript/no-unnecessary-parameter-property-assignment": {
|
||||
"$ref": "#/definitions/RuleNoConfig"
|
||||
@@ -12789,6 +12826,28 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"NoUnnecessaryConditionConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"allowConstantLoopConditions": {
|
||||
"description": "Whether to allow constant loop conditions.\n`true` is treated as `\"always\"`, `false` as `\"never\"`.",
|
||||
"default": "never",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AllowConstantLoopConditions"
|
||||
}
|
||||
],
|
||||
"markdownDescription": "Whether to allow constant loop conditions.\n`true` is treated as `\"always\"`, `false` as `\"never\"`."
|
||||
},
|
||||
"checkTypePredicates": {
|
||||
"description": "Whether to check type predicate functions.",
|
||||
"default": false,
|
||||
"type": "boolean",
|
||||
"markdownDescription": "Whether to check type predicate functions."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"NoUnnecessaryTypeAssertionConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -295,6 +295,26 @@ expression: json
|
||||
"all"
|
||||
]
|
||||
},
|
||||
"AllowConstantLoopConditions": {
|
||||
"description": "Represents the different ways `allowConstantLoopConditions` can be specified in JSON.\nCan be:\n- `true` or `false`\n- A string enum (`\"never\"`, `\"always\"`, `\"only-allowed-literals\"`)",
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/AllowConstantLoopConditionsMode"
|
||||
}
|
||||
],
|
||||
"markdownDescription": "Represents the different ways `allowConstantLoopConditions` can be specified in JSON.\nCan be:\n- `true` or `false`\n- A string enum (`\"never\"`, `\"always\"`, `\"only-allowed-literals\"`)"
|
||||
},
|
||||
"AllowConstantLoopConditionsMode": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"never",
|
||||
"always",
|
||||
"only-allowed-literals"
|
||||
]
|
||||
},
|
||||
"AllowKind": {
|
||||
"description": "Kinds of functions that can be allowed to be empty.",
|
||||
"oneOf": [
|
||||
@@ -6589,7 +6609,24 @@ expression: json
|
||||
]
|
||||
},
|
||||
"typescript/no-unnecessary-condition": {
|
||||
"$ref": "#/definitions/DummyRule"
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AllowWarnDeny"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": [
|
||||
{
|
||||
"$ref": "#/definitions/AllowWarnDeny"
|
||||
},
|
||||
{
|
||||
"$ref": "#/definitions/NoUnnecessaryConditionConfig"
|
||||
}
|
||||
],
|
||||
"maxItems": 2,
|
||||
"minItems": 1
|
||||
}
|
||||
]
|
||||
},
|
||||
"typescript/no-unnecessary-parameter-property-assignment": {
|
||||
"$ref": "#/definitions/RuleNoConfig"
|
||||
@@ -12793,6 +12830,28 @@ expression: json
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"NoUnnecessaryConditionConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"allowConstantLoopConditions": {
|
||||
"description": "Whether to allow constant loop conditions.\n`true` is treated as `\"always\"`, `false` as `\"never\"`.",
|
||||
"default": "never",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/AllowConstantLoopConditions"
|
||||
}
|
||||
],
|
||||
"markdownDescription": "Whether to allow constant loop conditions.\n`true` is treated as `\"always\"`, `false` as `\"never\"`."
|
||||
},
|
||||
"checkTypePredicates": {
|
||||
"description": "Whether to check type predicate functions.",
|
||||
"default": false,
|
||||
"type": "boolean",
|
||||
"markdownDescription": "Whether to check type predicate functions."
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"NoUnnecessaryTypeAssertionConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Reference in new issue
Block a user