dphaener/kanji

View on GitHub
lib/kanji/type/class_interface.rb

Summary

Maintainability
A
2 hrs
Test Coverage

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

    module ClassInterface
      include Dry::Core::Constants

      attr_reader :_attributes, :_name, :_description, :_repo_name,
        :_associations
Severity: Minor
Found in lib/kanji/type/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.

Method attribute has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

      def attribute(name, type = nil, description = nil, **kwargs, &block)
Severity: Minor
Found in lib/kanji/type/class_interface.rb - About 35 mins to fix

    Method assoc has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

          def assoc(name, type = nil, description = nil, **kwargs, &block)
    Severity: Minor
    Found in lib/kanji/type/class_interface.rb - About 35 mins to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            def assoc(name, type = nil, description = nil, **kwargs, &block)
              if @_associations.map(&:name).include?(name)
                fail AttributeError, "Association #{name} is already defined"
              else
                @_associations <<
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb and 1 other location - About 25 mins to fix
      lib/kanji/type/class_interface.rb on lines 64..69

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

            def attribute(name, type = nil, description = nil, **kwargs, &block)
              if @_attributes.map(&:name).include?(name)
                fail AttributeError, "Attribute #{name} is already defined"
              else
                @_attributes <<
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb and 1 other location - About 25 mins to fix
      lib/kanji/type/class_interface.rb on lines 73..78

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

              if @_associations.map(&:name).include?(name)
      Severity: Minor
      Found in lib/kanji/type/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

      Redundant self detected.
      Open

              @_demodulized_type_name ||= Dry::Core::Inflector.demodulize(self.to_s)
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb by rubocop

      This cop checks for redundant uses of self.

      The usage of self is only needed when:

      • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

      • Calling an attribute writer to prevent an local variable assignment.

      Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

      Note we allow uses of self with operators because it would be awkward otherwise.

      Example:

      # bad
      def foo(bar)
        self.baz
      end
      
      # good
      def foo(bar)
        self.bar  # Resolves name clash with the argument.
      end
      
      def foo
        bar = 1
        self.bar  # Resolves name clash with the local variable.
      end
      
      def foo
        %w[x y z].select do |bar|
          self.bar == bar  # Resolves name clash with argument of the block.
        end
      end

      Always use raise to signal exceptions.
      Open

                fail AttributeError, "Association #{name} is already defined"
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb by rubocop

      This cop checks for uses of fail and raise.

      Example: EnforcedStyle: only_raise (default)

      # The `only_raise` style enforces the sole use of `raise`.
      # bad
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail
      
      # good
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise

      Example: EnforcedStyle: only_fail

      # The `only_fail` style enforces the sole use of `fail`.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail

      Example: EnforcedStyle: semantic

      # The `semantic` style enforces the use of `fail` to signal an
      # exception, then will use `raise` to trigger an offense after
      # it has been rescued.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        # Error thrown
      rescue Exception
        fail
      end
      
      Kernel.fail
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        raise 'Preferably with descriptive message'
      end
      
      explicit_receiver.fail
      explicit_receiver.raise

      Redundant self detected.
      Open

                  self.finalize(klass)
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb by rubocop

      This cop checks for redundant uses of self.

      The usage of self is only needed when:

      • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

      • Calling an attribute writer to prevent an local variable assignment.

      Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

      Note we allow uses of self with operators because it would be awkward otherwise.

      Example:

      # bad
      def foo(bar)
        self.baz
      end
      
      # good
      def foo(bar)
        self.bar  # Resolves name clash with the argument.
      end
      
      def foo
        bar = 1
        self.bar  # Resolves name clash with the local variable.
      end
      
      def foo
        %w[x y z].select do |bar|
          self.bar == bar  # Resolves name clash with argument of the block.
        end
      end

      Align the parameters of a method call if they span more than one line.
      Open

              :_associations
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb by rubocop

      Here we check if the parameters on a multi-line method call or definition are aligned.

      Example: EnforcedStyle: withfirstparameter (default)

      # good
      
      foo :bar,
          :baz
      
      # bad
      
      foo :bar,
        :baz

      Example: EnforcedStyle: withfixedindentation

      # good
      
      foo :bar,
        :baz
      
      # bad
      
      foo :bar,
          :baz

      1 trailing blank lines detected.
      Open

      Severity: Minor
      Found in lib/kanji/type/class_interface.rb by rubocop

      Always use raise to signal exceptions.
      Open

                fail AttributeError, "Attribute #{name} is already defined"
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb by rubocop

      This cop checks for uses of fail and raise.

      Example: EnforcedStyle: only_raise (default)

      # The `only_raise` style enforces the sole use of `raise`.
      # bad
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail
      
      # good
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise

      Example: EnforcedStyle: only_fail

      # The `only_fail` style enforces the sole use of `fail`.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        raise
      rescue Exception
        # handle it
      end
      
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        # handle it
      end
      
      Kernel.fail

      Example: EnforcedStyle: semantic

      # The `semantic` style enforces the use of `fail` to signal an
      # exception, then will use `raise` to trigger an offense after
      # it has been rescued.
      # bad
      begin
        raise
      rescue Exception
        # handle it
      end
      
      def watch_out
        # Error thrown
      rescue Exception
        fail
      end
      
      Kernel.fail
      Kernel.raise
      
      # good
      begin
        fail
      rescue Exception
        # handle it
      end
      
      def watch_out
        fail
      rescue Exception
        raise 'Preferably with descriptive message'
      end
      
      explicit_receiver.fail
      explicit_receiver.raise

      Use 2 (not 0) spaces for indenting an expression spanning multiple lines.
      Open

                AttributeDefiner.new(name, type, description, kwargs, &block).call
      Severity: Minor
      Found in lib/kanji/type/class_interface.rb by rubocop

      This cop checks the indentation of the right hand side operand in binary operations that span more than one line.

      Example:

      # bad
      if a +
      b
        something
      end
      
      # good
      if a +
         b
        something
      end

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

              if @_attributes.map(&:name).include?(name)
      Severity: Minor
      Found in lib/kanji/type/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

      There are no issues that match your filters.

      Category
      Status