mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
fix(style): properly tokenize in RedundantBegin rule
This commit is contained in:
parent
80532da357
commit
60bf8e13ce
2 changed files with 22 additions and 1 deletions
|
@ -241,6 +241,27 @@ module Ameba::Rule::Style
|
||||||
CRYSTAL
|
CRYSTAL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "fails if there is a redundant block with string with inner quotes" do
|
||||||
|
source = expect_issue subject, <<-CRYSTAL
|
||||||
|
def method
|
||||||
|
begin
|
||||||
|
# ^^^^^ error: Redundant `begin` block detected
|
||||||
|
"'"
|
||||||
|
rescue
|
||||||
|
end
|
||||||
|
end
|
||||||
|
CRYSTAL
|
||||||
|
|
||||||
|
expect_correction source, <<-CRYSTAL
|
||||||
|
def method
|
||||||
|
#{trailing_whitespace}
|
||||||
|
"'"
|
||||||
|
rescue
|
||||||
|
#{trailing_whitespace}
|
||||||
|
end
|
||||||
|
CRYSTAL
|
||||||
|
end
|
||||||
|
|
||||||
it "fails if there is top level redundant block in a method" do
|
it "fails if there is top level redundant block in a method" do
|
||||||
source = expect_issue subject, <<-CRYSTAL
|
source = expect_issue subject, <<-CRYSTAL
|
||||||
def method
|
def method
|
||||||
|
|
|
@ -142,7 +142,7 @@ module Ameba::Rule::Style
|
||||||
private def def_redundant_end_loc(lexer)
|
private def def_redundant_end_loc(lexer)
|
||||||
end_loc = def_end_loc = nil
|
end_loc = def_end_loc = nil
|
||||||
|
|
||||||
while !(token = lexer.next_token).type.eof?
|
Tokenizer.new(lexer).run do |token|
|
||||||
next unless token.value == Crystal::Keyword::END
|
next unless token.value == Crystal::Keyword::END
|
||||||
|
|
||||||
end_loc, def_end_loc = def_end_loc, token.location
|
end_loc, def_end_loc = def_end_loc, token.location
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue