Skip to content

Commit

Permalink
Tweak reported location of Lint/PercentArrays issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Feb 16, 2025
1 parent d28076c commit 02a072f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
26 changes: 10 additions & 16 deletions spec/ameba/rule/lint/percent_arrays_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/ameba/rule/lint/percent_arrays.cr
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 02a072f

Please sign in to comment.