Rubocop: Style/RegexpLiteral recommends %r when default (or forced) slashes is in effect

Created on 30 Jan 2018  路  1Comment  路  Source: rubocop-hq/rubocop

Expected behavior

No warning from rubocop.

Actual behavior

Fails. Even if we specify slashes in EnforcedStyle property in .rubocop.yml.

repro.rb:3:3: C: Style/RegexpLiteral: Use %r around regular expression.
  /.*\/tests~.*/
  ^^^^^^^^^^^^^^

Steps to reproduce the problem

Run rubocop in this snippet:

TEST_FILE_REGEX = [
  /.*\.tools.*/,
  /.*\/tests~.*/
].freeze

RuboCop version

$ bundle exec rubocop -V
0.52.1 (using Parser 2.4.0.2, running on ruby 2.5.0 x86_64-linux)

Most helpful comment

For this behavior, you should configure AllowInnerSlashes as well:

Style/RegexpLiteral:
  AllowInnerSlashes: true

>All comments

For this behavior, you should configure AllowInnerSlashes as well:

Style/RegexpLiteral:
  AllowInnerSlashes: true
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Aqualon picture Aqualon  路  3Comments

lepieru picture lepieru  路  3Comments

ecbrodie picture ecbrodie  路  3Comments

deivid-rodriguez picture deivid-rodriguez  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments