Fix newly found offenses

This commit is contained in:
Sijawusz Pur Rahnama 2023-11-11 19:03:28 +01:00
parent 971bff6c27
commit 61ccb030bd
9 changed files with 26 additions and 26 deletions

View file

@ -15,7 +15,7 @@ Benchmark.ips do |x|
20,
30,
40,
].each do |n|
].each do |n| # ameba:disable Naming/BlockParameterName
config = Ameba::Config.load
config.formatter = Ameba::Formatter::BaseFormatter.new
config.globs = get_files(n)

View file

@ -11,23 +11,23 @@ module Ameba::Cli
end
describe ".parse_args" do
%w(-s --silent).each do |f|
it "accepts #{f} flag" do
c = Cli.parse_args [f]
%w(-s --silent).each do |flag|
it "accepts #{flag} flag" do
c = Cli.parse_args [flag]
c.formatter.should eq :silent
end
end
%w(-c --config).each do |f|
it "accepts #{f} flag" do
c = Cli.parse_args [f, "config.yml"]
%w(-c --config).each do |flag|
it "accepts #{flag} flag" do
c = Cli.parse_args [flag, "config.yml"]
c.config.should eq Path["config.yml"]
end
end
%w(-f --format).each do |f|
it "accepts #{f} flag" do
c = Cli.parse_args [f, "my-formatter"]
%w(-f --format).each do |flag|
it "accepts #{flag} flag" do
c = Cli.parse_args [flag, "my-formatter"]
c.formatter.should eq "my-formatter"
end
end

View file

@ -21,8 +21,8 @@ module Ameba::AST::Util
static_literal?(node.to)}
when Crystal::ArrayLiteral,
Crystal::TupleLiteral
{true, node.elements.all? do |el|
static_literal?(el)
{true, node.elements.all? do |element|
static_literal?(element)
end}
when Crystal::HashLiteral
{true, node.entries.all? do |entry|

View file

@ -136,7 +136,7 @@ module Ameba::AST
case assign
when Crystal::Assign then eql?(assign.target)
when Crystal::OpAssign then eql?(assign.target)
when Crystal::MultiAssign then assign.targets.any? { |t| eql?(t) }
when Crystal::MultiAssign then assign.targets.any? { |target| eql?(target) }
when Crystal::UninitializedVar then eql?(assign.var)
else
false

View file

@ -43,7 +43,7 @@ module Ameba::AST
end
private def traverse_case(node)
node.whens.each { |n| traverse_node n.body }
node.whens.each { |when_node| traverse_node when_node.body }
traverse_node(node.else)
end
@ -54,7 +54,7 @@ module Ameba::AST
private def traverse_exception_handler(node)
traverse_node node.body
traverse_node node.else
node.rescues.try &.each { |n| traverse_node n.body }
node.rescues.try &.each { |rescue_node| traverse_node rescue_node.body }
end
end
end

View file

@ -75,11 +75,11 @@ module Ameba::Cli
parser.on("-h", "--help", "Show this help") { print_help(parser) }
parser.on("-r", "--rules", "Show all available rules") { opts.rules = true }
parser.on("-s", "--silent", "Disable output") { opts.formatter = :silent }
parser.unknown_args do |f|
if f.size == 1 && f.first =~ /.+:\d+:\d+/
configure_explain_opts(f.first, opts)
parser.unknown_args do |arr|
if arr.size == 1 && arr.first.matches?(/.+:\d+:\d+/)
configure_explain_opts(arr.first, opts)
else
opts.globs = f unless f.empty?
opts.globs = arr unless arr.empty?
end
end

View file

@ -39,12 +39,12 @@ module Ameba::Formatter
end
private def rule_issues_map(issues)
Hash(Rule::Base, Array(Issue)).new.tap do |h|
Hash(Rule::Base, Array(Issue)).new.tap do |hash|
issues.each do |issue|
next if issue.disabled? || issue.rule.is_a?(Rule::Lint::Syntax)
next if issue.correctable? && config[:autocorrect]?
(h[issue.rule] ||= Array(Issue).new) << issue
(hash[issue.rule] ||= Array(Issue).new) << issue
end
end
end

View file

@ -30,8 +30,8 @@ module Ameba::Rule::Lint
MSG = "Redundant use of `Object#to_s` in interpolation"
def test(source, node : Crystal::StringInterpolation)
string_coercion_nodes(node).each do |n|
issue_for n.name_location, n.end_location, MSG
string_coercion_nodes(node).each do |expr|
issue_for expr.name_location, expr.end_location, MSG
end
end

View file

@ -34,13 +34,13 @@ module Ameba::Rule::Naming
MSG_SINGULAR = "Disallowed variable name, use '%s' instead"
def test(source, node : Crystal::ExceptionHandler)
node.rescues.try &.each do |r|
next if valid_name?(r.name)
node.rescues.try &.each do |rescue_node|
next if valid_name?(rescue_node.name)
message =
allowed_names.size == 1 ? MSG_SINGULAR : MSG
issue_for r, message % allowed_names.join("', '")
issue_for rescue_node, message % allowed_names.join("', '")
end
end