From 02a072f04b24dd6c46457f2421e511d025be1f66 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sun, 16 Feb 2025 20:34:30 +0100 Subject: [PATCH] Tweak reported location of `Lint/PercentArrays` issues --- spec/ameba/rule/lint/percent_arrays_spec.cr | 26 ++++++++------------- src/ameba/rule/lint/percent_arrays.cr | 8 +++---- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/spec/ameba/rule/lint/percent_arrays_spec.cr b/spec/ameba/rule/lint/percent_arrays_spec.cr index 213902d58..42ce12c22 100644 --- a/spec/ameba/rule/lint/percent_arrays_spec.cr +++ b/spec/ameba/rule/lint/percent_arrays_spec.cr @@ -6,14 +6,13 @@ module Ameba::Rule::Lint it "passes if percent arrays are written correctly" do expect_no_issues subject, <<-CRYSTAL - %i[one two three] %w[one two three] - - %i[1 2 3] %w[1 2 3] + %w[] + %i[one two three] + %i[1 2 3] %i[] - %w[] CRYSTAL end @@ -45,17 +44,12 @@ module Ameba::Rule::Lint CRYSTAL end - it "reports rule, location and message for %i" do + it "reports rule, location and message" do expect_issue subject, <<-CRYSTAL - %i[:one] - # ^{} error: Symbols `,:` may be unwanted in `%i` array literals - CRYSTAL - end - - it "reports rule, location and message for %w" do - expect_issue subject, <<-CRYSTAL - %w["one"] - # ^{} error: Symbols `,"` may be unwanted in `%w` array literals + puts %w["one"] + # ^^ error: Symbols `,"` may be unwanted in `%w` array literals + puts %i[:one] + # ^^ error: Symbols `,:` may be unwanted in `%i` array literals CRYSTAL end @@ -64,14 +58,14 @@ module Ameba::Rule::Lint rule = PercentArrays.new rule.string_array_unwanted_symbols = "," - expect_no_issues rule, %( %w[one] ) + expect_no_issues rule, %(%w[one]) end it "#symbol_array_unwanted_symbols" do rule = PercentArrays.new rule.symbol_array_unwanted_symbols = "," - expect_no_issues rule, %( %i[:one] ) + expect_no_issues rule, %(%i[:one]) end end end diff --git a/src/ameba/rule/lint/percent_arrays.cr b/src/ameba/rule/lint/percent_arrays.cr index acf353a22..b7e28fb4c 100644 --- a/src/ameba/rule/lint/percent_arrays.cr +++ b/src/ameba/rule/lint/percent_arrays.cr @@ -1,18 +1,18 @@ module Ameba::Rule::Lint - # A rule that disallows some unwanted symbols in percent array literals. + # A rule that disallows some unwanted symbols in percent string and symbol array literals. # # For example, this is usually written by mistake: # # ``` - # %i[:one, :two] # %w["one", "two"] + # %i[:one, :two] # ``` # # And the expected example is: # # ``` - # %i[one two] # %w[one two] + # %i[one two] # ``` # # YAML configuration example: @@ -47,7 +47,7 @@ module Ameba::Rule::Lint end when .string_array_end? if (_start = start_token) && (_issue = issue) - issue_for _start, _issue + issue_for _start.location, _start.location.adjust(column_number: 1), _issue end issue = start_token = nil end