mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Skip macro scopes in ShadowingOuterLocalVar
This commit is contained in:
parent
2e9ef7fcb2
commit
614fcfa6a8
2 changed files with 22 additions and 4 deletions
|
@ -235,6 +235,23 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
CRYSTAL
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# https://github.com/crystal-ameba/ameba/issues/224#issuecomment-822245167
|
||||||
|
it "does not report scoped vars to MacroFor (2)" do
|
||||||
|
expect_no_issues subject, <<-CRYSTAL
|
||||||
|
struct Test
|
||||||
|
def test
|
||||||
|
{% begin %}
|
||||||
|
{% for ivar in @type.instance_vars %}
|
||||||
|
{% var_type = ivar %}
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
{% ["a", "b"].map { |ivar| puts ivar } %}
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CRYSTAL
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,10 @@ module Ameba::Rule::Lint
|
||||||
MSG = "Shadowing outer local variable `%s`"
|
MSG = "Shadowing outer local variable `%s`"
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
AST::ScopeVisitor.new self, source
|
AST::ScopeVisitor.new self, source, skip: [
|
||||||
|
Crystal::Macro,
|
||||||
|
Crystal::MacroFor,
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::ProcLiteral, scope : AST::Scope)
|
def test(source, node : Crystal::ProcLiteral, scope : AST::Scope)
|
||||||
|
@ -51,9 +54,7 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
|
|
||||||
private def find_shadowing(source, scope)
|
private def find_shadowing(source, scope)
|
||||||
outer_scope = scope.outer_scope
|
return unless outer_scope = scope.outer_scope
|
||||||
|
|
||||||
return if outer_scope.nil? || outer_scope.in_macro?
|
|
||||||
|
|
||||||
scope.arguments.reject(&.ignored?).each do |arg|
|
scope.arguments.reject(&.ignored?).each do |arg|
|
||||||
variable = outer_scope.find_variable(arg.name)
|
variable = outer_scope.find_variable(arg.name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue