Skip to content

Commit 612e8fd

Browse files
committed
perf(linter): move root scope check into match arms in import/no-webpack-loader-syntax
1 parent 1dced5d commit 612e8fd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,8 @@ impl RuleRunner for crate::rules::import::no_unassigned_import::NoUnassignedImpo
11751175
}
11761176

11771177
impl RuleRunner for crate::rules::import::no_webpack_loader_syntax::NoWebpackLoaderSyntax {
1178-
const NODE_TYPES: Option<&AstTypesBitset> = None;
1178+
const NODE_TYPES: Option<&AstTypesBitset> =
1179+
Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::ImportDeclaration]));
11791180
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
11801181
}
11811182

crates/oxc_linter/src/rules/import/no_webpack_loader_syntax.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ declare_oxc_lint!(
5454

5555
impl Rule for NoWebpackLoaderSyntax {
5656
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
57-
// not in top level
58-
if node.scope_id() != ctx.scoping().root_scope_id() {
59-
return;
60-
}
61-
6257
match node.kind() {
6358
AstKind::CallExpression(call_expr) => {
6459
if let Expression::Identifier(identifier) = &call_expr.callee {
@@ -74,6 +69,11 @@ impl Rule for NoWebpackLoaderSyntax {
7469
return;
7570
};
7671

72+
// not in top level
73+
if node.scope_id() != ctx.scoping().root_scope_id() {
74+
return;
75+
}
76+
7777
if ident.value.contains('!') {
7878
ctx.diagnostic(no_named_as_default_diagnostic(
7979
ident.value.as_str(),
@@ -83,6 +83,11 @@ impl Rule for NoWebpackLoaderSyntax {
8383
}
8484
}
8585
AstKind::ImportDeclaration(import_decl) => {
86+
// not in top level
87+
if node.scope_id() != ctx.scoping().root_scope_id() {
88+
return;
89+
}
90+
8691
if import_decl.source.value.contains('!') {
8792
ctx.diagnostic(no_named_as_default_diagnostic(
8893
&import_decl.source.value,

0 commit comments

Comments
 (0)