codeclimate/codeclimate

View on GitHub
lib/cc/analyzer/measurement_validations/name_validation.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%

Redundant escape inside regexp literal
Open

        REGEX = /^[A-Za-z0-9_\.\-]+$/

Checks for redundant escapes inside Regexp literals.

Example:

# bad
%r{foo\/bar}

# good
%r{foo/bar}

# good
/foo\/bar/

# good
%r/foo\/bar/

# good
%r!foo\!bar!

# bad
/a\-b/

# good
/a-b/

# bad
/[\+\-]\d/

# good
/[+\-]\d/

Redundant safe navigation detected.
Open

          name&.is_a?(String) && REGEX.match?(name)

Checks for redundant safe navigation calls. instance_of?, kind_of?, is_a?, eql?, respond_to?, and equal? methods are checked by default. These are customizable with AllowedMethods option.

In the example below, the safe navigation operator (&.) is unnecessary because NilClass has methods like respond_to? and is_a?.

Safety:

This cop is unsafe, because autocorrection can change the return type of the expression. An offending expression that previously could return nil will be autocorrected to never return nil.

Example:

# bad
do_something if attrs&.respond_to?(:[])

# good
do_something if attrs.respond_to?(:[])

# bad
while node&.is_a?(BeginNode)
  node = node.parent
end

# good
while node.is_a?(BeginNode)
  node = node.parent
end

# good - without `&.` this will always return `true`
foo&.respond_to?(:to_a)

There are no issues that match your filters.

Category
Status