Skip to content

Commit 05b4dcf

Browse files
committed
feat(linter): add schema for eslint/prefer-const (#23081)
1 parent 5a06c4d commit 05b4dcf

4 files changed

Lines changed: 140 additions & 5 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export type CaughtErrorsJson = "all" | "none";
127127
export type NoUnusedVarsFixMode = "off" | "suggestion" | "fix" | "safe-fix";
128128
export type Location = "start" | "anywhere";
129129
export type ShorthandType = "always" | "methods" | "properties" | "consistent" | "consistent-as-needed" | "never";
130+
export type Destructuring = "any" | "all";
130131
/**
131132
* A forbidden prop, either as a plain prop name string or with options.
132133
*/
@@ -1068,7 +1069,7 @@ export interface DummyRuleMap {
10681069
"oxc/only-used-in-recursion"?: RuleNoConfig;
10691070
"oxc/uninvoked-array-callback"?: RuleNoConfig;
10701071
"prefer-arrow-callback"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, PreferArrowCallbackConfig];
1071-
"prefer-const"?: DummyRule;
1072+
"prefer-const"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, PreferConstConfig];
10721073
"prefer-destructuring"?: DummyRule;
10731074
"prefer-exponentiation-operator"?: RuleNoConfig;
10741075
"prefer-named-capture-group"?: RuleNoConfig;
@@ -3421,6 +3422,17 @@ export interface PreferArrowCallbackConfig {
34213422
allowNamedFunctions?: boolean;
34223423
allowUnboundThis?: boolean;
34233424
}
3425+
export interface PreferConstConfig {
3426+
/**
3427+
* Configures how destructuring assignments are handled.
3428+
*/
3429+
destructuring?: Destructuring;
3430+
/**
3431+
* If `true`, the rule will not report variables that are read before their initial assignment.
3432+
* This is mainly useful for preventing conflicts with the `typescript/no-use-before-define` rule.
3433+
*/
3434+
ignoreReadBeforeAssign?: boolean;
3435+
}
34243436
export interface PreferPromiseRejectErrors {
34253437
/**
34263438
* Whether to allow calls to `Promise.reject()` with no arguments.

crates/oxc_linter/src/utils/schemars.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ 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; 100] = [
16+
const NO_VERIFIED_VALID_SCHEMA: [&str; 99] = [
1717
"eslint/func-name-matching",
1818
"eslint/no-restricted-globals",
1919
"eslint/no-restricted-imports",
2020
"eslint/no-restricted-properties",
2121
"eslint/no-use-before-define",
2222
"eslint/prefer-destructuring",
23-
"eslint/prefer-const",
2423
"eslint/radix",
2524
"eslint/sort-vars",
2625
"import/extensions",

npm/oxlint/configuration_schema.json

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,26 @@
11941194
},
11951195
"additionalProperties": false
11961196
},
1197+
"Destructuring": {
1198+
"oneOf": [
1199+
{
1200+
"description": "Warn if any of the variables in a destructuring assignment should be `const`.",
1201+
"type": "string",
1202+
"enum": [
1203+
"any"
1204+
],
1205+
"markdownDescription": "Warn if any of the variables in a destructuring assignment should be `const`."
1206+
},
1207+
{
1208+
"description": "Only warn if all variables in a destructuring assignment should be `const`. Otherwise, ignore them.",
1209+
"type": "string",
1210+
"enum": [
1211+
"all"
1212+
],
1213+
"markdownDescription": "Only warn if all variables in a destructuring assignment should be `const`. Otherwise, ignore them."
1214+
}
1215+
]
1216+
},
11971217
"DisplayNameConfig": {
11981218
"type": "object",
11991219
"properties": {
@@ -4381,7 +4401,24 @@
43814401
]
43824402
},
43834403
"prefer-const": {
4384-
"$ref": "#/definitions/DummyRule"
4404+
"anyOf": [
4405+
{
4406+
"$ref": "#/definitions/AllowWarnDeny"
4407+
},
4408+
{
4409+
"type": "array",
4410+
"items": [
4411+
{
4412+
"$ref": "#/definitions/AllowWarnDeny"
4413+
},
4414+
{
4415+
"$ref": "#/definitions/PreferConst"
4416+
}
4417+
],
4418+
"maxItems": 2,
4419+
"minItems": 1
4420+
}
4421+
]
43854422
},
43864423
"prefer-destructuring": {
43874424
"$ref": "#/definitions/DummyRule"
@@ -12316,6 +12353,31 @@
1231612353
},
1231712354
"additionalProperties": false
1231812355
},
12356+
"PreferConst": {
12357+
"$ref": "#/definitions/PreferConstConfig"
12358+
},
12359+
"PreferConstConfig": {
12360+
"type": "object",
12361+
"properties": {
12362+
"destructuring": {
12363+
"description": "Configures how destructuring assignments are handled.",
12364+
"default": "any",
12365+
"allOf": [
12366+
{
12367+
"$ref": "#/definitions/Destructuring"
12368+
}
12369+
],
12370+
"markdownDescription": "Configures how destructuring assignments are handled."
12371+
},
12372+
"ignoreReadBeforeAssign": {
12373+
"description": "If `true`, the rule will not report variables that are read before their initial assignment.\nThis is mainly useful for preventing conflicts with the `typescript/no-use-before-define` rule.",
12374+
"default": false,
12375+
"type": "boolean",
12376+
"markdownDescription": "If `true`, the rule will not report variables that are read before their initial assignment.\nThis is mainly useful for preventing conflicts with the `typescript/no-use-before-define` rule."
12377+
}
12378+
},
12379+
"additionalProperties": false
12380+
},
1231912381
"PreferES6ClassOptionType": {
1232012382
"oneOf": [
1232112383
{

tasks/website_linter/src/snapshots/schema_json.snap

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,26 @@ expression: json
11981198
},
11991199
"additionalProperties": false
12001200
},
1201+
"Destructuring": {
1202+
"oneOf": [
1203+
{
1204+
"description": "Warn if any of the variables in a destructuring assignment should be `const`.",
1205+
"type": "string",
1206+
"enum": [
1207+
"any"
1208+
],
1209+
"markdownDescription": "Warn if any of the variables in a destructuring assignment should be `const`."
1210+
},
1211+
{
1212+
"description": "Only warn if all variables in a destructuring assignment should be `const`. Otherwise, ignore them.",
1213+
"type": "string",
1214+
"enum": [
1215+
"all"
1216+
],
1217+
"markdownDescription": "Only warn if all variables in a destructuring assignment should be `const`. Otherwise, ignore them."
1218+
}
1219+
]
1220+
},
12011221
"DisplayNameConfig": {
12021222
"type": "object",
12031223
"properties": {
@@ -4385,7 +4405,24 @@ expression: json
43854405
]
43864406
},
43874407
"prefer-const": {
4388-
"$ref": "#/definitions/DummyRule"
4408+
"anyOf": [
4409+
{
4410+
"$ref": "#/definitions/AllowWarnDeny"
4411+
},
4412+
{
4413+
"type": "array",
4414+
"items": [
4415+
{
4416+
"$ref": "#/definitions/AllowWarnDeny"
4417+
},
4418+
{
4419+
"$ref": "#/definitions/PreferConst"
4420+
}
4421+
],
4422+
"maxItems": 2,
4423+
"minItems": 1
4424+
}
4425+
]
43894426
},
43904427
"prefer-destructuring": {
43914428
"$ref": "#/definitions/DummyRule"
@@ -12320,6 +12357,31 @@ expression: json
1232012357
},
1232112358
"additionalProperties": false
1232212359
},
12360+
"PreferConst": {
12361+
"$ref": "#/definitions/PreferConstConfig"
12362+
},
12363+
"PreferConstConfig": {
12364+
"type": "object",
12365+
"properties": {
12366+
"destructuring": {
12367+
"description": "Configures how destructuring assignments are handled.",
12368+
"default": "any",
12369+
"allOf": [
12370+
{
12371+
"$ref": "#/definitions/Destructuring"
12372+
}
12373+
],
12374+
"markdownDescription": "Configures how destructuring assignments are handled."
12375+
},
12376+
"ignoreReadBeforeAssign": {
12377+
"description": "If `true`, the rule will not report variables that are read before their initial assignment.\nThis is mainly useful for preventing conflicts with the `typescript/no-use-before-define` rule.",
12378+
"default": false,
12379+
"type": "boolean",
12380+
"markdownDescription": "If `true`, the rule will not report variables that are read before their initial assignment.\nThis is mainly useful for preventing conflicts with the `typescript/no-use-before-define` rule."
12381+
}
12382+
},
12383+
"additionalProperties": false
12384+
},
1232312385
"PreferES6ClassOptionType": {
1232412386
"oneOf": [
1232512387
{

0 commit comments

Comments
 (0)