dry-rb/dry-struct

View on GitHub
lib/dry/struct/class_interface.rb

Summary

Maintainability
B
4 hrs
Test Coverage
A
97%

Module has too many lines. [191/100]
Open

    module ClassInterface
      include Core::ClassAttributes

      include Dry::Types::Type
      include Dry::Types::Builder
Severity: Minor
Found in lib/dry/struct/class_interface.rb by rubocop

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

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

  class Struct
    # Class-level interface of {Struct} and {Value}
    module ClassInterface
      include Core::ClassAttributes

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

    Assignment Branch Condition size for attributes is too high. [25.34/20]
    Open

          def attributes(new_schema)
            keys = new_schema.keys.map { |k| k.to_s.chomp('?').to_sym }
            check_schema_duplication(keys)
    
            schema schema.schema(new_schema)
    Severity: Minor
    Found in lib/dry/struct/class_interface.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

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

          def build_type(name, type, &block)
            type_object =
              if type.is_a?(String)
                Dry::Types[type]
              elsif block.nil? && type.nil?
    Severity: Minor
    Found in lib/dry/struct/class_interface.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 meta has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def meta(meta = Undefined)
            if meta.equal?(Undefined)
              @meta
            else
              Class.new(self) do
    Severity: Minor
    Found in lib/dry/struct/class_interface.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

    Rename has_attribute? to attribute?.
    Open

          def has_attribute?(key)
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    This cop makes sure that predicates are named properly.

    Example:

    # bad
    def is_even?(value)
    end
    
    # good
    def even?(value)
    end
    
    # bad
    def has_value?
    end
    
    # good
    def value?
    end

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

              class_eval(<<-RUBY)
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    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 <

    Favor modifier unless usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

              unless equal?(Value)
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Line is too long. [115/100]
    Open

          #         versions: Constrained<Array<Constrained<Nominal<String> rule=[type?(String)]>> rule=[type?(Array)]>
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    Missing magic comment # frozen_string_literal: true.
    Open

    require 'dry/core/class_attributes'
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

    Example: EnforcedStyle: when_needed (default)

    # The `when_needed` style will add the frozen string literal comment
    # to files only when the `TargetRubyVersion` is set to 2.3+.
    # bad
    module Foo
      # ...
    end
    
    # good
    # frozen_string_literal: true
    
    module Foo
      # ...
    end

    Example: EnforcedStyle: always

    # The `always` style will always add the frozen string literal comment
    # to a file, regardless of the Ruby version or if `freeze` or `<

    Example: EnforcedStyle: never

    # The `never` will enforce that the frozen string literal comment does
    # not exist in a file.
    # bad
    # frozen_string_literal: true
    
    module Baz
      # ...
    end
    
    # good
    module Baz
      # ...
    end

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

            if overlapping_keys.any?
    Severity: Minor
    Found in lib/dry/struct/class_interface.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

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

            if overlapping_keys.any?
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    When defining the | operator, name its argument other.
    Open

          def |(type)
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    This cop makes sure that certain binary operator methods have their sole parameter named other.

    Example:

    # bad
    def +(amount); end
    
    # good
    def +(other); end

    Line is too long. [155/100]
    Open

          #   # => #<Dry::Types[Constructor<Schema<keys={name: Constrained<Nominal<String> rule=[type?(String)]> details: Language::Details}> fn=Kernel.Hash>]>
    Severity: Minor
    Found in lib/dry/struct/class_interface.rb by rubocop

    There are no issues that match your filters.

    Category
    Status