dphaener/kanji

View on GitHub

Showing 70 of 71 total issues

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.

Block has too many lines. [42/27]
Open

Gem::Specification.new do |s|
  s.name              = "kanji-web"
  s.version           = Kanji::Version
  s.summary           = "A strongly Typed GraphQL API"
  s.authors           = ["Darin Haener"]
Severity: Minor
Found in kanji.gemspec by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

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

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

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

              def initialize(&block)
                @_arguments = []
                self.instance_eval &block
        
                raise(AttributeError, "You must supply a name") unless @_name
        Severity: Minor
        Found in lib/kanji/type/mutation_definer.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

        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

        Align the operands of an expression in an assignment spanning multiple lines.
        Open

                "      field :destroy#{class_name}, Types::#{class_name}[:destroy_mutation]\n"
        Severity: Minor
        Found in lib/kanji/generators/type.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

        Prefer to_s over string interpolation.
        Open

                define_method "#{arg}" do |value|
        Severity: Minor
        Found in lib/kanji/instance_define.rb by rubocop

        This cop checks for strings that are just an interpolated expression.

        Example:

        # bad
        "#{@var}"
        
        # good
        @var.to_s
        
        # good if @var is already a String
        @var

        Freeze mutable objects assigned to constants.
        Open

              TYPE_MAP = {
                "String" => "String",
                "NilClass | String" => "String",
                "Integer" => "Int",
                "NilClass | Integer" => "Int",
        Severity: Minor
        Found in lib/kanji/graph/coerce_type.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

        Extra empty line detected at method body beginning.
        Open

        
              end

        This cops checks if empty lines exist around the bodies of methods.

        Example:

        # good
        
        def foo
          # ...
        end
        
        # bad
        
        def bar
        
          # ...
        
        end

        Always use raise to signal exceptions.
        Open

                fail NotImplementedError

        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

        Line is too long. [125/100]
        Open

              template_file = template_files.find { |f| f == aboslute_source_path.to_s } or raise "missing template file +#{source}+"
        Severity: Minor
        Found in lib/kanji/generate.rb by rubocop

        Redundant self detected.
        Open

                resolve_proc = self.resolve

        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

        Redundant self detected.
        Open

                self.instance_eval &block if block_given?
        Severity: Minor
        Found in lib/kanji/type/attribute_definer.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

        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

        Do not use spaces between -> and opening brace in lambda literals
        Open

                  lookup_type: -> (name) { lookup_type(name) },
        Severity: Minor
        Found in lib/kanji/generators/type.rb by rubocop

        This cop checks for spaces between -> and opening parameter brace in lambda literals.

        Example: EnforcedStyle: requirenospace (default)

        # bad
          a = -> (x, y) { x + y }
        
          # good
          a = ->(x, y) { x + y }

        Example: EnforcedStyle: require_space

        # bad
          a = ->(x, y) { x + y }
        
          # good
          a = -> (x, y) { x + y }

        Use \ instead of + or << to concatenate those strings.
        Open

                "      field :update#{class_name}, Types::#{class_name}[:update_mutation]\n" +
        Severity: Minor
        Found in lib/kanji/generators/type.rb by rubocop

        This cop checks for string literal concatenation at the end of a line.

        Example:

        # bad
        some_str = 'ala' +
                   'bala'
        
        some_str = 'ala' <<
                   'bala'
        
        # good
        some_str = 'ala' \
                   'bala'

        When using method_missing, fall back on super.
        Open

            def method_missing(method_name, *args, &block)
              if resolve(:value).respond_to?(method_name)
                resolve(:value).send(method_name, *args)
              else
                super(method_name, *args, &block)
        Severity: Minor
        Found in lib/kanji/type.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