Skip to content

Performance/StringInclude autocorrect is unsafe #145

Closed
@beauraF

Description

Hi,

New cop Performance/StringInclude introduced by #117 is unsafe when use with --auto-correct.

  1. It currently auto-corrects the usage of match and =~. But the return values between match or =~ and include? are different. If the value is used, the behavior is altered.
  2. =~ doesn't raise an error in case of nil =~ /foobar/. Same, behavior is altered.

Two examples that broke in our codebase:

search_by_street_address = params[:types] =~ /street_address/
@agenda_requested_in_config ||= method.match(/agenda/)

I think it should only fix match? and reserve match and =~ in the case of --auto-correct-all. I don't know if you can make that distinction?

If not, maybe move this cop as unsafe? What do you think?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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