-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Style/FormatString
cop breaks code
#7130
Comments
"%02x" % 1 # => "01"
"%02x" % [1] # => "01"
"%02x-%02x" % [1, 2] # => "01-02"
format("%02x", 1)# => "01"
format("%02x", [1])# => TypeError
format("%02x-%02x", [1, 2]) # => TypeError
format("%02x-%02x", 1, 2) # => "01-02" I think we should mark the auto-correction as unsafe. |
@pocke Is is a good idea to not register offense when second argument to |
It makes sense, but I prefer changing auto-correct safety. By the way, I got other ideas. First, ignore only auto-correction when the argument is a variable. Second, I guess we can use splat operator for a variable, like |
This will be an issue if variable is a hash. First approach looks better. |
… argument is variable For `String#%` is second argument is variable, flag offense but skip autocorrect. It is not possible for rubocop to know if variable is array in which case the autocorrect leads to invalid code. Closes rubocop#7130.
Rubocop auto-corrector breaks code by
Style/FormatString
cop.Before code is
Execute auto-correct
After code is
Expected behavior
No effort.
Actual behavior
Fix to unexpected code.
RuboCop version
The text was updated successfully, but these errors were encountered: