HipByte/codeclimate-rubymotion

View on GitHub
lib/rubocop/cop/rubymotion/init_must_return_self.rb

Summary

Maintainability
A
1 hr
Test Coverage

Assignment Branch Condition size for on_method_def is too high. [16.58/15]
Open

        def on_method_def(_node, _method_name, _args, body)
          return unless _method_name == :init
          return unless body
          return if body.self_type?

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 on_method_def has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

        def on_method_def(_node, _method_name, _args, body)
          return unless _method_name == :init
          return unless body
          return if body.self_type?

Severity: Minor
Found in lib/rubocop/cop/rubymotion/init_must_return_self.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

Avoid too many return statements within this method.
Open

          return if last_expr_in_body.self_type?
Severity: Major
Found in lib/rubocop/cop/rubymotion/init_must_return_self.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

              return if last_expr_in_body.return_type? && last_expr_in_body.children.last.self_type?
    Severity: Major
    Found in lib/rubocop/cop/rubymotion/init_must_return_self.rb - About 30 mins to fix

      Line is too long. [96/80]
      Open

                return if last_expr_in_body.return_type? && last_expr_in_body.children.last.self_type?

      Space between { and | missing.
      Open

                if body.each_node.none?{|x| x.type == :self }

      Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.

      Example: EnforcedStyle: space (default)

      # The `space` style enforces that block braces have
      # surrounding space.
      
      # bad
      some_array.each {puts e}
      
      # good
      some_array.each { puts e }

      Example: EnforcedStyle: no_space

      # The `no_space` style enforces that block braces don't
      # have surrounding space.
      
      # bad
      some_array.each { puts e }
      
      # good
      some_array.each {puts e}

      Example: EnforcedStyleForEmptyBraces: no_space (default)

      # The `no_space` EnforcedStyleForEmptyBraces style enforces that
      # block braces don't have a space in between when empty.
      
      # bad
      some_array.each {   }
      some_array.each {  }
      some_array.each { }
      
      # good
      some_array.each {}

      Example: EnforcedStyleForEmptyBraces: space

      # The `space` EnforcedStyleForEmptyBraces style enforces that
      # block braces have at least a spece in between when empty.
      
      # bad
      some_array.each {}
      
      # good
      some_array.each { }
      some_array.each {  }
      some_array.each {   }

      Example: SpaceBeforeBlockParameters: true (default)

      # The SpaceBeforeBlockParameters style set to `true` enforces that
      # there is a space between `{` and `|`. Overrides `EnforcedStyle`
      # if there is a conflict.
      
      # bad
      [1, 2, 3].each {|n| n * 2 }
      
      # good
      [1, 2, 3].each { |n| n * 2 }

      Example: SpaceBeforeBlockParameters: true

      # The SpaceBeforeBlockParameters style set to `false` enforces that
      # there is no space between `{` and `|`. Overrides `EnforcedStyle`
      # if there is a conflict.
      
      # bad
      [1, 2, 3].each { |n| n * 2 }
      
      # good
      [1, 2, 3].each {|n| n * 2 }

      Freeze mutable objects assigned to constants.
      Open

              MESSAGE = "When overriding the #init method, self must be returned."

      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

      Trailing whitespace detected.
      Open

            

      Extra empty line detected at module body beginning.
      Open

      
            class InitMustReturnSelf < Cop

      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

      Trailing whitespace detected.
      Open

                add_init_must_return_self_offense(_node) 

      Trailing whitespace detected.
      Open

              private 

      Space missing to the left of {.
      Open

                if body.each_node.none?{|x| x.type == :self }

      Checks that block braces have or don't have a space before the opening brace depending on configuration.

      Example:

      # bad
      foo.map{ |a|
        a.bar.to_s
      }
      
      # good
      foo.map { |a|
        a.bar.to_s
      }

      There are no issues that match your filters.

      Category
      Status