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

        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

        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 }

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

        Use SCREAMING_SNAKE_CASE for constants.
        Open

          Version = "0.3.1".freeze
        Severity: Minor
        Found in lib/kanji/version.rb by rubocop

        This cop checks whether constant names are written using SCREAMINGSNAKECASE.

        To avoid false positives, it ignores cases in which we cannot know for certain the type of value that would be assigned to a constant.

        Example:

        # bad
        InchInCm = 2.54
        INCHinCM = 2.54
        Inch_In_Cm = 2.54
        
        # good
        INCH_IN_CM = 2.54

        private (on line 16) does not make singleton methods private. Use private_class_method or private inside a class << self block instead.
        Open

              def self.get_member_type(type)
        Severity: Minor
        Found in lib/kanji/graph/coerce_type.rb by rubocop

        This cop checks for private or protected access modifiers which are applied to a singleton method. These access modifiers do not make singleton methods private/protected. private_class_method can be used for that.

        Example:

        # bad
        
        class C
          private
        
          def self.method
            puts 'hi'
          end
        end

        Example:

        # good
        
        class C
          def self.method
            puts 'hi'
          end
        
          private_class_method :method
        end

        Example:

        # good
        
        class C
          class << self
            private
        
            def method
              puts 'hi'
            end
          end
        end

        Extra empty line detected at module body beginning.
        Open

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

        This cops checks if empty lines around the bodies of modules match the configuration.

        Example: EnforcedStyle: empty_lines

        # good
        
        module Foo
        
          def bar
            # ...
          end
        
        end

        Example: EnforcedStyle: emptylinesexcept_namespace

        # good
        
        module Foo
          module Bar
        
            # ...
        
          end
        end

        Example: EnforcedStyle: emptylinesspecial

        # good
        module Foo
        
          def bar; end
        
        end

        Example: EnforcedStyle: noemptylines (default)

        # good
        
        module Foo
          def bar
            # ...
          end
        end

        Ambiguous block operator. Parenthesize the method arguments if it's surely a block operator, or add a whitespace to the right of the & if it should be a binary AND.
        Open

                self.instance_eval &block
        Severity: Minor
        Found in lib/kanji/type/mutation_definer.rb by rubocop

        This cop checks for ambiguous operators in the first argument of a method invocation without parentheses.

        Example:

        # bad
        
        # The `*` is interpreted as a splat operator but it could possibly be
        # a `*` method invocation (i.e. `do_something.*(some_array)`).
        do_something *some_array

        Example:

        # good
        
        # With parentheses, there's no ambiguity.
        do_something(*some_array)

        Unused method argument - options. If it's necessary, use _ or _options as an argument name to indicate that it won't be used.
        Open

              def initialize(app_name, options = {})
        Severity: Minor
        Found in lib/kanji/generators/project.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

        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

        Put empty method definitions on a single line.
        Open

              def post_process_callback
        
              end

        This cop checks for the formatting of empty method definitions. By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the end to go on its own line (expanded style).

        Note: A method definition is not considered empty if it contains comments.

        Example: EnforcedStyle: compact (default)

        # bad
        def foo(bar)
        end
        
        def self.foo(bar)
        end
        
        # good
        def foo(bar); end
        
        def foo(bar)
          # baz
        end
        
        def self.foo(bar); end

        Example: EnforcedStyle: expanded

        # bad
        def foo(bar); end
        
        def self.foo(bar); end
        
        # good
        def foo(bar)
        end
        
        def self.foo(bar)
        end

        Gems should be sorted in an alphabetical order within their section of the Gemfile. Gem rom-factory should appear before rspec.
        Open

          gem "rom-factory"
        Severity: Minor
        Found in lib/kanji/templates/Gemfile by rubocop

        Gems should be alphabetically sorted within groups.

        Example:

        # bad
        gem 'rubocop'
        gem 'rspec'
        
        # good
        gem 'rspec'
        gem 'rubocop'
        
        # good
        gem 'rubocop'
        
        gem 'rspec'
        
        # good only if TreatCommentsAsGroupSeparators is true
        # For code quality
        gem 'rubocop'
        # For tests
        gem 'rspec'
        Severity
        Category
        Status
        Source
        Language