codeclimate/codeclimate-yaml

View on GitHub
lib/cc/yaml/nodes/mapping.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Class has too many lines. [170/100]
Open

    class Mapping < Node
      INCOMPATIBLE_KEYS_WARNING = "Use either a languages key or an engines key, but not both. They are mutually exclusive.".freeze

      def self.mapping
        @mapping ||= superclass.respond_to?(:mapping) ? superclass.mapping.dup : {}
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class Mapping has 33 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Mapping < Node
      INCOMPATIBLE_KEYS_WARNING = "Use either a languages key or an engines key, but not both. They are mutually exclusive.".freeze

      def self.mapping
        @mapping ||= superclass.respond_to?(:mapping) ? superclass.mapping.dup : {}
Severity: Minor
Found in lib/cc/yaml/nodes/mapping.rb - About 4 hrs to fix

    Method has too many lines. [11/10]
    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 by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    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 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/

    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'

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

                error "missing key %p", key
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Unnecessary spacing detected.
    Open

              required     << key.to_s if options[:required]
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop checks for extra/unnecessary whitespace.

    Example:

    # good if AllowForAlignment is true
    name      = "RuboCop"
    # Some comment and an empty line
    
    website  += "/bbatsov/rubocop" unless cond
    puts        "rubocop"          if     debug
    
    # bad for any configuration
    set_app("RuboCop")
    website  = "https://github.com/bbatsov/rubocop"

    Use nested module/class definitions instead of compact style.
    Open

    module CC::Yaml
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop checks the style of children definitions at classes and modules. Basically there are two different styles:

    Example: EnforcedStyle: nested (default)

    # good
    # have each child on its own line
    class Foo
      class Bar
      end
    end

    Example: EnforcedStyle: compact

    # good
    # combine definitions as much as possible
    class Foo::Bar
    end

    The compact style is only forced for classes/modules with one child.

    Use && instead of and.
    Open

            if other.respond_to? :to_hash and other.to_hash.size == @mapping.size
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.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

    Use && instead of and.
    Open

              other.to_hash.all? { |k, v| include?(k) and self[k] == v }
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.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

    Avoid the use of double negation (!!).
    Open

            define_method("#{key}?") { | | !!self[key]     } unless method_defined? "#{key}?"
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop checks for uses of double negation (!!) to convert something to a boolean value. As this is both cryptic and usually redundant, it should be avoided.

    Example:

    # bad
    !!something
    
    # good
    !something.nil?

    Please, note that when something is a boolean value !!something and !something.nil? are not the same thing. As you're unlikely to write code that can accept values of any type this is rarely a problem in practice.

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

                error "invalid %p section: %s", key, value.errors.join(", ")
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

                warning "missing key %p, defaulting to %p", key, type.default
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Useless assignment to variable - list.
    Open

              list = value.nested_warnings(*prefix, key) + list
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

    assigned but unused variable - foo

    Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

    Example:

    # bad
    
    def some_method
      some_var = 1
      do_something
    end

    Example:

    # good
    
    def some_method
      some_var = 1
      do_something(some_var)
    end

    Use alias instead of alias_method in a class body.
    Open

          alias_method :__getobj__, :mapping
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

    Example: EnforcedStyle: prefer_alias (default)

    # bad
    alias_method :bar, :foo
    alias :bar :foo
    
    # good
    alias bar foo

    Example: EnforcedStyle: preferaliasmethod

    # bad
    alias :bar :foo
    alias bar foo
    
    # good
    alias_method :bar, :foo

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

              warning("unexpected key %p, dropping", key)
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

              warning("unexpected key %p, dropping", key)
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Omit pipes for the empty block parameters.
    Open

            define_method(key)       { | | self[key]       } unless method_defined? key
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop checks for pipes for empty block parameters. Pipes for empty block parameters do not cause syntax errors, but they are redundant.

    Example:

    # bad
    a do ||
      do_something
    end
    
    # bad
    a { || do_something }
    
    # good
    a do
    end
    
    # good
    a { do_something }

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

                warning "missing key %p, defaulting to %p", key, type.default
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Operator << should be surrounded by a single space.
    Open

              required     << key.to_s if options[:required]
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Checks that operators have space around them, except for ** which should not have surrounding space.

    Example:

    # bad
    total = 3*4
    "apple"+"juice"
    my_number = 38/4
    a ** b
    
    # good
    total = 3 * 4
    "apple" + "juice"
    my_number = 38 / 4
    a**b

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

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

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

                error "invalid %p section: %s", key, value.errors.join(", ")
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Prefer annotated tokens (like %<foo>s</foo>) over unannotated tokens (like %s).
    Open

            warning("has multiple %p entries, keeping last entry", key) if self[key]
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    Use a consistent style for named format string tokens.

    Note: unannotated style cop only works for strings which are passed as arguments to those methods: sprintf, format, %. The reason is that unannotated format is very similar to encoded URLs or Date/Time formatting strings.

    Example: EnforcedStyle: annotated (default)

    # bad
    format('%{greeting}', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%<greeting>s', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: template

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%s', 'Hello')
    
    # good
    format('%{greeting}', greeting: 'Hello')</greeting>

    Example: EnforcedStyle: unannotated

    # bad
    format('%<greeting>s', greeting: 'Hello')
    format('%{greeting}', 'Hello')
    
    # good
    format('%s', 'Hello')</greeting>

    Omit pipes for the empty block parameters.
    Open

            define_method("#{key}?") { | | !!self[key]     } unless method_defined? "#{key}?"
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop checks for pipes for empty block parameters. Pipes for empty block parameters do not cause syntax errors, but they are redundant.

    Example:

    # bad
    a do ||
      do_something
    end
    
    # bad
    a { || do_something }
    
    # good
    a do
    end
    
    # good
    a { do_something }

    Use == if you meant to do a comparison or wrap the expression in parentheses to indicate you meant to assign in a condition.
    Open

            if mapped_key = mapped_key(key)
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop checks for assignments in the conditions of if/while/until.

    Example:

    # bad
    
    if some_var = true
      do_something
    end

    Example:

    # good
    
    if some_var == true
      do_something
    end

    Shadowing outer local variable - value.
    Open

            value.each { |key, value| self[key] = value }
    Severity: Minor
    Found in lib/cc/yaml/nodes/mapping.rb by rubocop

    This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

    Example:

    # bad
    
    def some_method
      foo = 1
    
      2.times do |foo| # shadowing outer `foo`
        do_something(foo)
      end
    end

    Example:

    # good
    
    def some_method
      foo = 1
    
      2.times do |bar|
        do_something(bar)
      end
    end

    There are no issues that match your filters.

    Category
    Status