Skip to content

False positive with DeletePrefix #118

@avdv

Description

@avdv

For a multi-line string, I am using gsub(/^ /, '') and I receive a wrong suggestion that I should replace this call with delete_prefix.

Note that ^ matches at the beginning of a line, not only at the beginning of the string.


Expected behavior

No offense being reported.

Actual behavior

lib/colorls/flags.rb:169:23: C: Performance/DeletePrefix: Use delete_prefix instead of gsub.

      puts <<EXAMPLES.gsub(/^  /, '')

                      ^^^^

Steps to reproduce the problem

def show_examples
      puts <<EXAMPLES.gsub(/^  /, '')

  examples:

    * show the given file:

      colorls README.md

    * show matching files and list matching directories:

EXAMPLES
    end

RuboCop version

0.84.0 (using Parser 2.7.1.2, rubocop-ast 0.0.3, running on ruby 2.6.6 x86_64-linux)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions