You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected autocorrect result to not raise error undefined method chars' for nil (NoMethodError)` for example by using a safe operator.
Actual behavior
Safe Autocorrect will create code that raises errors, either when the string is too short or when it's entirely empty (e.g. with a variable that can be blank or have a string of any length).
Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-performance, rubocop-rails, and others) output by rubocop -V,
include them as well. Here's an example:
phone_number.number.chars[0..9]
autocorrected to:
phone_number.number[0..9].chars
This will raise when number[0..9] is blank.
Instead, it should be autocorrected to:
phone_number.number[0..9]&.chars
We have a similar nil handling problem when the string is too short instead of blank:
So the safe operator will make this safe.
Expected behavior
Expected autocorrect result to not raise error
undefined method
chars' for nil (NoMethodError)` for example by using a safe operator.Actual behavior
Safe Autocorrect will create code that raises errors, either when the string is too short or when it's entirely empty (e.g. with a variable that can be blank or have a string of any length).
Steps to reproduce the problem
RuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler. Here's an example:You can see extension cop versions (e.g. rubocop-performance, rubocop-rails, and others) output by
rubocop -V
,include them as well. Here's an example:
Background Docs:
https://msp-greg.github.io/rubocop-performance/RuboCop/Cop/Performance/RedundantStringChars.html
The text was updated successfully, but these errors were encountered: