ManageIQ/more_core_extensions

View on GitHub

Showing 70 of 70 total issues

Method store_path has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

      def store_path(*args)
        raise ArgumentError, "must pass at least one key, and a value" if args.length < 2
        value = args.pop
        child = self
        key   = args.first
Severity: Minor
Found in lib/more_core_extensions/core_ext/shared/nested.rb - About 2 hrs 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 step_value has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def step_value(value)
      if block_given?
        return if self.begin > self.end

        iter = self.begin
Severity: Minor
Found in lib/more_core_extensions/core_ext/range/step_value.rb - About 2 hrs 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 cache_with_timeout has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def cache_with_timeout(method, timeout = nil, &block)
      raise "no block given" if block.nil?
      raise ArgumentError, "method must be a Symbol" unless method.respond_to?(:to_sym)

      key = "#{name}.#{method}".to_sym
Severity: Minor
Found in lib/more_core_extensions/core_ext/module/cache_with_timeout.rb - About 2 hrs 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 tabular_sort has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def tabular_sort(col_names = nil, order = nil, &block)
      # stabilizer is needed because of
      # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170565
      stabilizer = 0
      nil_rows, sortable =
Severity: Minor
Found in lib/more_core_extensions/core_ext/array/sorting.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 cache_with_timeout has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def cache_with_timeout(method, timeout = nil, &block)
      raise "no block given" if block.nil?
      raise ArgumentError, "method must be a Symbol" unless method.respond_to?(:to_sym)

      key = "#{name}.#{method}".to_sym
Severity: Minor
Found in lib/more_core_extensions/core_ext/module/cache_with_timeout.rb - About 1 hr to fix

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

          def delete_path(*args)
            args = args.first if args.length == 1 && args.first.kind_of?(Array)
            raise ArgumentError, "must pass at least one key" if args.empty?
    
            key = args.first
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/shared/nested.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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        if Gem.win_platform?
          def pause(pid)
            return unless alive?(pid)
    
            begin
    Severity: Major
    Found in lib/more_core_extensions/core_ext/process/pause_resume.rb and 1 other location - About 1 hr to fix
    lib/more_core_extensions/core_ext/process/pause_resume.rb on lines 83..104

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        if Gem.win_platform?
          def resume(pid)
            return unless alive?(pid)
    
            begin
    Severity: Major
    Found in lib/more_core_extensions/core_ext/process/pause_resume.rb and 1 other location - About 1 hr to fix
    lib/more_core_extensions/core_ext/process/pause_resume.rb on lines 56..77

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 52.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Method realtime_block has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def realtime_block(key, &block)
          hash = current_realtime
    
          if in_realtime_block?
            ret = realtime_store(hash, key, &block)
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/benchmark/realtime_store.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 find_path has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

          def find_path(val)
            self.each_with_index do |v, k|
              k, v = v if self.kind_of?(Hash)
              return [k] if v == val
    
    
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/shared/nested.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 ansi_truncate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def ansi_truncate(field, width)
            escapes = ansi_escapes(field)
            if escapes.none?
              field.slice(0, width)
            else
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/array/tableize.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

    Method pause has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def pause(pid)
            return unless alive?(pid)
    
            begin
              handle = OpenProcess.call(PROCESS_SUSPEND_RESUME, 0, pid)
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/process/pause_resume.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

    Method resume has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def resume(pid)
            return unless alive?(pid)
    
            begin
              handle = OpenProcess.call(PROCESS_SUSPEND_RESUME, 0, pid)
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/process/pause_resume.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

    Method has_key_path? has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def has_key_path?(*args)
            args = args.first if args.length == 1 && args.first.kind_of?(Array)
            raise ArgumentError, "must pass at least one key" if args.empty?
    
            key = args.first
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/shared/nested.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

    Method fetch_path has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def fetch_path(*args)
            args = args.first if args.length == 1 && args.first.kind_of?(Array)
            raise ArgumentError, "must pass at least one key" if args.empty?
    
            result = self
    Severity: Minor
    Found in lib/more_core_extensions/core_ext/shared/nested.rb - About 45 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

    Use include MoreCoreExtensions::ArrayDeletes instead of send(:include, MoreCoreExtensions::ArrayDeletes).
    Open

    Array.send(:include, MoreCoreExtensions::ArrayDeletes)

    Checks for send, public_send, and __send__ methods when using mix-in.

    include and prepend methods were private methods until Ruby 2.0, they were mixed-in via send method. This cop uses Ruby 2.1 or higher style that can be called by public methods. And extend method that was originally a public method is also targeted for style unification.

    Example:

    # bad
    Foo.send(:include, Bar)
    Foo.send(:prepend, Bar)
    Foo.send(:extend, Bar)
    
    # bad
    Foo.public_send(:include, Bar)
    Foo.public_send(:prepend, Bar)
    Foo.public_send(:extend, Bar)
    
    # bad
    Foo.__send__(:include, Bar)
    Foo.__send__(:prepend, Bar)
    Foo.__send__(:extend, Bar)
    
    # good
    Foo.include Bar
    Foo.prepend Bar
    Foo.extend Bar

    Use include MoreCoreExtensions::StableSorting instead of send(:include, MoreCoreExtensions::StableSorting).
    Open

    Array.send(:include, MoreCoreExtensions::StableSorting)

    Checks for send, public_send, and __send__ methods when using mix-in.

    include and prepend methods were private methods until Ruby 2.0, they were mixed-in via send method. This cop uses Ruby 2.1 or higher style that can be called by public methods. And extend method that was originally a public method is also targeted for style unification.

    Example:

    # bad
    Foo.send(:include, Bar)
    Foo.send(:prepend, Bar)
    Foo.send(:extend, Bar)
    
    # bad
    Foo.public_send(:include, Bar)
    Foo.public_send(:prepend, Bar)
    Foo.public_send(:extend, Bar)
    
    # bad
    Foo.__send__(:include, Bar)
    Foo.__send__(:prepend, Bar)
    Foo.__send__(:extend, Bar)
    
    # good
    Foo.include Bar
    Foo.prepend Bar
    Foo.extend Bar

    Use include MoreCoreExtensions::ArrayTableize instead of send(:include, MoreCoreExtensions::ArrayTableize).
    Open

    Array.send(:include, MoreCoreExtensions::ArrayTableize)

    Checks for send, public_send, and __send__ methods when using mix-in.

    include and prepend methods were private methods until Ruby 2.0, they were mixed-in via send method. This cop uses Ruby 2.1 or higher style that can be called by public methods. And extend method that was originally a public method is also targeted for style unification.

    Example:

    # bad
    Foo.send(:include, Bar)
    Foo.send(:prepend, Bar)
    Foo.send(:extend, Bar)
    
    # bad
    Foo.public_send(:include, Bar)
    Foo.public_send(:prepend, Bar)
    Foo.public_send(:extend, Bar)
    
    # bad
    Foo.__send__(:include, Bar)
    Foo.__send__(:prepend, Bar)
    Foo.__send__(:extend, Bar)
    
    # good
    Foo.include Bar
    Foo.prepend Bar
    Foo.extend Bar

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

          delete_if { |k, v| v.nil? }

    Checks for unused block arguments.

    Example:

    # bad
    do_something do |used, unused|
      puts used
    end
    
    do_something do |bar|
      puts :foo
    end
    
    define_method(:foo) do |bar|
      puts :baz
    end
    
    # good
    do_something do |used, _unused|
      puts used
    end
    
    do_something do
      puts :foo
    end
    
    define_method(:foo) do |_bar|
      puts :baz
    end

    Example: IgnoreEmptyBlocks: true (default)

    # good
    do_something { |unused| }

    Example: IgnoreEmptyBlocks: false

    # bad
    do_something { |unused| }

    Example: AllowUnusedKeywordArguments: false (default)

    # bad
    do_something do |unused: 42|
      foo
    end

    Example: AllowUnusedKeywordArguments: true

    # good
    do_something do |unused: 42|
      foo
    end

    Wrap expressions with varying precedence with parentheses to avoid ambiguity.
    Open

            slope = (n * sum_xy - sum_x * sum_y) / (n * sum_x2 - sum_x.square)

    Looks for expressions containing multiple binary operators where precedence is ambiguous due to lack of parentheses. For example, in 1 + 2 * 3, the multiplication will happen before the addition, but lexically it appears that the addition will happen first.

    The cop does not consider unary operators (ie. !a or -b) or comparison operators (ie. a =~ b) because those are not ambiguous.

    NOTE: Ranges are handled by Lint/AmbiguousRange.

    Example:

    # bad
    a + b * c
    a || b && c
    a ** b + c
    
    # good (different precedence)
    a + (b * c)
    a || (b && c)
    (a ** b) + c
    
    # good (same precedence)
    a + b + c
    a * b / c % d
    Severity
    Category
    Status
    Source
    Language