Skip to content

Commit

Permalink
refactor(linter): add missing should_run implementations (#6666)
Browse files Browse the repository at this point in the history
Added some `should_run` implementations that probably should exist but didn't previously.
  • Loading branch information
camchenry committed Oct 19, 2024
1 parent 34fe7c0 commit 2eb984a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
7 changes: 4 additions & 3 deletions crates/oxc_linter/src/rules/eslint/no_unused_labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_linter/src/rules/jest/no_untyped_mock_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions crates/oxc_linter/src/rules/typescript/no_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}
Expand Down

0 comments on commit 2eb984a

Please sign in to comment.