Skip to content

Commit 23e84b8

Browse files
fix review
1 parent aa1a5bb commit 23e84b8

File tree

1 file changed

+40
-46
lines changed

1 file changed

+40
-46
lines changed

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

+40-46
Original file line numberDiff line numberDiff line change
@@ -57,56 +57,50 @@ declare_oxc_lint!(
5757
);
5858

5959
impl Rule for NoMutableExports {
60-
fn run_once(&self, ctx: &LintContext) {
61-
for node in ctx.semantic().nodes() {
62-
match node.kind() {
63-
AstKind::ExportNamedDeclaration(export_name_decl) => {
64-
// e.g. "export let a = 4;"
65-
if let Some(declaration) = &export_name_decl.declaration {
66-
let Declaration::VariableDeclaration(decl) = declaration else {
67-
return;
68-
};
69-
if matches!(
70-
decl.kind,
71-
VariableDeclarationKind::Var | VariableDeclarationKind::Let
72-
) {
73-
ctx.diagnostic(no_mutable_exports_diagnostic(decl.span, decl.kind));
74-
}
75-
} else if export_name_decl.source.is_none() {
76-
// e.g. "let a = 3; export { a }"
77-
for specifier in &export_name_decl.specifiers {
78-
if let ModuleExportName::IdentifierReference(ident) = &specifier.local {
79-
let Some(declaration) =
80-
get_reference_declaration(ident.reference_id(), ctx)
81-
else {
82-
continue;
83-
};
84-
ctx.diagnostic(no_mutable_exports_diagnostic(
85-
declaration.span,
86-
declaration.kind,
87-
));
88-
}
89-
}
90-
}
91-
}
92-
AstKind::ExportDefaultDeclaration(export_default_decl) => {
93-
// e.g. "let a = 4; export default a"
94-
let Some(Expression::Identifier(ident)) =
95-
export_default_decl.declaration.as_expression()
96-
else {
97-
return;
98-
};
99-
let Some(declaration) = get_reference_declaration(ident.reference_id(), ctx)
100-
else {
60+
fn run<'a>(&self, node: &oxc_semantic::AstNode<'a>, ctx: &LintContext<'a>) {
61+
match node.kind() {
62+
AstKind::ExportNamedDeclaration(export_name_decl) => {
63+
// e.g. "export let a = 4;"
64+
if let Some(declaration) = &export_name_decl.declaration {
65+
let Declaration::VariableDeclaration(decl) = declaration else {
10166
return;
10267
};
103-
ctx.diagnostic(no_mutable_exports_diagnostic(
104-
declaration.span,
105-
declaration.kind,
106-
));
68+
if matches!(
69+
decl.kind,
70+
VariableDeclarationKind::Var | VariableDeclarationKind::Let
71+
) {
72+
ctx.diagnostic(no_mutable_exports_diagnostic(decl.span, decl.kind));
73+
}
74+
} else if export_name_decl.source.is_none() {
75+
// e.g. "let a = 3; export { a }"
76+
for specifier in &export_name_decl.specifiers {
77+
if let ModuleExportName::IdentifierReference(ident) = &specifier.local {
78+
let Some(declaration) =
79+
get_reference_declaration(ident.reference_id(), ctx)
80+
else {
81+
continue;
82+
};
83+
ctx.diagnostic(no_mutable_exports_diagnostic(
84+
declaration.span,
85+
declaration.kind,
86+
));
87+
}
88+
}
10789
}
108-
_ => {}
10990
}
91+
AstKind::ExportDefaultDeclaration(export_default_decl) => {
92+
// e.g. "let a = 4; export default a"
93+
let Some(Expression::Identifier(ident)) =
94+
export_default_decl.declaration.as_expression()
95+
else {
96+
return;
97+
};
98+
let Some(declaration) = get_reference_declaration(ident.reference_id(), ctx) else {
99+
return;
100+
};
101+
ctx.diagnostic(no_mutable_exports_diagnostic(declaration.span, declaration.kind));
102+
}
103+
_ => {}
110104
}
111105
}
112106
}

0 commit comments

Comments
 (0)