dry-rb/dry-struct

View on GitHub

Showing 53 of 53 total issues

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 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

    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

    Missing magic comment # frozen_string_literal: true.
    Open

    require 'dry/struct'
    Severity: Minor
    Found in lib/dry-struct.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

    Missing magic comment # frozen_string_literal: true.
    Open

    Dry::Struct.register_extension(:pretty_print) do
    Severity: Minor
    Found in lib/dry/struct/extensions.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

    Missing magic comment # frozen_string_literal: true.
    Open

    require 'ice_nine'
    Severity: Minor
    Found in lib/dry/struct/value.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

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

      spec.add_runtime_dependency 'dry-core', '~> 0.4', '>= 0.4.3'
    Severity: Minor
    Found in dry-struct.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'

    Missing magic comment # frozen_string_literal: true.
    Open

    #!/usr/bin/env ruby
    Severity: Minor
    Found in bin/console 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

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

          def ===(value)
    Severity: Minor
    Found in lib/dry/struct/sum.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

    Unused method argument - keys. If it's necessary, use _ or _keys as an argument name to indicate that it won't be used. You can also write as deconstruct_keys(*) if you want the method to accept any arguments but don't care about them.
    Open

          def deconstruct_keys(keys)
    Severity: Minor
    Found in lib/dry/struct.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Missing magic comment # frozen_string_literal: true.
    Open

    source 'https://rubygems.org'
    Severity: Minor
    Found in Gemfile 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

    Space inside string interpolation detected.
    Open

          pp.group(1, "#<#{ klass.name || klass.inspect }", '>') do

    This cop checks for whitespace within string interpolations.

    Example: EnforcedStyle: no_space (default)

    # bad
       var = "This is the #{ space } example"
    
    # good
       var = "This is the #{no_space} example"

    Example: EnforcedStyle: space

    # bad
       var = "This is the #{no_space} example"
    
    # good
       var = "This is the #{ space } example"

    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

    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?

    Missing magic comment # frozen_string_literal: true.
    Open

    require 'pp'

    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

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

          def |(type)
    Severity: Minor
    Found in lib/dry/struct/sum.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
    Severity
    Category
    Status
    Source
    Language