From bbbfdfc5a2e7b9234c66487a59464915d45d2b66 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 23 Dec 2022 14:46:23 +0100 Subject: [PATCH 1/2] Tweak reported location for `Lint/UnusedBlockArgument` --- spec/ameba/rule/lint/unused_block_argument_spec.cr | 6 +++--- src/ameba/rule/lint/unused_block_argument.cr | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/ameba/rule/lint/unused_block_argument_spec.cr b/spec/ameba/rule/lint/unused_block_argument_spec.cr index dbc95b8c..d5ad799c 100644 --- a/spec/ameba/rule/lint/unused_block_argument_spec.cr +++ b/spec/ameba/rule/lint/unused_block_argument_spec.cr @@ -38,7 +38,7 @@ module Ameba::Rule::Lint it "reports if block arg is not used" do source = expect_issue subject, <<-CRYSTAL def method(a, b, c, &block) - # ^ error: Unused block argument `block`. [...] + # ^^^^^ error: Unused block argument `block`. [...] end CRYSTAL @@ -51,7 +51,7 @@ module Ameba::Rule::Lint it "reports if unused and there is yield" do source = expect_issue subject, <<-CRYSTAL def method(a, b, c, &block) - # ^ error: Use `&` as an argument name to indicate that it won't be referenced. + # ^^^^^ error: Use `&` as an argument name to indicate that it won't be referenced. 3.times do |i| i.try do yield i @@ -94,7 +94,7 @@ module Ameba::Rule::Lint source = expect_issue subject, <<-CRYSTAL class Bar < Foo def method(a, b, c, &block) - # ^ error: Unused block argument `block`. [...] + # ^^^^^ error: Unused block argument `block`. [...] super a, b, c end end diff --git a/src/ameba/rule/lint/unused_block_argument.cr b/src/ameba/rule/lint/unused_block_argument.cr index 0af82811..7fdb0f67 100644 --- a/src/ameba/rule/lint/unused_block_argument.cr +++ b/src/ameba/rule/lint/unused_block_argument.cr @@ -58,7 +58,7 @@ module Ameba::Rule::Lint if scope.yields? if location && end_location - issue_for block_arg.node, MSG_YIELDED do |corrector| + issue_for location, end_location, MSG_YIELDED do |corrector| corrector.remove(location, end_location) end else @@ -67,7 +67,7 @@ module Ameba::Rule::Lint else return if block_arg.ignored? if location && end_location - issue_for block_arg.node, MSG_UNUSED % block_arg.name do |corrector| + issue_for location, end_location, MSG_UNUSED % block_arg.name do |corrector| corrector.insert_before(location, '_') end else From caaf803ecdd3f22314a99e42c2eda4e50dbb5241 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 23 Dec 2022 14:46:45 +0100 Subject: [PATCH 2/2] Tweak reported location for `Style/UnlessElse` --- src/ameba/rule/style/unless_else.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ameba/rule/style/unless_else.cr b/src/ameba/rule/style/unless_else.cr index 42f9cfb9..ba9c380b 100644 --- a/src/ameba/rule/style/unless_else.cr +++ b/src/ameba/rule/style/unless_else.cr @@ -62,7 +62,7 @@ module Ameba::Rule::Style return end - issue_for node, MSG do |corrector| + issue_for location, cond_end_location, MSG do |corrector| keyword_begin_pos = source.pos(location) keyword_end_pos = keyword_begin_pos + {{ "unless".size }} keyword_range = keyword_begin_pos...keyword_end_pos