From d8d2ec625729582b58633e0e17e39059a248dd81 Mon Sep 17 00:00:00 2001 From: "Alexander S." Date: Sat, 28 Dec 2024 18:03:11 +0100 Subject: [PATCH] perf(linter): run rules which require typescript syntax only when source type is actually typescript (#8166) --- .../src/rules/typescript/consistent_generic_constructors.rs | 4 ++++ .../oxc_linter/src/rules/typescript/no_empty_object_type.rs | 4 ++++ crates/oxc_linter/src/rules/typescript/no_misused_new.rs | 4 ++++ .../src/rules/typescript/no_unsafe_function_type.rs | 4 ++++ .../src/rules/typescript/no_wrapper_object_types.rs | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs b/crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs index 8ee66e9916c97..bcb86b4f21156 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_generic_constructors.rs @@ -118,6 +118,10 @@ impl Rule for ConsistentGenericConstructors { .unwrap_or_default(), })) } + + fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool { + ctx.source_type().is_typescript() + } } impl ConsistentGenericConstructors { diff --git a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs index 12c1bc5f91fe6..8e479d1d8e83f 100644 --- a/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs +++ b/crates/oxc_linter/src/rules/typescript/no_empty_object_type.rs @@ -140,6 +140,10 @@ impl Rule for NoEmptyObjectType { _ => {} } } + + fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool { + ctx.source_type().is_typescript() + } } fn check_interface_declaration( diff --git a/crates/oxc_linter/src/rules/typescript/no_misused_new.rs b/crates/oxc_linter/src/rules/typescript/no_misused_new.rs index acc5d646d2992..64e5c77c35b98 100644 --- a/crates/oxc_linter/src/rules/typescript/no_misused_new.rs +++ b/crates/oxc_linter/src/rules/typescript/no_misused_new.rs @@ -113,6 +113,10 @@ impl Rule for NoMisusedNew { _ => {} } } + + fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool { + ctx.source_type().is_typescript() + } } #[test] diff --git a/crates/oxc_linter/src/rules/typescript/no_unsafe_function_type.rs b/crates/oxc_linter/src/rules/typescript/no_unsafe_function_type.rs index 23ff43c4704f0..dd7fe7af08a3b 100644 --- a/crates/oxc_linter/src/rules/typescript/no_unsafe_function_type.rs +++ b/crates/oxc_linter/src/rules/typescript/no_unsafe_function_type.rs @@ -76,6 +76,10 @@ impl Rule for NoUnsafeFunctionType { _ => {} } } + + fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool { + ctx.source_type().is_typescript() + } } fn handle_function_type<'a>(identifier: &'a IdentifierReference<'a>, ctx: &LintContext<'a>) { diff --git a/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs b/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs index f8adc33f1f4b7..d320944f24c17 100644 --- a/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs +++ b/crates/oxc_linter/src/rules/typescript/no_wrapper_object_types.rs @@ -99,6 +99,10 @@ impl Rule for NoWrapperObjectTypes { } } } + + fn should_run(&self, ctx: &crate::rules::ContextHost) -> bool { + ctx.source_type().is_typescript() + } } #[test]