-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
EndWith/StartWith autocorrects are not nil-safe #50
Comments
dduugg
added a commit
to dduugg/rubocop-performance
that referenced
this issue
May 7, 2019
8 tasks
dduugg
added a commit
to dduugg/rubocop-performance
that referenced
this issue
May 9, 2019
dduugg
added a commit
to dduugg/rubocop-performance
that referenced
this issue
May 10, 2019
dduugg
added a commit
to dduugg/rubocop-performance
that referenced
this issue
May 14, 2019
dduugg
added a commit
to dduugg/rubocop-performance
that referenced
this issue
May 20, 2019
This cop is marked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
EndWith
/StartWith
autocorrects do not contemplatenil
. I propose modifying them to behave likeRegexpMatch
(which correctsdo_something if pattern =~ param
intodo_something if pattern&.match?(path)
Expected behavior
do_something if var =~ /\A#/
should autocorrect todo_something if var&.start_with?('#')
Since it appears rubocop will soon end support for pre-2.3 ruby, I propose only fixing this for ruby 2.3 and above (where safe navigation is available).
Actual behavior
do_something if var =~ /\A#/
autocorrects todo_something if var.start_with?('#')
. The correction will now raise aNoMethodError
whenvar
isnil
, where previously the condition would simply evaluate tonil
.Steps to reproduce the problem
Invoke
rubocop -a --only Performance/StartWith
on a file containingdo_something if var =~ /\A#/
, with a.rubocop.yml
file containing:RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:The text was updated successfully, but these errors were encountered: