Skip to content
Merged
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 @@ -181,7 +181,13 @@ impl Rule for ConsistentFunctionScoping {
}

fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
let (function_declaration_symbol_id, function_name, function_body, reporter_span) =
let (
function_declaration_symbol_id,
function_name,
function_body,
reporter_span,
function_scope_id,
) =
match node.kind() {
AstKind::Function(function) => {
if function.is_typescript_syntax() {
Expand Down Expand Up @@ -215,13 +221,15 @@ impl Rule for ConsistentFunctionScoping {
Span::sized(function.span.start, 8),
|func_binding_ident| func_binding_ident.span,
),
func_scope_id,
)
} else if let Some(function_id) = &function.id {
(
function_id.symbol_id(),
Some(function_id.name),
function_body,
function_id.span(),
func_scope_id,
)
} else {
return;
Expand All @@ -237,6 +245,7 @@ impl Rule for ConsistentFunctionScoping {
Some(binding_ident.name),
&arrow_function.body,
binding_ident.span(),
arrow_function.scope_id(),
)
}
_ => return,
Expand Down Expand Up @@ -273,10 +282,8 @@ impl Rule for ConsistentFunctionScoping {
}

let parent_scope_ids = {
let mut current_scope_id =
ctx.scoping().symbol_scope_id(function_declaration_symbol_id);
let mut current_scope_id = function_scope_id;
let mut parent_scope_ids = FxHashSet::default();
parent_scope_ids.insert(current_scope_id);
while let Some(parent_scope_id) = ctx.scoping().scope_parent_id(current_scope_id) {
parent_scope_ids.insert(parent_scope_id);
current_scope_id = parent_scope_id;
Expand Down Expand Up @@ -749,6 +756,7 @@ fn test() {
",
None,
),
("function outer() { { let x; var inner = () => x; } return inner; }", None),
];

let fail = vec![
Expand Down
Loading