codeclimate/codeclimate-yaml

View on GitHub

Showing 158 of 158 total issues

Cyclomatic complexity for parses? is too high. [7/6]
Open

      def self.parses?(value)
        return true if value.is_a?(::Psych::Nodes::Node)
        return true if value.is_a?(String) or value.is_a?(IO)
        return true if defined?(StringIO) and value.is_a?(StringIO)
        value.respond_to?(:to_str) or value.respond_to?(:to_io)
Severity: Minor
Found in lib/cc/yaml/parser/psych.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Cyclomatic complexity for serialize_secure is too high. [7/6]
Open

      def serialize_secure(value)
        case options[:secure]
        when :decrypted
          raise ArgumentError, "secure option is set decrypted, but a secure value is not decrypted" unless value.decrypted?
          serialize_decrypted(value)
Severity: Minor
Found in lib/cc/yaml/serializer/generic.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method serialize_secure has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def serialize_secure(value)
        case options[:secure]
        when :decrypted
          raise ArgumentError, "secure option is set decrypted, but a secure value is not decrypted" unless value.decrypted?
          serialize_decrypted(value)
Severity: Minor
Found in lib/cc/yaml/serializer/generic.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 accept_mapping has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def accept_mapping(node, value)
        case value.tag
        when MAP, OMAP, PAIRS then node.visit_mapping  self, value
        when SET              then node.visit_sequence self, SetNode.new(value)
        when SEQ              then node.visit_sequence self, value
Severity: Minor
Found in lib/cc/yaml/parser/psych.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 generate_key has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def generate_key(node, value)
        if value.respond_to? :value and (value.tag.nil? || value.tag == STR)
          value = value.value.to_s
          value.start_with?(?:) ? value[1..-1] : value
        else
Severity: Minor
Found in lib/cc/yaml/parser/psych.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 prefix_scalar has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def self.prefix_scalar(key = nil, *types)
        @prefix_scalar ||= superclass.respond_to?(:prefix_scalar) ? superclass.prefix_scalar : nil
        if key
          @prefix_scalar = key.to_s
          define_method(:visit_scalar) do |visitor, type, value, _implicit = true|
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.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 verify_required has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def verify_required
        self.class.required.each do |key|
          next if @mapping.include? key
          type = self.class.subnode_for_key(key)
          if type.has_default?
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.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 parses? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def self.parses?(value)
        return true if value.is_a?(::Psych::Nodes::Node)
        return true if value.is_a?(String) or value.is_a?(IO)
        return true if defined?(StringIO) and value.is_a?(StringIO)
        value.respond_to?(:to_str) or value.respond_to?(:to_io)
Severity: Minor
Found in lib/cc/yaml/parser/psych.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 lines has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def lines(wrapper, lines)
        return wrapper % lines.join(",") unless pretty?
        return wrapper % "" if lines.empty?
        return wrapper % " #{lines.first} " unless lines.size > 1 or  lines.first.include?("\n") or lines.first.size > 50
        lines = "\n  " + lines.join(",\n").strip.gsub("\n", "\n  ") + "\n"
Severity: Minor
Found in lib/cc/yaml/serializer/json.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 regexp has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def regexp(pattern)
        return pattern if pattern.is_a? Regexp
        return Regexp.new(pattern) unless pattern =~ FORMATS["!regexp"]
        flag = $2.chars.inject(0) { |f,c| f | REG_FLAGS.fetch(c, 0) }
        Regexp.new($1, flag)
Severity: Minor
Found in lib/cc/yaml/parser/psych.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 map has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def self.map(*list)
        options = Hash === list.last ? list.pop : {}
        list.each do |key|
          required     << key.to_s if options[:required]
          define_map_accessor(key)
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.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 define_map_accessor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

      def self.define_map_accessor(key)
        define_method(key)       { | | self[key]       } unless method_defined? key
        define_method("#{key}=") { |v| self[key] = v   } unless method_defined? "#{key}="
        define_method("#{key}?") { | | !!self[key]     } unless method_defined? "#{key}?"
      end
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.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

Avoid the use of the case equality operator ===.
Open

        options = Hash === list.last ? list.pop : {}
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.rb by rubocop

This cop checks for uses of the case equality operator(===).

Example:

# bad
Array === something
(1..100) === 7
/something/ === some_string

# good
something.is_a?(Array)
(1..100).include?(7)
some_string =~ /something/

Use the return of the conditional for variable assignment and comparison.
Open

          if message
            message = message << ". #{GENERIC_ERROR_MESSAGE}"
          else
            message = GENERIC_ERROR_MESSAGE
          end
Severity: Minor
Found in lib/cc/yaml/nodes/engine_list.rb by rubocop

Unused method argument - key. If it's necessary, use _ or _key as an argument name to indicate that it won't be used. You can also write as accept_key?(*) if you want the method to accept any arguments but don't care about them.
Open

      def accept_key?(key)
Severity: Minor
Found in lib/cc/yaml/nodes/open_mapping.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

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

        def visit_pair(visitor, key, value)
Severity: Minor
Found in lib/cc/yaml/nodes/node.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

Duplicate when condition detected.
Open

        when NULL      then node.visit_scalar self, :null,   value, value.tag.nil?
Severity: Minor
Found in lib/cc/yaml/parser/psych.rb by rubocop

This cop checks that there are no repeated conditions used in case 'when' expressions.

Example:

# bad

case x
when 'first'
  do_something
when 'first'
  do_something_else
end

Example:

# good

case x
when 'first'
  do_something
when 'second'
  do_something_else
end

Use || instead of or.
Open

        value.respond_to?(:to_str) or value.respond_to?(:to_io)
Severity: Minor
Found in lib/cc/yaml/parser/psych.rb by rubocop

This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

Example: EnforcedStyle: always (default)

# bad
foo.save and return

# bad
if foo and bar
end

# good
foo.save && return

# good
if foo && bar
end

Example: EnforcedStyle: conditionals

# bad
if foo and bar
end

# good
foo.save && return

# good
foo.save and return

# good
if foo && bar
end

Inconsistent indentation detected.
Open

      def serialize_str(value)
        string = value.encode("utf-8")
        string.force_encoding("binary")
        string.gsub!(/["\\\x0-\x1f]/) { MAP[$&] }
        string.force_encoding("utf-8")
Severity: Minor
Found in lib/cc/yaml/serializer/json.rb by rubocop

This cops checks for inconsistent indentation.

Example:

class A
  def test
    puts 'hello'
     puts 'world'
  end
end

Favor format over String#%.
Open

          else raise ArgumentError, "unexpected value for to: %p" % options[:to]
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.rb by rubocop

This cop enforces the use of a single string formatting utility. Valid options include Kernel#format, Kernel#sprintf and String#%.

The detection of String#% cannot be implemented in a reliable manner for all cases, so only two scenarios are considered - if the first argument is a string literal and if the second argument is an array literal.

Example: EnforcedStyle: format(default)

# bad
puts sprintf('%10s', 'hoge')
puts '%10s' % 'hoge'

# good
puts format('%10s', 'hoge')

Example: EnforcedStyle: sprintf

# bad
puts format('%10s', 'hoge')
puts '%10s' % 'hoge'

# good
puts sprintf('%10s', 'hoge')

Example: EnforcedStyle: percent

# bad
puts format('%10s', 'hoge')
puts sprintf('%10s', 'hoge')

# good
puts '%10s' % 'hoge'
Severity
Category
Status
Source
Language