johnbellone/rc-cookbook

View on GitHub
libraries/rc_file.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method to_content has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def to_content
        case type.to_sym
        when :edn
          require 'edn'
          options.to_edn
Severity: Minor
Found in libraries/rc_file.rb - About 1 hr to fix

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

          def to_content
            case type.to_sym
            when :edn
              require 'edn'
              options.to_edn
    Severity: Minor
    Found in libraries/rc_file.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

    Always use raise to signal exceptions.
    Open

            fail 'You cannot use append_if_missing on non-bash file types!' unless new_resource.type == 'bash'
    Severity: Minor
    Found in libraries/rc_file.rb by rubocop

    This cop checks for uses of fail and raise.

    Example: EnforcedStyle: only_raise (default)

    # The `only_raise` style enforces the sole use of `raise`.
    # bad
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      # handle it
    end
    
    Kernel.fail
    
    # good
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      raise
    rescue Exception
      # handle it
    end
    
    Kernel.raise

    Example: EnforcedStyle: only_fail

    # The `only_fail` style enforces the sole use of `fail`.
    # bad
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      raise
    rescue Exception
      # handle it
    end
    
    Kernel.raise
    
    # good
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      # handle it
    end
    
    Kernel.fail

    Example: EnforcedStyle: semantic

    # The `semantic` style enforces the use of `fail` to signal an
    # exception, then will use `raise` to trigger an offense after
    # it has been rescued.
    # bad
    begin
      raise
    rescue Exception
      # handle it
    end
    
    def watch_out
      # Error thrown
    rescue Exception
      fail
    end
    
    Kernel.fail
    Kernel.raise
    
    # good
    begin
      fail
    rescue Exception
      # handle it
    end
    
    def watch_out
      fail
    rescue Exception
      raise 'Preferably with descriptive message'
    end
    
    explicit_receiver.fail
    explicit_receiver.raise

    There are no issues that match your filters.

    Category
    Status