mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Autocorrect Style/LargeNumbers
This commit is contained in:
parent
99e7ccd23b
commit
e5fb0526e0
2 changed files with 11 additions and 5 deletions
|
@ -9,7 +9,11 @@ module Ameba
|
||||||
|
|
||||||
expect_issue rule, <<-CRYSTAL, number: number
|
expect_issue rule, <<-CRYSTAL, number: number
|
||||||
number = %{number}
|
number = %{number}
|
||||||
# ^{number} error: Large numbers should be written with underscores: #{expected}
|
# ^{number} error: Large numbers should be written with underscores.
|
||||||
|
CRYSTAL
|
||||||
|
|
||||||
|
expect_correction <<-CRYSTAL
|
||||||
|
number = #{expected}
|
||||||
CRYSTAL
|
CRYSTAL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -122,7 +126,7 @@ module Ameba
|
||||||
issue.rule.should_not be_nil
|
issue.rule.should_not be_nil
|
||||||
issue.location.to_s.should eq "source.cr:1:1"
|
issue.location.to_s.should eq "source.cr:1:1"
|
||||||
issue.end_location.to_s.should eq "source.cr:1:7"
|
issue.end_location.to_s.should eq "source.cr:1:7"
|
||||||
issue.message.should match /1_200_000/
|
issue.message.should eq "Large numbers should be written with underscores."
|
||||||
end
|
end
|
||||||
|
|
||||||
context "properties" do
|
context "properties" do
|
||||||
|
|
|
@ -28,12 +28,12 @@ module Ameba::Rule::Style
|
||||||
# ```
|
# ```
|
||||||
class LargeNumbers < Base
|
class LargeNumbers < Base
|
||||||
properties do
|
properties do
|
||||||
enabled false
|
enabled true
|
||||||
description "Disallows usage of large numbers without underscore"
|
description "Disallows usage of large numbers without underscore"
|
||||||
int_min_digits 5
|
int_min_digits 5
|
||||||
end
|
end
|
||||||
|
|
||||||
MSG = "Large numbers should be written with underscores: %s"
|
MSG = "Large numbers should be written with underscores."
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
Tokenizer.new(source).run do |token|
|
Tokenizer.new(source).run do |token|
|
||||||
|
@ -48,7 +48,9 @@ module Ameba::Rule::Style
|
||||||
location.line_number,
|
location.line_number,
|
||||||
location.column_number + token.raw.size - 1
|
location.column_number + token.raw.size - 1
|
||||||
)
|
)
|
||||||
issue_for location, end_location, MSG % expected
|
issue_for location, end_location, MSG do |corrector|
|
||||||
|
corrector.replace(location, end_location, expected)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue