rubocop-hq/rubocop

View on GitHub
lib/rubocop/cop/mixin/hash_shorthand_syntax.rb

Summary

Maintainability
B
5 hrs
Test Coverage
A
99%

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

      def register_offense(node, message, replacement) # rubocop:disable Metrics/AbcSize
        add_offense(node.value, message: message) do |corrector|
          corrector.replace(node, replacement)

          next unless (def_node = def_node_that_require_parentheses(node))
Severity: Minor
Found in lib/rubocop/cop/mixin/hash_shorthand_syntax.rb - About 1 hr 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 def_node_that_require_parentheses has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

      def def_node_that_require_parentheses(node)
        last_pair = node.parent.pairs.last
        return unless last_pair.key.source == last_pair.value.source
        return unless (dispatch_node = find_ancestor_method_dispatch_node(node))
        return if dispatch_node.assignment_method?
Severity: Minor
Found in lib/rubocop/cop/mixin/hash_shorthand_syntax.rb - About 1 hr 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 on_pair has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def on_pair(node)
        return if ignore_hash_shorthand_syntax?(node)

        hash_key_source = node.key.source

Severity: Minor
Found in lib/rubocop/cop/mixin/hash_shorthand_syntax.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 dispatch_node.parent && parentheses?(dispatch_node.parent)
Severity: Major
Found in lib/rubocop/cop/mixin/hash_shorthand_syntax.rb - About 30 mins to fix

    Avoid too many return statements within this method.
    Open

            return if last_expression?(dispatch_node) && !method_dispatch_as_argument?(dispatch_node)
    Severity: Major
    Found in lib/rubocop/cop/mixin/hash_shorthand_syntax.rb - About 30 mins to fix

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

            def find_ancestor_method_dispatch_node(node)
              return unless (ancestor = node.parent.parent)
              return unless ancestor.call_type? || ancestor.super_type? || ancestor.yield_type?
              return if brackets?(ancestor)
      
      
      Severity: Minor
      Found in lib/rubocop/cop/mixin/hash_shorthand_syntax.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

      There are no issues that match your filters.

      Category
      Status