dry-rb/dry-matcher

View on GitHub

Showing 10 of 10 total issues

Method initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(match: Undefined, resolve: DEFAULT_RESOLVE, &block)
        if block
          @match = block
        else
          @match = proc do |value, patterns|
Severity: Minor
Found in lib/dry/matcher/case.rb - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

        if @unhandled_cases.any?
Severity: Minor
Found in lib/dry/matcher/evaluator.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Remove debugger entry point binding.pry.
Open

binding.pry
Severity: Minor
Found in bin/console by rubocop

This cop checks for calls to debugger or pry.

Example:

# bad (ok during development)

# using pry
def some_method
  binding.pry
  do_something
end

Example:

# bad (ok during development)

# using byebug
def some_method
  byebug
  do_something
end

Example:

# good

def some_method
  do_something
end

Line is too long. [108/100]
Open

  spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
Severity: Minor
Found in dry-matcher.gemspec by rubocop

Empty line detected around arguments.
Open


        if result.success?
Severity: Minor
Found in lib/dry/matcher/result_matcher.rb by rubocop

This cops checks if empty lines exist around the arguments of a method invocation.

Example:

# bad
do_something(
  foo

)

process(bar,

        baz: qux,
        thud: fred)

some_method(

  [1,2,3],
  x: y
)

# good
do_something(
  foo
)

process(bar,
        baz: qux,
        thud: fred)

some_method(
  [1,2,3],
  x: y
)

Empty line detected around arguments.
Open


        if result.failure?
Severity: Minor
Found in lib/dry/matcher/result_matcher.rb by rubocop

This cops checks if empty lines exist around the arguments of a method invocation.

Example:

# bad
do_something(
  foo

)

process(bar,

        baz: qux,
        thud: fred)

some_method(

  [1,2,3],
  x: y
)

# good
do_something(
  foo
)

process(bar,
        baz: qux,
        thud: fred)

some_method(
  [1,2,3],
  x: y
)

Avoid the use of the case equality operator ===.
Open

      elsif value.is_a?(::Array) && patterns.any? { |p| p === value[0] }
Severity: Minor
Found in lib/dry/matcher/result_matcher.rb by rubocop

This cop checks for uses of the case equality operator(===).

Example:

# bad
Array === something
(1..100) === 7
/something/ === some_string

# good
something.is_a?(Array)
(1..100).include?(7)
some_string =~ /something/

Line is too long. [102/100]
Open

          ::Kernel.raise NonExhaustiveMatchError, "cases +#{@unhandled_cases.join(', ')}+ not handled"
Severity: Minor
Found in lib/dry/matcher/evaluator.rb by rubocop

Avoid the use of the case equality operator ===.
Open

      elsif patterns.any? { |p| p === value }
Severity: Minor
Found in lib/dry/matcher/result_matcher.rb by rubocop

This cop checks for uses of the case equality operator(===).

Example:

# bad
Array === something
(1..100) === 7
/something/ === some_string

# good
something.is_a?(Array)
(1..100).include?(7)
some_string =~ /something/

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

        unless defined? @output
Severity: Minor
Found in lib/dry/matcher/evaluator.rb by rubocop

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok
Severity
Category
Status
Source
Language