dry-rb/dry-monads

View on GitHub

Showing 35 of 36 total issues

Class List has 31 methods (exceeds 20 allowed). Consider refactoring.
Open

    class List
      class << self
        # Builds a list.
        #
        # @param values [Array<Object>] List elements
Severity: Minor
Found in lib/dry/monads/list.rb - About 3 hrs to fix

    Class Task has 23 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Task
          # @api private
          class Promise < Concurrent::Promise
            public :on_fulfill, :on_reject
          end
    Severity: Minor
    Found in lib/dry/monads/task.rb - About 2 hrs to fix

      Perceived complexity for coerce is too high. [8/7]
      Open

              def coerce(value, type = nil)
                if value.nil?
                  List.new([], type)
                elsif value.respond_to?(:to_ary)
                  values = value.to_ary
      Severity: Minor
      Found in lib/dry/monads/list.rb by rubocop

      This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

      Example:

      def my_method                   # 1
        if cond                       # 1
          case var                    # 2 (0.8 + 4 * 0.2, rounded)
          when 1 then func_one
          when 2 then func_two
          when 3 then func_three
          when 4..10 then func_other
          end
        else                          # 1
          do_something until a && b   # 2
        end                           # ===
      end                             # 7 complexity points

      Method collect has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

            def collect
              if block_given?
                collected = value.each_with_object([]) do |x, ys|
                  y = yield(x)
                  ys << y.value! if y.some?
      Severity: Minor
      Found in lib/dry/monads/list.rb - About 55 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

      Method bind has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

              def bind(*args, **kwargs)
                if args.empty? && !kwargs.empty?
                  vargs, vkwargs = destructure(@value)
                  kw = [kwargs.merge(vkwargs)]
                else
      Severity: Minor
      Found in lib/dry/monads/right_biased.rb - About 45 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

      Method coerce has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def coerce(value, type = nil)
                if value.nil?
                  List.new([], type)
                elsif value.respond_to?(:to_ary)
                  values = value.to_ary
      Severity: Minor
      Found in lib/dry/monads/list.rb - About 35 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

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

            def self.call(value)
              func = value.is_a?(Proc) ? value : value.method(:call)
              seq_args = func.parameters.count { |type, _| type == :req || type == :opt }
              seq_args += 1 if func.parameters.any? { |type, _| type == :keyreq }
      
      
      Severity: Minor
      Found in lib/dry/monads/curry.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

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

                self.class == other.class && error === other.error
      Severity: Minor
      Found in lib/dry/monads/validated.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/

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

                self.class == other.class && value! === other.value!
      Severity: Minor
      Found in lib/dry/monads/right_biased.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/

      When using method_missing, define respond_to_missing?.
      Open

              def self.method_missing(m, *)
                if (instance.methods(true) - methods(true)).include?(m)
                  raise ConstructorNotAppliedError.new(m, :None)
                else
                  super
      Severity: Minor
      Found in lib/dry/monads/maybe.rb by rubocop

      This cop checks for the presence of method_missing without also defining respond_to_missing? and falling back on super.

      Example:

      #bad
      def method_missing(name, *args)
        # ...
      end
      
      #good
      def respond_to_missing?(name, include_private)
        # ...
      end
      
      def method_missing(name, *args)
        # ...
        super
      end

      Line is too long. [101/100]
      Open

              #                                                              or a name of predefined global
      Severity: Minor
      Found in lib/dry/monads/task.rb by rubocop

      Line is too long. [106/100]
      Open

            #   List[Right(Some(1)), Left(Some(1))].fmap3 { |x| x + 1 } # => List[Right(Some(2)), Left(Some(1))]
      Severity: Minor
      Found in lib/dry/monads/transformer.rb by rubocop

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

                if size.zero?
      Severity: Minor
      Found in lib/dry/monads/list.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

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

                Error === other && exception === other.exception
      Severity: Minor
      Found in lib/dry/monads/try.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/

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

                Failure === other && failure === other.failure
      Severity: Minor
      Found in lib/dry/monads/result.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

                  if value.some?
      Severity: Minor
      Found in lib/dry/monads/maybe.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

      Use yield instead of block.call.
      Open

                  inner = block.(v).promise
      Severity: Minor
      Found in lib/dry/monads/task.rb by rubocop

      This cop identifies the use of a &block parameter and block.call where yield would do just as well.

      Example:

      # bad
      def method(&block)
        block.call
      end
      def another(&func)
        func.call 1, 2, 3
      end
      
      # good
      def method
        yield
      end
      def another
        yield 1, 2, 3
      end

      Line is too long. [102/100]
      Open

              #   Dry::Monads.Failure(ArgumentError.new('error message')).or(&:message) # => "error message"
      Severity: Minor
      Found in lib/dry/monads/result.rb by rubocop

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

              if promise.wait.fulfilled?
      Severity: Minor
      Found in lib/dry/monads/task.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

      Use nested module/class definitions instead of compact style.
      Open

      module Dry::Monads
      Severity: Minor
      Found in lib/dry/monads/result/fixed.rb by rubocop

      This cop checks the style of children definitions at classes and modules. Basically there are two different styles:

      Example: EnforcedStyle: nested (default)

      # good
      # have each child on its own line
      class Foo
        class Bar
        end
      end

      Example: EnforcedStyle: compact

      # good
      # combine definitions as much as possible
      class Foo::Bar
      end

      The compact style is only forced for classes/modules with one child.

      Severity
      Category
      Status
      Source
      Language