From 2eb984ab052d338caa1408d3e6d5301e24159d6f Mon Sep 17 00:00:00 2001 From: camchenry <1514176+camchenry@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:54:25 +0000 Subject: [PATCH] refactor(linter): add missing `should_run` implementations (#6666) Added some `should_run` implementations that probably should exist but didn't previously. --- crates/oxc_linter/src/rules/eslint/no_unused_labels.rs | 7 ++++--- .../oxc_linter/src/rules/jest/no_untyped_mock_factory.rs | 8 ++++---- crates/oxc_linter/src/rules/typescript/no_namespace.rs | 7 +++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs b/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs index 63c953a479e5a..140d7fa04ca7e 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_labels.rs @@ -39,9 +39,6 @@ declare_oxc_lint!( impl Rule for NoUnusedLabels { fn run_once(&self, ctx: &LintContext) { - if ctx.file_path().extension().is_some_and(|ext| ext == "svelte") { - return; - } for id in ctx.semantic().unused_labels() { let node = ctx.semantic().nodes().get_node(*id); let AstKind::LabeledStatement(stmt) = node.kind() else { @@ -53,6 +50,10 @@ impl Rule for NoUnusedLabels { ); } } + + fn should_run(&self, ctx: &crate::context::ContextHost) -> bool { + ctx.file_path().extension().is_some_and(|ext| ext != "svelte") + } } #[test] diff --git a/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs b/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs index 0d1b5be2bd669..50b414ecb54c7 100644 --- a/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs +++ b/crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs @@ -93,14 +93,14 @@ declare_oxc_lint!( impl Rule for NoUntypedMockFactory { fn run_once(&self, ctx: &LintContext<'_>) { - if !ctx.source_type().is_typescript() { - return; - } - for possible_jest_node in &collect_possible_jest_call_node(ctx) { Self::run(possible_jest_node, ctx); } } + + fn should_run(&self, ctx: &crate::context::ContextHost) -> bool { + ctx.source_type().is_typescript() + } } impl NoUntypedMockFactory { diff --git a/crates/oxc_linter/src/rules/typescript/no_namespace.rs b/crates/oxc_linter/src/rules/typescript/no_namespace.rs index 3935d3839df2d..74e4c86357d3c 100644 --- a/crates/oxc_linter/src/rules/typescript/no_namespace.rs +++ b/crates/oxc_linter/src/rules/typescript/no_namespace.rs @@ -83,10 +83,6 @@ impl Rule for NoNamespace { return; } - if self.allow_definition_files && ctx.source_type().is_typescript_definition() { - return; - } - let declaration_code = declaration.span.source_text(ctx.source_text()); let span = match declaration.kind { @@ -104,6 +100,9 @@ impl Rule for NoNamespace { } fn should_run(&self, ctx: &ContextHost) -> bool { + if self.allow_definition_files && ctx.source_type().is_typescript_definition() { + return false; + } ctx.source_type().is_typescript() } }