Remove normalize parameter from expect_issue (#249)

* Add `normalize` parameter to `expect_correction`

* Convert Style/IsAFilter spec

* Revert "Add `normalize` parameter to `expect_correction`"

This reverts commit 4b67e4b900.

* Remove `normalize` parameter from `expect_issue`

* Require indentation if multiple issues on a single line

* Update `Style/IsAFilter` spec

* Update `ExpectIssue` documentation

* Add missing `expect_no_corrections`

* Use carets and space with issues at column 1 or 2

* Update `expect_issue` docs
This commit is contained in:
fn ⌃ ⌥ 2021-11-06 06:15:19 -07:00 committed by GitHub
parent 7cb0c15747
commit 7b437fbd2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 182 additions and 103 deletions

View file

@ -5,66 +5,74 @@ module Ameba::Rule::Performance
describe AnyAfterFilter do
it "passes if there is no potential performance improvements" do
expect_no_issues subject, %(
expect_no_issues subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 1 }.any?(&.zero?)
[1, 2, 3].reject { |e| e > 1 }.any?(&.zero?)
[1, 2, 3].select { |e| e > 1 }
[1, 2, 3].reject { |e| e > 1 }
[1, 2, 3].any? { |e| e > 1 }
)
CRYSTAL
end
it "reports if there is select followed by any? without a block" do
expect_issue subject, %(
source = expect_issue subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.any?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `select {...}.any?`
)
CRYSTAL
expect_no_corrections source
end
it "does not report if source is a spec" do
expect_no_issues subject, %(
expect_no_issues subject, <<-CRYSTAL, "source_spec.cr"
[1, 2, 3].select { |e| e > 2 }.any?
), "source_spec.cr"
CRYSTAL
end
it "reports if there is reject followed by any? without a block" do
expect_issue subject, %(
source = expect_issue subject, <<-CRYSTAL
[1, 2, 3].reject { |e| e > 2 }.any?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
)
CRYSTAL
expect_no_corrections source
end
it "does not report if any? calls contains a block" do
expect_no_issues subject, %(
expect_no_issues subject, <<-CRYSTAL
[1, 2, 3].select { |e| e > 2 }.any?(&.zero?)
[1, 2, 3].reject { |e| e > 2 }.any?(&.zero?)
)
CRYSTAL
end
context "properties" do
it "allows to configure object_call_names" do
rule = Rule::Performance::AnyAfterFilter.new
rule.filter_names = %w(select)
expect_no_issues rule, %(
expect_no_issues rule, <<-CRYSTAL
[1, 2, 3].reject { |e| e > 2 }.any?
)
CRYSTAL
end
end
context "macro" do
it "reports in macro scope" do
expect_issue subject, %(
source = expect_issue subject, <<-CRYSTAL
{{ [1, 2, 3].reject { |e| e > 2 }.any? }}
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
)
CRYSTAL
expect_no_corrections source
end
end
it "reports rule, pos and message" do
expect_issue subject, %(
source = expect_issue subject, <<-CRYSTAL
[1, 2, 3].reject { |e| e > 2 }.any?
# ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: Use `any? {...}` instead of `reject {...}.any?`
)
CRYSTAL
expect_no_corrections source
end
end
end