Readability-related refactors

This commit is contained in:
Sijawusz Pur Rahnama 2022-11-14 01:24:29 +01:00
parent a6ebb48f14
commit e668ba5bf5
24 changed files with 89 additions and 61 deletions

View file

@ -191,7 +191,7 @@ module Ameba::AST
it "returns true if node is nested to Crystal::Macro" do
nodes = as_nodes %(
macro included
{{@type.each do |type| a = type end}}
{{ @type.each do |type| a = type end }}
end
)
outer_scope = Scope.new nodes.macro_nodes.first

View file

@ -40,7 +40,9 @@ module Ameba
---
Globs: 100
CONFIG
expect_raises(Exception, "incorrect 'Globs' section in a config file") { Config.new(yml) }
expect_raises(Exception, "Incorrect 'Globs' section in a config file") do
Config.new(yml)
end
end
it "initializes excluded as string" do
@ -68,7 +70,9 @@ module Ameba
---
Excluded: true
CONFIG
expect_raises(Exception, "incorrect 'Excluded' section in a config file") { Config.new(yml) }
expect_raises(Exception, "Incorrect 'Excluded' section in a config file") do
Config.new(yml)
end
end
end

View file

@ -211,11 +211,13 @@ module Ameba::Rule::Lint
end
def bar
{{@type.instance_vars.map do |ivar|
{{
@type.instance_vars.map do |ivar|
ivar.annotations(Name).each do |ann|
puts ann.args
end
end}}
end
}}
end
end
end

View file

@ -218,11 +218,11 @@ module Ameba::Rule::Lint
s = Source.new %(
record X do
macro foo(a, b)
{{a}} + {{b}}
{{ a }} + {{ b }}
end
macro bar(a, b, c)
{{a}} + {{b}} + {{c}}
{{ a }} + {{ b }} + {{ c }}
end
end
)

View file

@ -949,7 +949,7 @@ module Ameba::Rule::Lint
foo = 22
{% for x in %w(foo) %}
add({{x.id}})
add({{ x.id }})
{% end %}
)
subject.catch(s).should be_valid

View file

@ -190,7 +190,7 @@ module Ameba
def test(source, node : Crystal::ClassDef)
return unless location = node.location
end_location = location.adjust(column_number: {{"class".size - 1}})
end_location = location.adjust(column_number: {{ "class".size - 1 }})
issue_for(location, end_location, message: "class to module") do |corrector|
corrector.replace(location, end_location, "module")
@ -208,7 +208,7 @@ module Ameba
def test(source, node : Crystal::ModuleDef)
return unless location = node.location
end_location = location.adjust(column_number: {{"module".size - 1}})
end_location = location.adjust(column_number: {{ "module".size - 1 }})
issue_for(location, end_location, message: "module to class") do |corrector|
corrector.replace(location, end_location, "class")
@ -265,12 +265,12 @@ module Ameba
end
{% for node in NODES %}
{{getter_name = node.stringify.split("::").last.underscore + "_nodes"}}
{{ getter_name = node.stringify.split("::").last.underscore + "_nodes" }}
getter {{getter_name.id}} = [] of {{node}}
getter {{ getter_name.id }} = [] of {{ node }}
def visit(node : {{node}})
{{getter_name.id}} << node
def visit(node : {{ node }})
{{ getter_name.id }} << node
true
end
{% end %}