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,7 +5,7 @@ module Ameba::Rule::Lint
|
|||
|
||||
describe DebuggerStatement do
|
||||
it "passes if there is no debugger statement" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
"this is not a debugger statement"
|
||||
s = "debugger"
|
||||
|
||||
|
@ -18,16 +18,18 @@ module Ameba::Rule::Lint
|
|||
end
|
||||
end
|
||||
A.new.debugger
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "fails if there is a debugger statement" do
|
||||
expect_issue subject, %(
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
a = 2
|
||||
debugger
|
||||
# ^{} error: Possible forgotten debugger statement detected
|
||||
# ^^^^^^ error: Possible forgotten debugger statement detected
|
||||
a = a + 1
|
||||
)
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
|
|
|
@ -5,20 +5,22 @@ module Ameba::Rule::Lint
|
|||
|
||||
describe DuplicatedRequire do
|
||||
it "passes if there are no duplicated requires" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
require "math"
|
||||
require "big"
|
||||
require "big/big_decimal"
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there are a duplicated requires" do
|
||||
expect_issue subject, %(
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
require "big"
|
||||
require "math"
|
||||
require "big"
|
||||
# ^{} error: Duplicated require of `big`
|
||||
)
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
|
|
|
@ -5,18 +5,18 @@ module Ameba::Rule::Lint
|
|||
subject = SharedVarInFiber.new
|
||||
|
||||
it "doesn't report if there is only local shared var in fiber" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
spawn do
|
||||
i = 1
|
||||
puts i
|
||||
end
|
||||
|
||||
Fiber.yield
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if there is only block shared var in fiber" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
10.times do |i|
|
||||
spawn do
|
||||
puts i
|
||||
|
@ -24,11 +24,11 @@ module Ameba::Rule::Lint
|
|||
end
|
||||
|
||||
Fiber.yield
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if there a spawn macro is used" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
i = 0
|
||||
while i < 10
|
||||
spawn puts(i)
|
||||
|
@ -36,11 +36,11 @@ module Ameba::Rule::Lint
|
|||
end
|
||||
|
||||
Fiber.yield
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports if there is a shared var in spawn" do
|
||||
expect_issue subject, %(
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
i = 0
|
||||
while i < 10
|
||||
spawn do
|
||||
|
@ -51,11 +51,13 @@ module Ameba::Rule::Lint
|
|||
end
|
||||
|
||||
Fiber.yield
|
||||
)
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source
|
||||
end
|
||||
|
||||
it "reports reassigned reference to shared var in spawn" do
|
||||
expect_issue subject, %(
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
channel = Channel(String).new
|
||||
n = 0
|
||||
|
||||
|
@ -67,11 +69,13 @@ module Ameba::Rule::Lint
|
|||
channel.send m
|
||||
end
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source
|
||||
end
|
||||
|
||||
it "doesn't report reassigned reference to shared var in block" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
channel = Channel(String).new
|
||||
n = 0
|
||||
|
||||
|
@ -82,21 +86,21 @@ module Ameba::Rule::Lint
|
|||
channel.send m
|
||||
end
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "does not report block is called in a spawn" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
def method(block)
|
||||
spawn do
|
||||
block.call(10)
|
||||
end
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports multiple shared variables in spawn" do
|
||||
expect_issue subject, %(
|
||||
source = expect_issue subject, <<-CRYSTAL
|
||||
foo, bar, baz = 0, 0, 0
|
||||
while foo < 10
|
||||
baz += 1
|
||||
|
@ -109,11 +113,13 @@ module Ameba::Rule::Lint
|
|||
end
|
||||
foo += 1
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
|
||||
expect_no_corrections source
|
||||
end
|
||||
|
||||
it "doesn't report if variable is passed to the proc" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
i = 0
|
||||
while i < 10
|
||||
proc = ->(x : Int32) do
|
||||
|
@ -124,19 +130,19 @@ module Ameba::Rule::Lint
|
|||
proc.call(i)
|
||||
i += 1
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if a channel is declared in outer scope" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
channel = Channel(Nil).new
|
||||
spawn { channel.send(nil) }
|
||||
channel.receive
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if there is a loop in spawn" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
channel = Channel(String).new
|
||||
|
||||
spawn do
|
||||
|
@ -146,47 +152,47 @@ module Ameba::Rule::Lint
|
|||
channel.send(line)
|
||||
end
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if a var is mutated in spawn and referenced outside" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
def method
|
||||
foo = 1
|
||||
spawn { foo = 2 }
|
||||
foo
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if variable is changed without iterations" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
def foo
|
||||
i = 0
|
||||
i += 1
|
||||
spawn { i }
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if variable is in a loop inside spawn" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
i = 0
|
||||
spawn do
|
||||
while i < 10
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "doesn't report if variable declared inside loop" do
|
||||
expect_no_issues subject, %(
|
||||
expect_no_issues subject, <<-CRYSTAL
|
||||
while true
|
||||
i = 0
|
||||
spawn { i += 1 }
|
||||
end
|
||||
)
|
||||
CRYSTAL
|
||||
end
|
||||
|
||||
it "reports rule, location and message" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue