From e5fb0526e0ead371d50e9cdb2b14a93fcb0ad868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fn=20=E2=8C=83=20=E2=8C=A5?= <70830482+FnControlOption@users.noreply.github.com> Date: Sat, 23 Oct 2021 02:09:04 -0700 Subject: [PATCH] Autocorrect `Style/LargeNumbers` --- spec/ameba/rule/style/large_numbers_spec.cr | 8 ++++++-- src/ameba/rule/style/large_numbers.cr | 8 +++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spec/ameba/rule/style/large_numbers_spec.cr b/spec/ameba/rule/style/large_numbers_spec.cr index 87fe95c6..f29884b5 100644 --- a/spec/ameba/rule/style/large_numbers_spec.cr +++ b/spec/ameba/rule/style/large_numbers_spec.cr @@ -9,7 +9,11 @@ module Ameba expect_issue rule, <<-CRYSTAL, 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 end end @@ -122,7 +126,7 @@ module Ameba issue.rule.should_not be_nil issue.location.to_s.should eq "source.cr:1:1" 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 context "properties" do diff --git a/src/ameba/rule/style/large_numbers.cr b/src/ameba/rule/style/large_numbers.cr index 8608abe3..2f72ff1f 100644 --- a/src/ameba/rule/style/large_numbers.cr +++ b/src/ameba/rule/style/large_numbers.cr @@ -28,12 +28,12 @@ module Ameba::Rule::Style # ``` class LargeNumbers < Base properties do - enabled false + enabled true description "Disallows usage of large numbers without underscore" int_min_digits 5 end - MSG = "Large numbers should be written with underscores: %s" + MSG = "Large numbers should be written with underscores." def test(source) Tokenizer.new(source).run do |token| @@ -48,7 +48,9 @@ module Ameba::Rule::Style location.line_number, 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