mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Minor details
This commit is contained in:
parent
523a622b34
commit
134963ece7
7 changed files with 21 additions and 10 deletions
|
@ -12,15 +12,17 @@ module Ameba::AST
|
|||
# :nodoc:
|
||||
def visit(node : Crystal::Require)
|
||||
require_nodes << node
|
||||
true
|
||||
end
|
||||
|
||||
# If a top level node is Crystal::Expressions traverse the children.
|
||||
# If a top level node is `Crystal::Expressions`,
|
||||
# then always traverse the children.
|
||||
def visit(node : Crystal::Expressions)
|
||||
true
|
||||
end
|
||||
|
||||
# A general visit method for rest of the nodes.
|
||||
# Returns false meaning all child nodes will not be traversed.
|
||||
# Returns `false`, meaning all child nodes will not be traversed.
|
||||
def visit(node : Crystal::ASTNode)
|
||||
false
|
||||
end
|
||||
|
|
|
@ -24,7 +24,9 @@ module Ameba::Rule::Layout
|
|||
return if source_lines_size == 1 && last_source_line.empty?
|
||||
|
||||
last_line_empty = last_source_line.empty?
|
||||
return if source_lines_size.zero? || (source_lines.last(2).join.presence && last_line_empty)
|
||||
return if source_lines_size.zero? ||
|
||||
(source_lines.last(2).join.presence && last_line_empty)
|
||||
|
||||
if last_line_empty
|
||||
issue_for({source_lines_size, 1}, MSG)
|
||||
else
|
||||
|
|
|
@ -41,6 +41,7 @@ module Ameba::Rule::Lint
|
|||
op_end_location.column_number - 1
|
||||
)
|
||||
op_text = source_between(op_location, op_end_location, source.lines)
|
||||
|
||||
return unless op_text
|
||||
return unless MISTAKES.has_key?(op_text)
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ module Ameba::Rule::Lint
|
|||
private def duplicated_keys(entries)
|
||||
entries.map(&.key)
|
||||
.group_by(&.itself)
|
||||
.tap(&.select! { |_, v| v.size > 1 })
|
||||
.select! { |_, v| v.size > 1 }
|
||||
.map { |k, _| k }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,13 +45,16 @@ module Ameba::Rule::Lint
|
|||
|
||||
return if rescues.nil?
|
||||
|
||||
shadowed(rescues).each { |tp| issue_for tp, MSG % tp.names.join("::") }
|
||||
shadowed(rescues).each do |path|
|
||||
issue_for path, MSG % path.names.join("::")
|
||||
end
|
||||
end
|
||||
|
||||
private def shadowed(rescues, catch_all = false)
|
||||
traversed_types = Set(String).new
|
||||
|
||||
filter_rescues(rescues).each_with_object([] of Crystal::Path) do |types, shadowed|
|
||||
rescues = filter_rescues(rescues)
|
||||
rescues.each_with_object([] of Crystal::Path) do |types, shadowed|
|
||||
case
|
||||
when catch_all
|
||||
shadowed.concat(types)
|
||||
|
@ -62,7 +65,7 @@ module Ameba::Rule::Lint
|
|||
catch_all = true
|
||||
next
|
||||
else
|
||||
nodes = types.select { |tp| traverse(tp.to_s, traversed_types) }
|
||||
nodes = types.select { |path| traverse(path.to_s, traversed_types) }
|
||||
shadowed.concat(nodes) unless nodes.empty?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,10 +20,12 @@ module Ameba::Rule::Metrics
|
|||
|
||||
def test(source, node : Crystal::Def)
|
||||
complexity = AST::CountingVisitor.new(node).count
|
||||
return unless complexity > max_complexity
|
||||
|
||||
return unless complexity > max_complexity && (location = node.name_location)
|
||||
issue_for location, name_end_location(node),
|
||||
MSG % {complexity, max_complexity}
|
||||
return unless location = node.name_location
|
||||
end_location = name_end_location(node)
|
||||
|
||||
issue_for location, end_location, MSG % {complexity, max_complexity}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,6 +79,7 @@ module Ameba::Rule::Style
|
|||
old = OLD % node.name
|
||||
new = NEW % {node.name, name}
|
||||
msg = MSG % {new, old}
|
||||
|
||||
if end_location
|
||||
issue_for(filter_location, end_location, msg) do |corrector|
|
||||
corrector.replace(filter_location, end_location, new)
|
||||
|
|
Loading…
Reference in a new issue