Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/oxlint/fixtures/tsgolint_rule_options/.oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
{
"ignoredTypeNames": ["Error", "RegExp", "URL", "URLSearchParams", "CustomStringifiable"]
}
],
"typescript/no-deprecated": [
"error",
{
"allow": [
{ "from": "file", "name": "allowedDeprecated" }
]
}
]
}
}
13 changes: 13 additions & 0 deletions apps/oxlint/fixtures/tsgolint_rule_options/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Original file line number Diff line number Diff line change
Expand Up @@ -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 <variable>ms on 1 file using 1 threads.
----------
CLI result: LintSucceeded
CLI result: LintFoundErrors
----------
34 changes: 29 additions & 5 deletions crates/oxc_linter/src/rules/typescript/no_deprecated.rs
Original file line number Diff line number Diff line change
@@ -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<NoDeprecatedConfig>);

#[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<TypeOrValueSpecifier>,
}

declare_oxc_lint!(
/// ### What it does
Expand Down Expand Up @@ -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::<DefaultRuleConfig<NoDeprecated>>(value)
.unwrap_or_default()
.into_inner()
}

fn to_configuration(&self) -> Option<Result<serde_json::Value, serde_json::Error>> {
Some(serde_json::to_value(&*self.0))
}
}
Loading