am-kantox/kantox-chronoscope

View on GitHub
lib/kantox/chronoscope.rb

Summary

Maintainability
C
1 day
Test Coverage

Method attach has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
Open

      def attach(klazz, *methods, cms: nil)
        klazz = Kernel.const_get(klazz) unless klazz.is_a?(Class)
        methods = klazz.instance_methods(false) if methods.empty?
        do_log = !option(ENV, 'options.silent')

Severity: Minor
Found in lib/kantox/chronoscope.rb - About 7 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 attach has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def attach(klazz, *methods, cms: nil)
        klazz = Kernel.const_get(klazz) unless klazz.is_a?(Class)
        methods = klazz.instance_methods(false) if methods.empty?
        do_log = !option(ENV, 'options.silent')

Severity: Minor
Found in lib/kantox/chronoscope.rb - About 1 hr to fix

    FIXME found
    Open

        kungfuig(File.join(File.expand_path('..', __FILE__), CONFIG_LOCATION)) rescue nil # FIXME: report
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by fixme

    FIXME found
    Open

                          # FIXME: Log this error
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by fixme

    FIXME found
    Open

              next if (klazz.instance_method(m).parameters.to_h[:block] rescue false) # FIXME: report
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by fixme

    FIXME found
    Open

        kungfuig(CONFIG_LOCATION) rescue nil # FIXME: report
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by fixme

    FIXME found
    Open

              next if (klazz.instance_method(m).parameters.to_h[:block] rescue false) # FIXME: report
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by fixme

    TODO found
    Open

          #  TODO: Permit monitoring of private methods
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by fixme

    Extra empty line detected before the rescue.
    Open

    
          rescue NameError => e
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by rubocop

    This cops checks if empty lines exist around the bodies of begin sections. This cop doesn't check empty lines at begin body beginning/end and around method definition body. Style/EmptyLinesAroundBeginBody or Style/EmptyLinesAroundMethodBody can be used for this purpose.

    Example:

    # good
    
    begin
      do_something
    rescue
      do_something2
    else
      do_something3
    ensure
      do_something4
    end
    
    # good
    
    def foo
      do_something
    rescue
      do_something2
    end
    
    # bad
    
    begin
      do_something
    
    rescue
    
      do_something2
    
    else
    
      do_something3
    
    ensure
    
      do_something4
    end
    
    # bad
    
    def foo
      do_something
    
    rescue
    
      do_something2
    end

    Pass __FILE__ and __LINE__ to eval method, as they are used by backtraces.
    Open

              klazz.class_eval %Q|
                alias_method :'#{CHAIN_PREFIX}#{m}', :'#{m}'
                def #{m}(#{arg_string})
                  ⌚('#{klazz}##{m}', #{do_log}) { #{receiver}#{CHAIN_PREFIX}#{m} #{arg_string} }
                end
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by rubocop

    This cop checks eval method usage. eval can receive source location metadata, that are filename and line number. The metadata is used by backtraces. This cop recommends to pass the metadata to eval method.

    Example:

    # bad
    eval <<-RUBY
      def do_something
      end
    RUBY
    
    # bad
    C.class_eval <<-RUBY
      def do_something
      end
    RUBY
    
    # good
    eval <<-RUBY, binding, __FILE__, __LINE__ + 1
      def do_something
      end
    RUBY
    
    # good
    C.class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def do_something
      end
    RUBY

    Pass __FILE__ and __LINE__ to eval method, as they are used by backtraces.
    Open

              klazz.class_eval %Q|
                class << self
                  alias_method :'#{CHAIN_PREFIX}#{m}', :'#{m}'
                  def #{m}(*args)
                    ⌚('#{klazz}::#{m}', #{do_log}) { #{klazz}.#{CHAIN_PREFIX}#{m} *args }
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by rubocop

    This cop checks eval method usage. eval can receive source location metadata, that are filename and line number. The metadata is used by backtraces. This cop recommends to pass the metadata to eval method.

    Example:

    # bad
    eval <<-RUBY
      def do_something
      end
    RUBY
    
    # bad
    C.class_eval <<-RUBY
      def do_something
      end
    RUBY
    
    # good
    eval <<-RUBY, binding, __FILE__, __LINE__ + 1
      def do_something
      end
    RUBY
    
    # good
    C.class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def do_something
      end
    RUBY

    Omit parentheses for ternary conditions.
    Open

              receiver, arg_string = (m.to_s =~ /[^\p{L}?]\z/) ? ['self.', 'arg'] : [nil, '*args'] # to satisfy setter
    Severity: Minor
    Found in lib/kantox/chronoscope.rb by rubocop

    This cop checks for the presence of parentheses around ternary conditions. It is configurable to enforce inclusion or omission of parentheses using EnforcedStyle. Omission is only enforced when removing the parentheses won't cause a different behavior.

    Example: EnforcedStyle: requirenoparentheses (default)

    # bad
    foo = (bar?) ? a : b
    foo = (bar.baz?) ? a : b
    foo = (bar && baz) ? a : b
    
    # good
    foo = bar? ? a : b
    foo = bar.baz? ? a : b
    foo = bar && baz ? a : b

    Example: EnforcedStyle: require_parentheses

    # bad
    foo = bar? ? a : b
    foo = bar.baz? ? a : b
    foo = bar && baz ? a : b
    
    # good
    foo = (bar?) ? a : b
    foo = (bar.baz?) ? a : b
    foo = (bar && baz) ? a : b

    Example: EnforcedStyle: requireparentheseswhen_complex

    # bad
    foo = (bar?) ? a : b
    foo = (bar.baz?) ? a : b
    foo = bar && baz ? a : b
    
    # good
    foo = bar? ? a : b
    foo = bar.baz? ? a : b
    foo = (bar && baz) ? a : b

    There are no issues that match your filters.

    Category
    Status