dry-rb/dry-auto_inject

View on GitHub

Showing 39 of 39 total issues

Method has too many lines. [17/10]
Open

        def define_initialize_with_splat(super_parameters)
          assign_dependencies = method(:assign_dependencies)
          slice_kwargs = method(:slice_kwargs)

          instance_mod.class_exec do

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

Method has too many lines. [14/10]
Open

        def self.of(obj, name)
          Enumerator.new do |y|
            ancestors = obj.ancestors

            loop do

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

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

        def self.of(obj, name)
          Enumerator.new do |y|
            ancestors = obj.ancestors

            loop do
Severity: Minor
Found in lib/dry/auto_inject/method_parameters.rb - About 2 hrs 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 has too many lines. [13/10]
Open

        def define_initialize_with_keywords(super_parameters)
          assign_dependencies = method(:assign_dependencies)
          slice_kwargs = method(:slice_kwargs)

          instance_mod.class_exec do

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

Method has too many lines. [11/10]
Open

            define_method :initialize do |*args, **kwargs|
              assign_dependencies.(kwargs, self)

              if super_parameters.splat?
                super(*args, kwargs)

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

Method has too many lines. [11/10]
Open

        def self.of(obj, name)
          Enumerator.new do |y|
            begin
              method = obj.instance_method(name)
            rescue NameError

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

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

        def define_initialize_with_splat(super_parameters)
          assign_dependencies = method(:assign_dependencies)
          slice_kwargs = method(:slice_kwargs)

          instance_mod.class_exec do
Severity: Minor
Found in lib/dry/auto_inject/strategies/kwargs.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 of has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

        def self.of(obj, name)
          Enumerator.new do |y|
            begin
              method = obj.instance_method(name)
            rescue NameError
Severity: Minor
Found in lib/dry/auto_inject/method_parameters.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 define_initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def define_initialize(klass)
          super_parameters = MethodParameters.of(klass, :initialize).each do |ps|
            # Look upwards past `def foo(*)` methods until we get an explicit list of parameters
            break ps unless ps.pass_through?
          end
Severity: Minor
Found in lib/dry/auto_inject/strategies/kwargs.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 define_initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def define_initialize(klass)
          super_parameters = MethodParameters.of(klass, :initialize).each do |ps|
            # Look upwards past `def foo(*)` methods until we get an explicit list of parameters
            break ps unless ps.pass_through?
          end
Severity: Minor
Found in lib/dry/auto_inject/strategies/args.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

required_ruby_version (2.4, declared in dry-auto_inject.gemspec) and TargetRubyVersion (2.1, declared in .rubocop.yml) should be equal.
Open

  spec.required_ruby_version = '>= 2.4.0'
Severity: Minor
Found in dry-auto_inject.gemspec by rubocop

Checks that required_ruby_version of gemspec and TargetRubyVersion of .rubocop.yml are equal. Thereby, RuboCop to perform static analysis working on the version required by gemspec.

Example:

# When `TargetRubyVersion` of .rubocop.yml is `2.3`.

# bad
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.2.0'
end

# bad
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.4.0'
end

# good
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.3.0'
end

# good
Gem::Specification.new do |spec|
  spec.required_ruby_version = '>= 2.3'
end

# good
Gem::Specification.new do |spec|
  spec.required_ruby_version = ['>= 2.3.0', '< 2.5.0']
end

Extra empty line detected before the rescue.
Open


rescue LoadError
Severity: Minor
Found in rakelib/rubocop.rake by rubocop

This cops checks if empty lines exist around the bodies of begin sections. This cop doesn't check empty lines at begin body beginning/end and around method definition body. Style/EmptyLinesAroundBeginBody or Style/EmptyLinesAroundMethodBody can be used for this purpose.

Example:

# good

begin
  do_something
rescue
  do_something2
else
  do_something3
ensure
  do_something4
end

# good

def foo
  do_something
rescue
  do_something2
end

# bad

begin
  do_something

rescue

  do_something2

else

  do_something3

ensure

  do_something4
end

# bad

def foo
  do_something

rescue

  do_something2
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

          raise NotImplementedError, "must be implemented by a subclass"

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Avoid comparing a variable with multiple items in a conditional, use Array#include? instead.
Open

          names << name if type == :key || type == :keyreq

This cop checks against comparing a variable with multiple items, where Array#include? could be used instead to avoid code repetition.

Example:

# bad
a = 'a'
foo if a == 'a' || a == 'b' || a == 'c'

# good
a = 'a'
foo if ['a', 'b', 'c'].include?(a)

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  gem "codeclimate-test-reporter", require: nil
Severity: Minor
Found in Gemfile by rubocop

Checks if uses of quotes match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
"No special symbols"
"No string interpolation"
"Just text"

# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"

Example: EnforcedStyle: double_quotes

# bad
'Just some text'
'No special chars or interpolation'

# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"

Freeze mutable objects assigned to constants.
Open

      PASS_THROUGH = [[:rest]]

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

When using method_missing, define respond_to_missing? and fall back on super.
Open

      def method_missing(name, *args, &block)
        builder.__send__(name)
      end
Severity: Minor
Found in lib/dry/auto_inject/injector.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

Freeze mutable objects assigned to constants.
Open

    VERSION = '0.6.1'
Severity: Minor
Found in lib/dry/auto_inject/version.rb by rubocop

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Avoid using {...} for multi-line blocks.
Open

        @sequential_arguments = parameters.any? { |type, _|

Check for uses of braces or do/end around single line or multi-line blocks.

Example: EnforcedStyle: linecountbased (default)

# bad - single line block
items.each do |item| item / 5 end

# good - single line block
items.each { |item| item / 5 }

# bad - multi-line block
things.map { |thing|
  something = thing.some_method
  process(something)
}

# good - multi-line block
things.map do |thing|
  something = thing.some_method
  process(something)
end

Example: EnforcedStyle: semantic

# Prefer `do...end` over `{...}` for procedural blocks.

# return value is used/assigned
# bad
foo = map do |x|
  x
end
puts (map do |x|
  x
end)

# return value is not used out of scope
# good
map do |x|
  x
end

# Prefer `{...}` over `do...end` for functional blocks.

# return value is not used out of scope
# bad
each { |x|
  x
}

# return value is used/assigned
# good
foo = map { |x|
  x
}
map { |x|
  x
}.inspect

Example: EnforcedStyle: bracesforchaining

# bad
words.each do |word|
  word.flip.flop
end.join("-")

# good
words.each { |word|
  word.flip.flop
}.join("-")

When using method_missing, define respond_to_missing?.
Open

      def method_missing(name, *args, &block)
        if strategies.key?(name)
          Injector.new(container, strategies[name], builder: self)
        else
          super
Severity: Minor
Found in lib/dry/auto_inject/builder.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
Severity
Category
Status
Source
Language