feat(linter): add schema for typescript/triple-slash-reference (#23300)

Little review please because of the enum removal  🙇
#23301 has a question too.
This commit is contained in:
Sysix committed 2026-06-11 21:29:40 +00:00
1 parent 6619ceeffa
commit 03060f5f06
5 files changed
+225 -17

No files matched your search

+17 -1
View File
@@ -229,6 +229,8 @@ export type NameSpecifier = string | string[];
export type LibFrom = "lib";
export type PackageFrom = "package";
export type ReturnAwaitOption = "in-try-catch" | "always" | "error-handling-correctness-only" | "never";
export type PathOption = "always" | "never";
export type TypesOption = "always" | "never" | "prefer-import";
export type BomOptionType = "always" | "never";
export type NonZero = "greater-than" | "not-equal";
export type NoInstanceofBuiltinsStrategy = "strict" | "loose";
@@ -1389,7 +1391,7 @@ export interface DummyRuleMap {
| AllowWarnDeny
| [AllowWarnDeny]
| [AllowWarnDeny, SwitchExhaustivenessCheckConfig];
"typescript/triple-slash-reference"?: DummyRule;
"typescript/triple-slash-reference"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, TripleSlashReferenceConfig];
"typescript/unbound-method"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, UnboundMethodConfig];
"typescript/unified-signatures"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, UnifiedSignaturesOptions];
"typescript/use-unknown-in-catch-callback-variable"?: RuleNoConfig;
@@ -5142,6 +5144,20 @@ export interface SwitchExhaustivenessCheckConfig {
*/
requireDefaultForNonUnion?: boolean;
}
export interface TripleSlashReferenceConfig {
/**
* What to enforce for `/// <reference lib="..." />` references.
*/
lib?: AlwaysNever;
/**
* What to enforce for `/// <reference path="..." />` references.
*/
path?: PathOption;
/**
* What to enforce for `/// <reference types="..." />` references.
*/
types?: TypesOption;
}
export interface UnboundMethodConfig {
/**
* Whether to ignore unbound methods that are static.
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
use crate::{
context::{ContextHost, LintContext},
rule::{DefaultRuleConfig, Rule},
utils::AlwaysNever,
};
fn triple_slash_reference_diagnostic(ref_kind: &str, span: Span) -> OxcDiagnostic {
@@ -24,23 +25,13 @@ pub struct TripleSlashReference(Box<TripleSlashReferenceConfig>);
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct TripleSlashReferenceConfig {
/// What to enforce for `/// <reference lib="..." />` references.
lib: LibOption,
lib: AlwaysNever,
/// What to enforce for `/// <reference path="..." />` references.
path: PathOption,
/// What to enforce for `/// <reference types="..." />` references.
types: TypesOption,
}
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum LibOption {
/// Allow triple-slash `lib` references.
#[default]
Always,
/// Disallow triple-slash `lib` references.
Never,
}
#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum PathOption {
@@ -119,7 +110,7 @@ impl Rule for TripleSlashReference {
if let Some((group1, group2)) = get_attr_key_and_value(raw) {
if (group1 == "types" && self.types == TypesOption::Never)
|| (group1 == "path" && self.path == PathOption::Never)
|| (group1 == "lib" && self.lib == LibOption::Never)
|| (group1 == "lib" && self.lib == AlwaysNever::Never)
{
ctx.diagnostic(triple_slash_reference_diagnostic(&group2, comment.span));
}
+1 -2
View File
@@ -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; 49] = [
const NO_VERIFIED_VALID_SCHEMA: [&str; 48] = [
"eslint/func-name-matching",
"eslint/no-restricted-globals",
"eslint/no-restricted-imports",
@@ -56,7 +56,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 49] = [
"typescript/parameter-properties",
"typescript/prefer-nullish-coalescing",
"typescript/prefer-string-starts-ends-with",
"typescript/triple-slash-reference",
"unicorn/filename-case",
"unicorn/import-style",
"unicorn/numeric-separators-style",
+102 -1
View File
@@ -6999,7 +6999,24 @@
]
},
"typescript/triple-slash-reference": {
"$ref": "#/definitions/DummyRule"
"anyOf": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"type": "array",
"items": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"$ref": "#/definitions/TripleSlashReferenceConfig"
}
],
"maxItems": 2,
"minItems": 1
}
]
},
"typescript/unbound-method": {
"anyOf": [
@@ -13729,6 +13746,26 @@
},
"additionalProperties": false
},
"PathOption": {
"oneOf": [
{
"description": "Allow triple-slash `path` references.",
"type": "string",
"enum": [
"always"
],
"markdownDescription": "Allow triple-slash `path` references."
},
{
"description": "Disallow triple-slash `path` references.",
"type": "string",
"enum": [
"never"
],
"markdownDescription": "Disallow triple-slash `path` references."
}
]
},
"PreferArrowCallback": {
"$ref": "#/definitions/PreferArrowCallbackConfig"
},
@@ -15125,6 +15162,42 @@
},
"additionalProperties": false
},
"TripleSlashReferenceConfig": {
"type": "object",
"properties": {
"lib": {
"description": "What to enforce for `/// <reference lib=\"...\" />` references.",
"default": "always",
"allOf": [
{
"$ref": "#/definitions/AlwaysNever"
}
],
"markdownDescription": "What to enforce for `/// <reference lib=\"...\" />` references."
},
"path": {
"description": "What to enforce for `/// <reference path=\"...\" />` references.",
"default": "never",
"allOf": [
{
"$ref": "#/definitions/PathOption"
}
],
"markdownDescription": "What to enforce for `/// <reference path=\"...\" />` references."
},
"types": {
"description": "What to enforce for `/// <reference types=\"...\" />` references.",
"default": "prefer-import",
"allOf": [
{
"$ref": "#/definitions/TypesOption"
}
],
"markdownDescription": "What to enforce for `/// <reference types=\"...\" />` references."
}
},
"additionalProperties": false
},
"TypeOrValueSpecifier": {
"description": "Type or value specifier for matching specific declarations\n\nSupports four types of specifiers:\n\n1. **String specifier** (deprecated): Universal match by name\n```json\n\"Promise\"\n```\n\n2. **File specifier**: Match types/values declared in local files\n```json\n{ \"from\": \"file\", \"name\": \"MyType\" }\n{ \"from\": \"file\", \"name\": [\"Type1\", \"Type2\"] }\n{ \"from\": \"file\", \"name\": \"MyType\", \"path\": \"./types.ts\" }\n```\n\n3. **Lib specifier**: Match TypeScript built-in lib types\n```json\n{ \"from\": \"lib\", \"name\": \"Promise\" }\n{ \"from\": \"lib\", \"name\": [\"Promise\", \"PromiseLike\"] }\n```\n\n4. **Package specifier**: Match types/values from npm packages\n```json\n{ \"from\": \"package\", \"name\": \"Observable\", \"package\": \"rxjs\" }\n{ \"from\": \"package\", \"name\": [\"Observable\", \"Subject\"], \"package\": \"rxjs\" }\n```",
"anyOf": [
@@ -15163,6 +15236,34 @@
],
"markdownDescription": "Type or value specifier for matching specific declarations\n\nSupports four types of specifiers:\n\n1. **String specifier** (deprecated): Universal match by name\n```json\n\"Promise\"\n```\n\n2. **File specifier**: Match types/values declared in local files\n```json\n{ \"from\": \"file\", \"name\": \"MyType\" }\n{ \"from\": \"file\", \"name\": [\"Type1\", \"Type2\"] }\n{ \"from\": \"file\", \"name\": \"MyType\", \"path\": \"./types.ts\" }\n```\n\n3. **Lib specifier**: Match TypeScript built-in lib types\n```json\n{ \"from\": \"lib\", \"name\": \"Promise\" }\n{ \"from\": \"lib\", \"name\": [\"Promise\", \"PromiseLike\"] }\n```\n\n4. **Package specifier**: Match types/values from npm packages\n```json\n{ \"from\": \"package\", \"name\": \"Observable\", \"package\": \"rxjs\" }\n{ \"from\": \"package\", \"name\": [\"Observable\", \"Subject\"], \"package\": \"rxjs\" }\n```"
},
"TypesOption": {
"oneOf": [
{
"description": "Allow triple-slash `types` references.",
"type": "string",
"enum": [
"always"
],
"markdownDescription": "Allow triple-slash `types` references."
},
{
"description": "Disallow triple-slash `types` references.",
"type": "string",
"enum": [
"never"
],
"markdownDescription": "Disallow triple-slash `types` references."
},
{
"description": "Prefer ES module import declarations over triple-slash `types` references.\nThis option only reports when there is an existing `import` declaration for the same module.\n\nFor example, this would be reported as a lint violation with `prefer-import`:\n```ts\n/// <reference types=\"foo\" />\nimport { bar } from 'foo';\n```",
"type": "string",
"enum": [
"prefer-import"
],
"markdownDescription": "Prefer ES module import declarations over triple-slash `types` references.\nThis option only reports when there is an existing `import` declaration for the same module.\n\nFor example, this would be reported as a lint violation with `prefer-import`:\n```ts\n/// <reference types=\"foo\" />\nimport { bar } from 'foo';\n```"
}
]
},
"UnboundMethodConfig": {
"type": "object",
"properties": {
@@ -7003,7 +7003,24 @@ expression: json
]
},
"typescript/triple-slash-reference": {
"$ref": "#/definitions/DummyRule"
"anyOf": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"type": "array",
"items": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"$ref": "#/definitions/TripleSlashReferenceConfig"
}
],
"maxItems": 2,
"minItems": 1
}
]
},
"typescript/unbound-method": {
"anyOf": [
@@ -13733,6 +13750,26 @@ expression: json
},
"additionalProperties": false
},
"PathOption": {
"oneOf": [
{
"description": "Allow triple-slash `path` references.",
"type": "string",
"enum": [
"always"
],
"markdownDescription": "Allow triple-slash `path` references."
},
{
"description": "Disallow triple-slash `path` references.",
"type": "string",
"enum": [
"never"
],
"markdownDescription": "Disallow triple-slash `path` references."
}
]
},
"PreferArrowCallback": {
"$ref": "#/definitions/PreferArrowCallbackConfig"
},
@@ -15129,6 +15166,42 @@ expression: json
},
"additionalProperties": false
},
"TripleSlashReferenceConfig": {
"type": "object",
"properties": {
"lib": {
"description": "What to enforce for `/// <reference lib=\"...\" />` references.",
"default": "always",
"allOf": [
{
"$ref": "#/definitions/AlwaysNever"
}
],
"markdownDescription": "What to enforce for `/// <reference lib=\"...\" />` references."
},
"path": {
"description": "What to enforce for `/// <reference path=\"...\" />` references.",
"default": "never",
"allOf": [
{
"$ref": "#/definitions/PathOption"
}
],
"markdownDescription": "What to enforce for `/// <reference path=\"...\" />` references."
},
"types": {
"description": "What to enforce for `/// <reference types=\"...\" />` references.",
"default": "prefer-import",
"allOf": [
{
"$ref": "#/definitions/TypesOption"
}
],
"markdownDescription": "What to enforce for `/// <reference types=\"...\" />` references."
}
},
"additionalProperties": false
},
"TypeOrValueSpecifier": {
"description": "Type or value specifier for matching specific declarations\n\nSupports four types of specifiers:\n\n1. **String specifier** (deprecated): Universal match by name\n```json\n\"Promise\"\n```\n\n2. **File specifier**: Match types/values declared in local files\n```json\n{ \"from\": \"file\", \"name\": \"MyType\" }\n{ \"from\": \"file\", \"name\": [\"Type1\", \"Type2\"] }\n{ \"from\": \"file\", \"name\": \"MyType\", \"path\": \"./types.ts\" }\n```\n\n3. **Lib specifier**: Match TypeScript built-in lib types\n```json\n{ \"from\": \"lib\", \"name\": \"Promise\" }\n{ \"from\": \"lib\", \"name\": [\"Promise\", \"PromiseLike\"] }\n```\n\n4. **Package specifier**: Match types/values from npm packages\n```json\n{ \"from\": \"package\", \"name\": \"Observable\", \"package\": \"rxjs\" }\n{ \"from\": \"package\", \"name\": [\"Observable\", \"Subject\"], \"package\": \"rxjs\" }\n```",
"anyOf": [
@@ -15167,6 +15240,34 @@ expression: json
],
"markdownDescription": "Type or value specifier for matching specific declarations\n\nSupports four types of specifiers:\n\n1. **String specifier** (deprecated): Universal match by name\n```json\n\"Promise\"\n```\n\n2. **File specifier**: Match types/values declared in local files\n```json\n{ \"from\": \"file\", \"name\": \"MyType\" }\n{ \"from\": \"file\", \"name\": [\"Type1\", \"Type2\"] }\n{ \"from\": \"file\", \"name\": \"MyType\", \"path\": \"./types.ts\" }\n```\n\n3. **Lib specifier**: Match TypeScript built-in lib types\n```json\n{ \"from\": \"lib\", \"name\": \"Promise\" }\n{ \"from\": \"lib\", \"name\": [\"Promise\", \"PromiseLike\"] }\n```\n\n4. **Package specifier**: Match types/values from npm packages\n```json\n{ \"from\": \"package\", \"name\": \"Observable\", \"package\": \"rxjs\" }\n{ \"from\": \"package\", \"name\": [\"Observable\", \"Subject\"], \"package\": \"rxjs\" }\n```"
},
"TypesOption": {
"oneOf": [
{
"description": "Allow triple-slash `types` references.",
"type": "string",
"enum": [
"always"
],
"markdownDescription": "Allow triple-slash `types` references."
},
{
"description": "Disallow triple-slash `types` references.",
"type": "string",
"enum": [
"never"
],
"markdownDescription": "Disallow triple-slash `types` references."
},
{
"description": "Prefer ES module import declarations over triple-slash `types` references.\nThis option only reports when there is an existing `import` declaration for the same module.\n\nFor example, this would be reported as a lint violation with `prefer-import`:\n```ts\n/// <reference types=\"foo\" />\nimport { bar } from 'foo';\n```",
"type": "string",
"enum": [
"prefer-import"
],
"markdownDescription": "Prefer ES module import declarations over triple-slash `types` references.\nThis option only reports when there is an existing `import` declaration for the same module.\n\nFor example, this would be reported as a lint violation with `prefer-import`:\n```ts\n/// <reference types=\"foo\" />\nimport { bar } from 'foo';\n```"
}
]
},
"UnboundMethodConfig": {
"type": "object",
"properties": {