bloomberg/collectd-cookbook

View on GitHub

Showing 7 of 7 total issues

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

      def write_elements(directives, indent = 0)
        tabs = ("\t" * indent)
        directives.dup.map do |key, value|
          next if value.nil?
          key = snake_to_camel(key)
Severity: Minor
Found in libraries/collectd_config.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 action_enable has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def action_enable
        notifying_block do
          # TODO: (jbellone) Fix the package resource for AIX so that
          # it is able to install from a URL.
          package_path = if new_resource.package_source
Severity: Minor
Found in libraries/collectd_service.rb - About 1 hr to fix

    Block has too many lines. [38/25]
    Open

            notifying_block do
              # TODO: (jbellone) Fix the package resource for AIX so that
              # it is able to install from a URL.
              package_path = if new_resource.package_source
                               url = new_resource.package_source % { version: new_resource.package_version }
    Severity: Minor
    Found in libraries/collectd_service.rb by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

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

          def action_enable
            notifying_block do
              # TODO: (jbellone) Fix the package resource for AIX so that
              # it is able to install from a URL.
              package_path = if new_resource.package_source
    Severity: Minor
    Found in libraries/collectd_service.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

    Use %i or %I for an array of symbols.
    Open

                action [:disable, :stop]
    Severity: Minor
    Found in libraries/collectd_service.rb by rubocop

    This cop can check for array literals made up of symbols that are not using the %i() syntax.

    Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

    Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

    Example: EnforcedStyle: percent (default)

    # good
    %i[foo bar baz]
    
    # bad
    [:foo, :bar, :baz]

    Example: EnforcedStyle: brackets

    # good
    [:foo, :bar, :baz]
    
    # bad
    %i[foo bar baz]

    Closing array brace must be on the same line as the last array element when opening brace is on the same line as the first array element.
    Open

                ].join("\n")
    Severity: Minor
    Found in libraries/collectd_config.rb by rubocop

    This cop checks that the closing brace in an array literal is either on the same line as the last array element, or a new line.

    When using the symmetrical (default) style:

    If an array's opening brace is on the same line as the first element of the array, then the closing brace should be on the same line as the last element of the array.

    If an array's opening brace is on the line above the first element of the array, then the closing brace should be on the line below the last element of the array.

    When using the new_line style:

    The closing brace of a multi-line array literal must be on the line after the last element of the array.

    When using the same_line style:

    The closing brace of a multi-line array literal must be on the same line as the last element of the array.

    Example: EnforcedStyle: symmetrical (default)

    # bad
      [ :a,
        :b
      ]
    
      # bad
      [
        :a,
        :b ]
    
      # good
      [ :a,
        :b ]
    
      # good
      [
        :a,
        :b
      ]

    Example: EnforcedStyle: new_line

    # bad
      [
        :a,
        :b ]
    
      # bad
      [ :a,
        :b ]
    
      # good
      [ :a,
        :b
      ]
    
      # good
      [
        :a,
        :b
      ]

    Example: EnforcedStyle: same_line

    # bad
      [ :a,
        :b
      ]
    
      # bad
      [
        :a,
        :b
      ]
    
      # good
      [
        :a,
        :b ]
    
      # good
      [ :a,
        :b ]

    Favor format over String#%.
    Open

                               url = new_resource.package_source % { version: new_resource.package_version }
    Severity: Minor
    Found in libraries/collectd_service.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