Merge pull request #223 from crystal-ameba/fix-issue-219

Skip macro code in `Style/IsAFilter` rule
This commit is contained in:
Sijawusz Pur Rahnama 2021-04-04 13:36:38 +02:00 committed by GitHub
commit f5628e6a11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -38,11 +38,11 @@ module Ameba::Rule::Style
end
context "macro" do
it "reports in macro scope" do
it "doesn't report in macro scope" do
source = Source.new %(
{{ [1, 2, nil].reject(&.nil?) }}
)
subject.catch(source).should_not be_valid
subject.catch(source).should be_valid
end
end

View file

@ -46,6 +46,15 @@ module Ameba::Rule::Style
MSG = "Use `%s(%s)` instead of `%s {...}`"
def test(source)
AST::NodeVisitor.new self, source, skip: [
Crystal::Macro,
Crystal::MacroExpression,
Crystal::MacroIf,
Crystal::MacroFor,
]
end
def test(source, node : Crystal::Call)
return unless node.name.in?(filter_names)
return unless (block = node.block)