Skip to content

Commit d353858

Browse files
committed
feat(linter): add schema for typescript/prefer-string-starts-ends-with (#23301)
Should we deprecate/remove the unicorn version of it? https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-string-starts-ends-with We marked some rules as unsupported because they should use the type-aware version. 🤔
1 parent 03060f5 commit d353858

4 files changed

Lines changed: 120 additions & 5 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
@@ -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 AllowSingleElementEquality = "always" | "never";
231232
export type ReturnAwaitOption = "in-try-catch" | "always" | "error-handling-correctness-only" | "never";
232233
export type PathOption = "always" | "never";
233234
export type TypesOption = "always" | "never" | "prefer-import";
@@ -1367,7 +1368,10 @@ export interface DummyRuleMap {
13671368
"typescript/prefer-reduce-type-parameter"?: RuleNoConfig;
13681369
"typescript/prefer-regexp-exec"?: RuleNoConfig;
13691370
"typescript/prefer-return-this-type"?: RuleNoConfig;
1370-
"typescript/prefer-string-starts-ends-with"?: DummyRule;
1371+
"typescript/prefer-string-starts-ends-with"?:
1372+
| AllowWarnDeny
1373+
| [AllowWarnDeny]
1374+
| [AllowWarnDeny, PreferStringStartsEndsWithConfig];
13711375
"typescript/prefer-ts-expect-error"?: RuleNoConfig;
13721376
"typescript/promise-function-async"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, PromiseFunctionAsyncConfig];
13731377
"typescript/related-getter-setter-pairs"?: RuleNoConfig;
@@ -4986,6 +4990,12 @@ export interface PreferReadonlyParameterTypesConfig {
49864990
*/
49874991
treatMethodsAsReadonly?: boolean;
49884992
}
4993+
export interface PreferStringStartsEndsWithConfig {
4994+
/**
4995+
* Whether equality checks against the first/last character are allowed.
4996+
*/
4997+
allowSingleElementEquality?: AllowSingleElementEquality;
4998+
}
49894999
export interface PromiseFunctionAsyncConfig {
49905000
/**
49915001
* Whether to allow functions returning `any` type without requiring `async`.

‎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; 48] = [
16+
const NO_VERIFIED_VALID_SCHEMA: [&str; 47] = [
1717
"eslint/func-name-matching",
1818
"eslint/no-restricted-globals",
1919
"eslint/no-restricted-imports",
@@ -55,7 +55,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 48] = [
5555
"typescript/no-restricted-types",
5656
"typescript/parameter-properties",
5757
"typescript/prefer-nullish-coalescing",
58-
"typescript/prefer-string-starts-ends-with",
5958
"unicorn/filename-case",
6059
"unicorn/import-style",
6160
"unicorn/numeric-separators-style",

‎npm/oxlint/configuration_schema.json‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,26 @@
409409
],
410410
"markdownDescription": "Kinds of functions that can be allowed to be empty."
411411
},
412+
"AllowSingleElementEquality": {
413+
"oneOf": [
414+
{
415+
"description": "Always allow equality checks against the first or last character.",
416+
"type": "string",
417+
"enum": [
418+
"always"
419+
],
420+
"markdownDescription": "Always allow equality checks against the first or last character."
421+
},
422+
{
423+
"description": "Never allow equality checks against the first or last character.",
424+
"type": "string",
425+
"enum": [
426+
"never"
427+
],
428+
"markdownDescription": "Never allow equality checks against the first or last character."
429+
}
430+
]
431+
},
412432
"AllowWarnDeny": {
413433
"oneOf": [
414434
{
@@ -6827,7 +6847,24 @@
68276847
"$ref": "#/definitions/RuleNoConfig"
68286848
},
68296849
"typescript/prefer-string-starts-ends-with": {
6830-
"$ref": "#/definitions/DummyRule"
6850+
"anyOf": [
6851+
{
6852+
"$ref": "#/definitions/AllowWarnDeny"
6853+
},
6854+
{
6855+
"type": "array",
6856+
"items": [
6857+
{
6858+
"$ref": "#/definitions/AllowWarnDeny"
6859+
},
6860+
{
6861+
"$ref": "#/definitions/PreferStringStartsEndsWithConfig"
6862+
}
6863+
],
6864+
"maxItems": 2,
6865+
"minItems": 1
6866+
}
6867+
]
68316868
},
68326869
"typescript/prefer-ts-expect-error": {
68336870
"$ref": "#/definitions/RuleNoConfig"
@@ -14168,6 +14205,22 @@
1416814205
},
1416914206
"additionalProperties": false
1417014207
},
14208+
"PreferStringStartsEndsWithConfig": {
14209+
"type": "object",
14210+
"properties": {
14211+
"allowSingleElementEquality": {
14212+
"description": "Whether equality checks against the first/last character are allowed.",
14213+
"default": "never",
14214+
"allOf": [
14215+
{
14216+
"$ref": "#/definitions/AllowSingleElementEquality"
14217+
}
14218+
],
14219+
"markdownDescription": "Whether equality checks against the first/last character are allowed."
14220+
}
14221+
},
14222+
"additionalProperties": false
14223+
},
1417114224
"PreferStructuredCloneConfig": {
1417214225
"type": "object",
1417314226
"properties": {

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,26 @@ expression: json
413413
],
414414
"markdownDescription": "Kinds of functions that can be allowed to be empty."
415415
},
416+
"AllowSingleElementEquality": {
417+
"oneOf": [
418+
{
419+
"description": "Always allow equality checks against the first or last character.",
420+
"type": "string",
421+
"enum": [
422+
"always"
423+
],
424+
"markdownDescription": "Always allow equality checks against the first or last character."
425+
},
426+
{
427+
"description": "Never allow equality checks against the first or last character.",
428+
"type": "string",
429+
"enum": [
430+
"never"
431+
],
432+
"markdownDescription": "Never allow equality checks against the first or last character."
433+
}
434+
]
435+
},
416436
"AllowWarnDeny": {
417437
"oneOf": [
418438
{
@@ -6831,7 +6851,24 @@ expression: json
68316851
"$ref": "#/definitions/RuleNoConfig"
68326852
},
68336853
"typescript/prefer-string-starts-ends-with": {
6834-
"$ref": "#/definitions/DummyRule"
6854+
"anyOf": [
6855+
{
6856+
"$ref": "#/definitions/AllowWarnDeny"
6857+
},
6858+
{
6859+
"type": "array",
6860+
"items": [
6861+
{
6862+
"$ref": "#/definitions/AllowWarnDeny"
6863+
},
6864+
{
6865+
"$ref": "#/definitions/PreferStringStartsEndsWithConfig"
6866+
}
6867+
],
6868+
"maxItems": 2,
6869+
"minItems": 1
6870+
}
6871+
]
68356872
},
68366873
"typescript/prefer-ts-expect-error": {
68376874
"$ref": "#/definitions/RuleNoConfig"
@@ -14172,6 +14209,22 @@ expression: json
1417214209
},
1417314210
"additionalProperties": false
1417414211
},
14212+
"PreferStringStartsEndsWithConfig": {
14213+
"type": "object",
14214+
"properties": {
14215+
"allowSingleElementEquality": {
14216+
"description": "Whether equality checks against the first/last character are allowed.",
14217+
"default": "never",
14218+
"allOf": [
14219+
{
14220+
"$ref": "#/definitions/AllowSingleElementEquality"
14221+
}
14222+
],
14223+
"markdownDescription": "Whether equality checks against the first/last character are allowed."
14224+
}
14225+
},
14226+
"additionalProperties": false
14227+
},
1417514228
"PreferStructuredCloneConfig": {
1417614229
"type": "object",
1417714230
"properties": {

0 commit comments

Comments
 (0)