toptal/chewy

View on GitHub
lib/chewy/index/witchcraft.rb

Summary

Maintainability
B
6 hrs
Test Coverage

Method non_proc_values has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

        def non_proc_values(field, nesting)
          non_proc_fields = non_proc_fields_for(field, nesting)
          object = "object#{nesting}"

          if non_proc_fields.present?
Severity: Minor
Found in lib/chewy/index/witchcraft.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 source_for has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def source_for(proc, nesting)
          ast = Parser::CurrentRuby.parse(proc.source)
          lambdas = exctract_lambdas(ast)

          raise "No lambdas found, try to reformat your code:\n`#{proc.source}`" unless lambdas
Severity: Minor
Found in lib/chewy/index/witchcraft.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 replace_lvar has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

        def replace_lvar(node, old_variable, new_variable)
          if node.is_a?(Parser::AST::Node)
            if node.type == :lvar && node.children.to_a == [old_variable]
              node.updated(nil, [new_variable])
            else
Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def replace_send(node, variable)
          if node.is_a?(Parser::AST::Node)
            if node.type == :send && node.children[0].nil?
              node.updated(nil, [Parser::AST::Node.new(:lvar, [variable]), *node.children[1..]])
            else
Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def replace_local(node, variable, local_index)
          if node.is_a?(Parser::AST::Node)
            if node.type == :send && node.children.to_a == [nil, variable]
              node.updated(nil, [
                Parser::AST::Node.new(:lvar, [:locals]),
Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def check_requirements!
          messages = []
          messages << "MethodSource gem is required for the Witchcraft, please add `gem 'method_source'` to your Gemfile" unless Proc.method_defined?(:source)
          messages << "Parser gem is required for the Witchcraft, please add `gem 'parser'` to your Gemfile" unless '::Parser'.safe_constantize
          messages << "Unparser gem is required for the Witchcraft, please add `gem 'unparser'` to your Gemfile" unless '::Unparser'.safe_constantize
Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def proc_fields_for(parent, nesting)
          return [] unless parent

          fields = (parent.children || []).select { |field| field.value.is_a?(Proc) }

Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def binding_variable_list(node)
          return unless node.is_a?(Parser::AST::Node)

          if node.type == :send && node.children[0].nil?
            node.children[1]
Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def exctract_lambdas(node)
          return unless node.is_a?(Parser::AST::Node)

          if node.type == :block && node.children[0].type == :send && node.children[0].to_a == [nil, :lambda]
            [node.children[2]]
Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def non_proc_fields_for(parent, nesting)
          return [] unless parent

          fields = (parent.children || []).reject { |field| field.value.is_a?(Proc) }

Severity: Minor
Found in lib/chewy/index/witchcraft.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

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

        def replace_self(node, variable)
          if node.is_a?(Parser::AST::Node)
            if node.type == :self
              Parser::AST::Node.new(:lvar, [variable])
            else
Severity: Minor
Found in lib/chewy/index/witchcraft.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