diff --git a/apps/oxlint/fixtures/tsgolint_rule_options/.oxlintrc.json b/apps/oxlint/fixtures/tsgolint_rule_options/.oxlintrc.json index 08bca54e5f5fc..3de532dc9b41f 100644 --- a/apps/oxlint/fixtures/tsgolint_rule_options/.oxlintrc.json +++ b/apps/oxlint/fixtures/tsgolint_rule_options/.oxlintrc.json @@ -14,6 +14,14 @@ { "ignoredTypeNames": ["Error", "RegExp", "URL", "URLSearchParams", "CustomStringifiable"] } + ], + "typescript/no-deprecated": [ + "error", + { + "allow": [ + { "from": "file", "name": "allowedDeprecated" } + ] + } ] } } diff --git a/apps/oxlint/fixtures/tsgolint_rule_options/test.ts b/apps/oxlint/fixtures/tsgolint_rule_options/test.ts index 97245c1515ef8..23f61b8b4b544 100644 --- a/apps/oxlint/fixtures/tsgolint_rule_options/test.ts +++ b/apps/oxlint/fixtures/tsgolint_rule_options/test.ts @@ -22,4 +22,17 @@ declare class CustomStringifiable { declare const custom: CustomStringifiable; const customStr = custom.toString(); +// Test no-deprecated with allow option +/** @deprecated Use newFunction instead */ +function allowedDeprecated(): void {} + +/** @deprecated Use anotherNewFunction instead */ +function notAllowedDeprecated(): void {} + +// This should NOT error because allowedDeprecated is in the allow list +allowedDeprecated(); + +// This SHOULD error because notAllowedDeprecated is NOT in the allow list +notAllowedDeprecated(); + export { result, customStr }; diff --git a/apps/oxlint/src/snapshots/fixtures__tsgolint_rule_options_--type-aware@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__tsgolint_rule_options_--type-aware@oxlint.snap index 7b8bb7d75b8ad..1607af1a0b378 100644 --- a/apps/oxlint/src/snapshots/fixtures__tsgolint_rule_options_--type-aware@oxlint.snap +++ b/apps/oxlint/src/snapshots/fixtures__tsgolint_rule_options_--type-aware@oxlint.snap @@ -5,8 +5,17 @@ source: apps/oxlint/src/tester.rs arguments: --type-aware working directory: fixtures/tsgolint_rule_options ---------- -Found 0 warnings and 0 errors. + + x typescript-eslint(no-deprecated): `notAllowedDeprecated` is deprecated. Use anotherNewFunction instead + ,-[test.ts:36:1] + 35 | // This SHOULD error because notAllowedDeprecated is NOT in the allow list + 36 | notAllowedDeprecated(); + : ^^^^^^^^^^^^^^^^^^^^ + 37 | + `---- + +Found 0 warnings and 1 error. Finished in ms on 1 file using 1 threads. ---------- -CLI result: LintSucceeded +CLI result: LintFoundErrors ---------- diff --git a/crates/oxc_linter/src/rules/typescript/no_deprecated.rs b/crates/oxc_linter/src/rules/typescript/no_deprecated.rs index dc104c38c4baf..605aac8d065c5 100644 --- a/crates/oxc_linter/src/rules/typescript/no_deprecated.rs +++ b/crates/oxc_linter/src/rules/typescript/no_deprecated.rs @@ -1,9 +1,22 @@ use oxc_macros::declare_oxc_lint; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; -use crate::rule::Rule; +use crate::{ + rule::{DefaultRuleConfig, Rule}, + utils::TypeOrValueSpecifier, +}; -#[derive(Debug, Default, Clone)] -pub struct NoDeprecated; +#[derive(Debug, Default, Clone, Deserialize)] +pub struct NoDeprecated(Box); + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)] +#[serde(rename_all = "camelCase", default)] +pub struct NoDeprecatedConfig { + /// An array of type or value specifiers that are allowed to be used even if deprecated. + /// Use this to allow specific deprecated APIs that you intentionally want to continue using. + pub allow: Vec, +} declare_oxc_lint!( /// ### What it does @@ -48,7 +61,18 @@ declare_oxc_lint!( /// ``` NoDeprecated(tsgolint), typescript, - pedantic + pedantic, + config = NoDeprecatedConfig, ); -impl Rule for NoDeprecated {} +impl Rule for NoDeprecated { + fn from_configuration(value: serde_json::Value) -> Self { + serde_json::from_value::>(value) + .unwrap_or_default() + .into_inner() + } + + fn to_configuration(&self) -> Option> { + Some(serde_json::to_value(&*self.0)) + } +}