If you write a regexp containing inner slashes, RuboCop will keeps complaining about using %r{} even if you asks for slashes as enforced style in your .rubocop.yml file.
With EnforcedStyle: slashes or EnforcedStyle: mixed RuboCop should not display a warning urging you to use %r{} without more explanation. The message should be more explicit like: 芦 you should use %r{} when your regexp contains inner slashes (preference AllowInnerSlashes) [Style/RegexpLitteral] 禄
RuboCop warns me with a weird 芦 Use %r{} around regular expression [Style/RegexpLitteral] 禄
Write the following lines in a new files :
tutu = 'To/to lapin'
tutu.gsub(/o\/t?/, 'a')
puts tutu
In the same folder, create a .rubocop.yml file containing:
Style/RegexpLiteral:
EnforcedStyle: slashes
$ rubocop -V
0.46.0 (using Parser 2.3.2.0, running on ruby 2.1.2 x86_64-linux)
Agreed. This should be improved.
If we agree on the message to be displayed, I can try to make a PR to help you :)
I'll have to review the behavior of the cop first. Honestly I don't remember its different behaviors.
@milouse Actually, you need this configuration:
Style/RegexpLiteral:
EnforcedStyle: slashes
AllowInnerSlashes: true
because with the default AllowInnerSlashes: false, the meaning of EnforcedStyle: slashes is that slashes are only enforced as long as they don't make it necessary to escape inner slashes.
See the last example in the relevant section of the manual.
Most helpful comment
@milouse Actually, you need this configuration:
because with the default
AllowInnerSlashes: false, the meaning ofEnforcedStyle: slashesis that slashes are only enforced as long as they don't make it necessary to escape inner slashes.See the last example in the relevant section of the manual.