Small refactor

This commit is contained in:
Sijawusz Pur Rahnama 2022-12-13 23:42:18 +01:00
parent 7f6bd2289e
commit b6f3d41211
2 changed files with 6 additions and 12 deletions

View file

@ -58,16 +58,12 @@ module Ameba::Rule::Style
MSG = "Type name should be camelcased: %s, but it was %s"
private def check_node(source, node)
def test(source, node : Crystal::Alias | Crystal::ClassDef | Crystal::ModuleDef | Crystal::LibDef | Crystal::EnumDef)
name = node.name.to_s
expected = name.camelcase
return if name == expected
issue_for node, MSG % {expected, name}
end
def test(source, node : Crystal::Alias | Crystal::ClassDef | Crystal::ModuleDef | Crystal::LibDef | Crystal::EnumDef)
check_node(source, node)
end
end
end

View file

@ -29,18 +29,16 @@ module Ameba::Rule::Style
MSG = "Var name should be underscore-cased: %s, not %s"
private def check_node(source, node)
return if (expected = node.name.underscore) == node.name
issue_for node, MSG % {expected, node.name}
end
def test(source : Source)
VarVisitor.new self, source
end
def test(source, node : Crystal::Var | Crystal::InstanceVar | Crystal::ClassVar)
check_node source, node
name = node.name.to_s
expected = name.underscore
return if name == expected
issue_for node, MSG % {expected, name}
end
private class VarVisitor < AST::NodeVisitor