dry-rb/dry-schema

View on GitHub

Showing 56 of 63 total issues

Class DSL has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

    class DSL
      Types = Schema::Types

      extend Dry::Initializer

Severity: Minor
Found in lib/dry/schema/dsl.rb - About 3 hrs to fix

    Assignment Branch Condition size for call is too high. [28.72/20]
    Open

            def call(*predicates, **opts, &block)
              schema = predicates.detect { |predicate| predicate.is_a?(Processor) }
    
              if schema
                current_type = schema_dsl.types[name]
    Severity: Minor
    Found in lib/dry/schema/macros/value.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for exclude? is too high. [25.48/20]
    Open

              def exclude?(messages, opts)
                Array(messages).all? do |msg|
                  hints = opts
                    .hints
                    .reject { |hint| msg == hint }

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for define is too high. [25.63/20]
    Open

            def define(*args, &block)
              definition = schema_dsl.new(&block)
              schema = definition.call
              type_schema =
                if array_type?(parent_type)
    Severity: Minor
    Found in lib/dry/schema/macros/schema.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Perceived complexity for extract_type_spec is too high. [9/7]
    Open

            def extract_type_spec(*args, nullable: false, set_type: true)
              type_spec = args[0]
    
              is_type_spec = type_spec.is_a?(Dry::Schema::Processor) ||
                             type_spec.is_a?(Symbol) &&
    Severity: Minor
    Found in lib/dry/schema/macros/dsl.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

    Assignment Branch Condition size for visit_predicate is too high. [22.23/20]
    Open

          def visit_predicate(node, opts)
            predicate, args = node
    
            tokens = message_tokens(args)
            path, *arg_vals, input = predicate_resolvers[predicate].(args, opts)
    Severity: Minor
    Found in lib/dry/schema/message_compiler.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Perceived complexity for exclude? is too high. [9/7]
    Open

              def exclude?(messages, opts)
                Array(messages).all? do |msg|
                  hints = opts
                    .hints
                    .reject { |hint| msg == hint }

    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 extract_type_spec has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

            def extract_type_spec(*args, nullable: false, set_type: true)
              type_spec = args[0]
    
              is_type_spec = type_spec.is_a?(Dry::Schema::Processor) ||
                             type_spec.is_a?(Symbol) &&
    Severity: Minor
    Found in lib/dry/schema/macros/dsl.rb - About 1 hr 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 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def call(input)
            if input.success?
              type_schema[input.to_h]
            else
              type_schema.each_with_object(EMPTY_HASH.dup) do |key, hash|
    Severity: Minor
    Found in lib/dry/schema/value_coercer.rb - About 1 hr 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 value has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

            def value(*args, **opts, &block)
              type(:array)
    
              extract_type_spec(*args, set_type: false) do |*predicates, type_spec:|
                type(schema_dsl.array[type_spec]) if type_spec
    Severity: Minor
    Found in lib/dry/schema/macros/array.rb - About 1 hr 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 initialize_placeholders! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def initialize_placeholders!
            return @placeholders = EMPTY_HASH if empty?
    
            @placeholders = paths.reduce(EMPTY_HASH.dup) do |hash, path|
              curr_idx = 0
    Severity: Minor
    Found in lib/dry/schema/message_set.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 key_spec has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def key_spec(name, type)
            if type.respond_to?(:keys)
              { name => key_map(type.name_key_map) }
            elsif type.respond_to?(:member)
              kv = key_spec(name, type.member)
    Severity: Minor
    Found in lib/dry/schema/dsl.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 method_missing has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def method_missing(meth, *args, &block)
            if meth.to_s.end_with?(QUESTION_MARK)
              if ::Dry::Schema::Trace::INVALID_PREDICATES.include?(meth)
                ::Kernel.raise InvalidSchemaError, "#{meth} predicate cannot be used in this context"
              end
    Severity: Minor
    Found in lib/dry/schema/trace.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 7 (exceeds 5 allowed). Consider refactoring.
    Open

            def call(*predicates, **opts, &block)
              schema = predicates.detect { |predicate| predicate.is_a?(Processor) }
    
              if schema
                current_type = schema_dsl.types[name]
    Severity: Minor
    Found in lib/dry/schema/macros/value.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 exclude? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

              def exclude?(messages, opts)
                Array(messages).all? do |msg|
                  hints = opts
                    .hints
                    .reject { |hint| msg == hint }
    Severity: Minor
    Found in lib/dry/schema/extensions/hints/message_compiler_methods.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

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

            def visit_predicate(node)
              pred, args = node
    
              if pred.equal?(:type?)
                EMPTY_ARRAY
    Severity: Minor
    Found in lib/dry/schema/predicate_inferrer.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

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

            def define(*args, &block)
              definition = schema_dsl.new(&block)
              schema = definition.call
              type_schema =
                if array_type?(parent_type)
    Severity: Minor
    Found in lib/dry/schema/macros/schema.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

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

          def evaluate_predicates(predicates)
            predicates.flat_map do |predicate|
              if predicate.respond_to?(:call)
                predicate
              elsif predicate.is_a?(::Array)
    Severity: Minor
    Found in lib/dry/schema/trace.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

    Unused block argument - type_spec. If it's necessary, use _ or _type_spec as an argument name to indicate that it won't be used.
    Open

              extract_type_spec(*args, nullable: true) do |*predicates, type_spec:|
    Severity: Minor
    Found in lib/dry/schema/macros/key.rb by rubocop

    This cop checks for unused block arguments.

    Example:

    # bad
    
    do_something do |used, unused|
      puts used
    end
    
    do_something do |bar|
      puts :foo
    end
    
    define_method(:foo) do |bar|
      puts :baz
    end

    Example:

    #good
    
    do_something do |used, _unused|
      puts used
    end
    
    do_something do
      puts :foo
    end
    
    define_method(:foo) do |_bar|
      puts :baz
    end

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

        class Messages::YAML < Messages::Abstract
    Severity: Minor
    Found in lib/dry/schema/messages/yaml.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