ManageIQ/miq_bot

View on GitHub
app/workers/commit_monitor_handlers/commit_range/rubocop_checker/rubocop_results_filter.rb

Summary

Maintainability
A
0 mins
Test Coverage

Use match? instead of match when MatchData is not used.
Open

            next unless f["path"].match %r{(?:^|/)spec/.+_spec.rb}

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

Use =~ in places where the MatchData returned by #match will not be used.
Open

            next unless f["path"].match %r{(?:^|/)spec/.+_spec.rb}

This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

Example:

# bad
do_something if str.match(/regex/)
while regex.match('str')
  do_something
end

# good
method(str =~ /regex/)
return value unless regex =~ 'str'

There are no issues that match your filters.

Category
Status