-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #8948] Fix autocorrection for Style/RedundantRegexpCharacterClas…
…s with %r This commit uses `RegexpNode::RegexpParser#body` (#8960) instead of `Parser::Source::Range#adjust` in Style/RedundantRegexpCharacterClass. When regular expression are written by %r literal, RedundantRegexpCharacterClass made incorrect loc as following. ``` %r{abc[\d]+} ^^^^^^ ``` This bug are caused by calling`node.loc.begin.adjust` to get range of character class with %r regexp. `Parser::Source::Range#adjust` adjust based on `Parser::Source::Range#begin_pos` but it with %r literal doesn't indicate start of regular expression source, point to location of '%'. So, RedundantRegexpCharacterClass makes incorrect loc if %r literal are used in code. ``` r = %r{abc} ^ # `node.loc.begin.begin_pos` ``` ``` r = %r{abs} ^ # `node.loc.begin.end_pos` ```
- Loading branch information
Showing
4 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8230,6 +8230,12 @@ r = /[\s]/ | |
# good | ||
r = /\s/ | ||
# bad | ||
r = %r{/[b]} | ||
# good | ||
r = %r{/b} | ||
# good | ||
r = /[ab]/ | ||
---- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters