mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
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:
parent
7cb0c15747
commit
7b437fbd2f
9 changed files with 182 additions and 103 deletions
|
@ -5,53 +5,57 @@ module Ameba::Rule::Style
|
|||
|
||||
describe IsAFilter do
|
||||
it "passes if there is no potential performance improvements" do
|
||||
source = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
[1, 2, nil].select(Int32)
|
||||
[1, 2, nil].reject(Nil)
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is .is_a? call within select" do
|
||||
source = Source.new %(
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
[1, 2, nil].select(&.is_a?(Int32))
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
# ^^^^^^^^^^^^^^^^^^^^^^ error: Use `select(Int32)` instead of `select {...}`
|
||||
CRYSTAL
|
||||
|
||||
expect_correction source, <<-CRYSTAL
|
||||
[1, 2, nil].select(Int32)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is .nil? call within reject" do
|
||||
source = Source.new %(
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
[1, 2, nil].reject(&.nil?)
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
# ^^^^^^^^^^^^^^ error: Use `reject(Nil)` instead of `reject {...}`
|
||||
CRYSTAL
|
||||
|
||||
expect_correction source, <<-CRYSTAL
|
||||
[1, 2, nil].reject(Nil)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "does not report if there .is_a? call within block with multiple arguments" do
|
||||
source = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
t.all? { |_, v| v.is_a?(String) }
|
||||
t.all? { |foo, bar| foo.is_a?(String) }
|
||||
t.all? { |foo, bar| bar.is_a?(String) }
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
context "properties" do
|
||||
it "allows to configure filter_names" do
|
||||
source = Source.new %(
|
||||
[1, 2, nil].reject(&.nil?)
|
||||
)
|
||||
rule = IsAFilter.new
|
||||
rule.filter_names = %w(select)
|
||||
rule.catch(source).should be_valid
|
||||
expect_no_issues rule, <<-CRYSTAL
|
||||
[1, 2, nil].reject(&.nil?)
|
||||
CRYSTAL
|
||||
end
|
||||
end
|
||||
|
||||
context "macro" do
|
||||
it "doesn't report in macro scope" do
|
||||
source = Source.new %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
{{ [1, 2, nil].reject(&.nil?) }}
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
CRYSTAL
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue