dry-rb/dry-initializer

View on GitHub

Showing 13 of 13 total issues

Class has too many lines. [111/100]
Open

  class Config
    # @!attribute [r] null
    # @return [Dry::Initializer::UNDEFINED, nil] value of unassigned variable

    # @!attribute [r] extended_class
Severity: Minor
Found in lib/dry/initializer/config.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method wrap_value has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def wrap_value(value, count, type)
    if count.zero?
      type ? type.call(value) : value
    else
      return [wrap_value(value, count - 1, type)] unless value.is_a?(Array)
Severity: Minor
Found in lib/dry/initializer/dispatchers/wrap_type.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 add_definition has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def add_definition(option, name, type, block, **opts)
Severity: Minor
Found in lib/dry/initializer/config.rb - About 35 mins to fix

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

        def public_attributes(instance)
          definitions.values.each_with_object({}) do |item, obj|
            key = item.target
            next unless instance.respond_to? key
            val = instance.send(key)
    Severity: Minor
    Found in lib/dry/initializer/config.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 coercion_line has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def coercion_line
          return unless @type
          arity = @type.is_a?(Proc) ? @type.arity : @type.method(:call).arity
          if arity.abs == 1
            "#{@val} = #{@item}.type.call(#{@val}) unless #{@null} == #{@val}"
    Severity: Minor
    Found in lib/dry/initializer/builders/attribute.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

    private (on line 31) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
    Open

        def self.extended(mod)
    Severity: Minor
    Found in lib/dry/initializer/dsl.rb by rubocop

    This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

    Example:

    # bad
    
    class C
      private
    
      def self.method
        puts 'hi'
      end
    end

    Example:

    # good
    
    class C
      def self.method
        puts 'hi'
      end
    
      private_class_method :method
    end

    Example:

    # good
    
    class C
      class << self
        private
    
        def method
          puts 'hi'
        end
      end
    end

    Do not place comments on the same line as the def keyword.
    Open

        def self.extended(klass) # @deprecated
    Severity: Minor
    Found in lib/dry/initializer/mixin.rb by rubocop

    This cop checks for comments put on the same line as some keywords. These keywords are: begin, class, def, end, module.

    Note that some comments (such as :nodoc: and rubocop:disable) are allowed.

    Example:

    # bad
    if condition
      statement
    end # end if
    
    # bad
    class X # comment
      statement
    end
    
    # bad
    def x; end # comment
    
    # good
    if condition
      statement
    end
    
    # good
    class X # :nodoc:
      y
    end

    The use of eval is a serious security risk.
    Open

        eval "class #{klass_name} < Dry::Initializer::Struct; end"

    This cop checks for the use of Kernel#eval and Binding#eval.

    Example:

    # bad
    
    eval(something)
    binding.eval(something)

    Argument wrap was shadowed by a local variable before it was used.
    Open

        type, wrap = unwrap(type, 0)

    This cop checks for shadowed arguments.

    Example:

    # bad
    
    do_something do |foo|
      foo = 42
      puts foo
    end
    
    def do_something(foo)
      foo = 42
      puts foo
    end

    Example:

    # good
    
    do_something do |foo|
      foo = foo + 42
      puts foo
    end
    
    def do_something(foo)
      foo = foo + 42
      puts foo
    end
    
    def do_something(foo)
      puts foo
    end

    Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency dry-types should appear before rake.
    Open

      gem.add_development_dependency "dry-types", "> 0.5.1"
    Severity: Minor
    Found in dry-initializer.gemspec by rubocop

    Dependencies in the gemspec should be alphabetically sorted.

    Example:

    # bad
    spec.add_dependency 'rubocop'
    spec.add_dependency 'rspec'
    
    # good
    spec.add_dependency 'rspec'
    spec.add_dependency 'rubocop'
    
    # good
    spec.add_dependency 'rubocop'
    
    spec.add_dependency 'rspec'
    
    # bad
    spec.add_development_dependency 'rubocop'
    spec.add_development_dependency 'rspec'
    
    # good
    spec.add_development_dependency 'rspec'
    spec.add_development_dependency 'rubocop'
    
    # good
    spec.add_development_dependency 'rubocop'
    
    spec.add_development_dependency 'rspec'
    
    # bad
    spec.add_runtime_dependency 'rubocop'
    spec.add_runtime_dependency 'rspec'
    
    # good
    spec.add_runtime_dependency 'rspec'
    spec.add_runtime_dependency 'rubocop'
    
    # good
    spec.add_runtime_dependency 'rubocop'
    
    spec.add_runtime_dependency 'rspec'
    
    # good only if TreatCommentsAsGroupSeparators is true
    # For code quality
    spec.add_dependency 'rubocop'
    # For tests
    spec.add_dependency 'rspec'

    Pass __FILE__ and __LINE__ to eval method, as they are used by backtraces.
    Open

        eval "class #{klass_name} < Dry::Initializer::Struct; end"

    This cop checks eval method usage. eval can receive source location metadata, that are filename and line number. The metadata is used by backtraces. This cop recommends to pass the metadata to eval method.

    Example:

    # bad
    eval <

    Omit parentheses for ternary conditions.
    Open

          null = (undefined == false) ? nil : UNDEFINED
    Severity: Minor
    Found in lib/dry/initializer/dsl.rb by rubocop

    This cop checks for the presence of parentheses around ternary conditions. It is configurable to enforce inclusion or omission of parentheses using EnforcedStyle. Omission is only enforced when removing the parentheses won't cause a different behavior.

    Example: EnforcedStyle: requirenoparentheses (default)

    # bad
    foo = (bar?) ? a : b
    foo = (bar.baz?) ? a : b
    foo = (bar && baz) ? a : b
    
    # good
    foo = bar? ? a : b
    foo = bar.baz? ? a : b
    foo = bar && baz ? a : b

    Example: EnforcedStyle: require_parentheses

    # bad
    foo = bar? ? a : b
    foo = bar.baz? ? a : b
    foo = bar && baz ? a : b
    
    # good
    foo = (bar?) ? a : b
    foo = (bar.baz?) ? a : b
    foo = (bar && baz) ? a : b

    Example: EnforcedStyle: requireparentheseswhen_complex

    # bad
    foo = (bar?) ? a : b
    foo = (bar.baz?) ? a : b
    foo = bar && baz ? a : b
    
    # good
    foo = bar? ? a : b
    foo = bar.baz? ? a : b
    foo = (bar && baz) ? a : b

    Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency rake should appear before rspec.
    Open

      gem.add_development_dependency "rake", "> 10"
    Severity: Minor
    Found in dry-initializer.gemspec by rubocop

    Dependencies in the gemspec should be alphabetically sorted.

    Example:

    # bad
    spec.add_dependency 'rubocop'
    spec.add_dependency 'rspec'
    
    # good
    spec.add_dependency 'rspec'
    spec.add_dependency 'rubocop'
    
    # good
    spec.add_dependency 'rubocop'
    
    spec.add_dependency 'rspec'
    
    # bad
    spec.add_development_dependency 'rubocop'
    spec.add_development_dependency 'rspec'
    
    # good
    spec.add_development_dependency 'rspec'
    spec.add_development_dependency 'rubocop'
    
    # good
    spec.add_development_dependency 'rubocop'
    
    spec.add_development_dependency 'rspec'
    
    # bad
    spec.add_runtime_dependency 'rubocop'
    spec.add_runtime_dependency 'rspec'
    
    # good
    spec.add_runtime_dependency 'rspec'
    spec.add_runtime_dependency 'rubocop'
    
    # good
    spec.add_runtime_dependency 'rubocop'
    
    spec.add_runtime_dependency 'rspec'
    
    # good only if TreatCommentsAsGroupSeparators is true
    # For code quality
    spec.add_dependency 'rubocop'
    # For tests
    spec.add_dependency 'rspec'
    Severity
    Category
    Status
    Source
    Language