New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Style/RedundantRegexpCharacterClass
cop
#8055
Add Style/RedundantRegexpCharacterClass
cop
#8055
Conversation
0963bfe
to
3d44719
Compare
It sounds like a good idea, but maybe it's better to suggest it to Rubocop::RegularExpression. cc @pocke |
Hmm - is I'm also proposing to add another related Regexp cop in #7908 and Rubocop already has
which are Regexp-related. What do you think about adding this (and #7908) and maybe(?) later extracting them into |
I also wouldn't have regexp cops separated. |
CHANGELOG.md
Outdated
@@ -3,6 +3,7 @@ | |||
## master (unreleased) | |||
|
|||
### New features | |||
* [#8055](https://github.com/rubocop-hq/rubocop/pull/8055): Add new `Style/RedundantRegexpCharacterClass` cop. ([@owst][]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a blank line after the heading and remove the blank line between this and the next changelog entry?
config/default.yml
Outdated
@@ -3607,6 +3607,11 @@ Style/RedundantPercentQ: | |||
Enabled: true | |||
VersionAdded: '0.76' | |||
|
|||
Style/RedundantRegexpCharacterClass: | |||
Description: 'Checks for unnecessary single-element Regexp character classes.' | |||
Enabled: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true -> pending
include MatchRange | ||
|
||
MSG_REDUNDANT_CHARACTER_CLASS = | ||
'Redundant single-element character class, `[` and `]` can be removed' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot the final .
. I'd also make this more actionable and word it like Redundant ... [x] can be replaced with x.
(or something along those lines).
Great cop, btw! I love it! |
@owst You also have to rebase on top of |
@owst The CI is failing now. |
@owst I guess you have to rebase and squash here and we're good to go. |
```ruby # This cop checks for unnecessary single-element Regexp character classes. # # @example # # # bad # r = /[x]/ # # # good # r = /x/ # # # bad # r = /[\s]/ # # # good # r = /\s/ # # # good # r = /[ab]/ ```
6001467
to
9cddd6b
Compare
Done @bbatsov |
Thanks! |
This PR adds a cop to check for unnecessary single-element Regexp character classes:
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.