Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak reported location of Lint/PercentArrays issues #571

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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