Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ impl Rule for NoUnsafeOptionalChaining {
_ => {}
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::ChainExpression)
}
}

#[derive(Clone, Copy)]
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_unused_labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl Rule for NoUnusedLabels {
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.file_path().extension().is_some_and(|ext| ext != "svelte")
ctx.semantic().nodes().contains(oxc_ast::AstType::LabeledStatement)
&& ctx.file_path().extension().is_some_and(|ext| ext != "svelte")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ impl Rule for NoUnusedPrivateClassMembers {
}
});
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic()
.nodes()
.contains_all(&[oxc_ast::AstType::Class, oxc_ast::AstType::PrivateIdentifier])
}
}

fn is_read(current_node_id: NodeId, nodes: &AstNodes) -> bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ impl Rule for NoUselessBackreference {
}
});
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains_any(&[
oxc_ast::AstType::RegExpLiteral,
oxc_ast::AstType::NewExpression,
oxc_ast::AstType::CallExpression,
])
}
}

enum Problem {
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_useless_catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ impl Rule for NoUselessCatch {
}
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic()
.nodes()
.contains_all(&[oxc_ast::AstType::TryStatement, oxc_ast::AstType::CatchClause])
}
}

#[test]
Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_useless_escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ impl Rule for NoUselessEscape {

Self(Box::new(NoUselessEscapeConfig { allow_regex_characters }))
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains_any(&[
oxc_ast::AstType::RegExpLiteral,
oxc_ast::AstType::StringLiteral,
oxc_ast::AstType::TemplateLiteral,
])
}
}

fn is_within_jsx_attribute(id: NodeId, ctx: &LintContext) -> bool {
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_useless_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ impl Rule for NoUselessRename {
_ => {}
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains_any(&[
oxc_ast::AstType::ObjectPattern,
oxc_ast::AstType::AssignmentTarget,
oxc_ast::AstType::ImportSpecifier,
oxc_ast::AstType::ExportNamedDeclaration,
])
}
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_with.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ impl Rule for NoWith {
ctx.diagnostic(no_with_diagnostic(Span::sized(with_statement.span.start, 4)));
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::WithStatement)
}
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/eslint/require_yield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ impl Rule for RequireYield {
}
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::Function)
}
}

#[test]
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/rules/eslint/use_isnan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ impl Rule for UseIsnan {

Self { enforce_for_switch_case, enforce_for_index_of }
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains_any(&[
oxc_ast::AstType::BinaryExpression,
oxc_ast::AstType::SwitchCase,
oxc_ast::AstType::SwitchStatement,
oxc_ast::AstType::CallExpression,
])
}
}

fn is_nan_identifier<'a>(expr: &'a Expression<'a>) -> bool {
Expand Down
6 changes: 6 additions & 0 deletions crates/oxc_linter/src/rules/eslint/valid_typeof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ impl Rule for ValidTypeof {

Self { require_string_literals }
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic()
.nodes()
.contains_all(&[oxc_ast::AstType::UnaryExpression, oxc_ast::AstType::BinaryExpression])
}
}

const VALID_TYPES: [&str; 8] =
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_linter/src/rules/import/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ impl Rule for Default {
}
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains_any(&[
oxc_ast::AstType::ImportDefaultSpecifier,
oxc_ast::AstType::ExportDefaultDeclaration,
])
}
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/import/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ impl Rule for Namespace {
});
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::ImportDeclaration)
}
}

/// If the name is a namespace object in imported module, return the module request name.
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/expect_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ impl Rule for ExpectExpect {
) {
run(self, jest_node, ctx);
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

fn run<'a>(
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/no_conditional_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ impl Rule for NoConditionalExpect {
}
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

fn check_parents<'a>(
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/no_disabled_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ impl Rule for NoDisabledTests {
) {
run(jest_node, ctx);
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>) {
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/rules/jest/no_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ impl Rule for NoExport {
ctx.diagnostic(no_export_diagnostic(span));
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains_any(&[
oxc_ast::AstType::ExportNamedDeclaration,
oxc_ast::AstType::ExportDefaultDeclaration,
oxc_ast::AstType::ExportAllDeclaration,
oxc_ast::AstType::ExportSpecifier,
])
}
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/no_focused_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl Rule for NoFocusedTests {
) {
run(jest_node, ctx);
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>) {
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/no_standalone_expect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl Rule for NoStandaloneExpect {
self.run(possible_jest_node, &id_nodes_mapping, ctx);
}
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

impl NoStandaloneExpect {
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/require_to_throw_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ impl Rule for RequireToThrowMessage {
) {
Self::run(jest_node, ctx);
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

impl RequireToThrowMessage {
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/valid_describe_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ impl Rule for ValidDescribeCallback {
) {
run(jest_node, ctx);
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

fn run<'a>(possible_jest_node: &PossibleJestNode<'a, '_>, ctx: &LintContext<'a>) {
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/valid_expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ impl Rule for ValidExpect {
) {
self.run(jest_node, ctx);
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

impl ValidExpect {
Expand Down
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/jest/valid_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl Rule for ValidTitle {
) {
self.run(jest_node, ctx);
}

fn should_run(&self, ctx: &crate::context::ContextHost) -> bool {
ctx.semantic().nodes().contains(oxc_ast::AstType::CallExpression)
}
}

impl ValidTitle {
Expand Down
Loading