am-kantox/kantox-chronoscope

View on GitHub

Showing 27 of 27 total issues

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 log_report has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def log_report(count)
        count = @@chronoscope_data.size if count <= 0

        delim_label = [" ⇓⇓ [#{LOGGER_TAG}] ⇓⇓ ", " ⇑⇑ [#{LOGGER_TAG}] ⇑⇑ "].map do |label|
          delim = '—' * ((log_width - label.length) / 2)
Severity: Minor
Found in lib/kantox/chronoscope/generic.rb - About 1 hr to fix

    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

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

            def ⌚(arg = DEFAULT_TAG, log = false)
              return (@@chronoscope_data[arg.to_s] = nil) unless block_given? # pass no block to reset
      
              result = nil # needed for it to be defined in this scope
              @@chronoscope_data[arg.to_s] ||= { count: 0, total: 0, stack: @@★.dup }
      Severity: Minor
      Found in lib/kantox/chronoscope/generic.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

      Use normalcase for variable numbers.
      Open

            @@★ = []
      Severity: Minor
      Found in lib/kantox/chronoscope/generic.rb by rubocop

      This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.

      Example: EnforcedStyle: snake_case

      # bad
      
      variable1 = 1
      
      # good
      
      variable_1 = 1

      Example: EnforcedStyle: normalcase (default)

      # bad
      
      variable_1 = 1
      
      # good
      
      variable1 = 1

      Example: EnforcedStyle: non_integer

      # bad
      
      variable1 = 1
      
      variable_1 = 1
      
      # good
      
      variableone = 1
      
      variable_one = 1

      Add an empty line after magic comments.
      Open

      lib = File.expand_path('../lib', __FILE__)
      Severity: Minor
      Found in kantox-chronoscope.gemspec by rubocop

      Checks for a newline after the final magic comment.

      Example:

      # good
      # frozen_string_literal: true
      
      # Some documentation for Person
      class Person
        # Some code
      end
      
      # bad
      # frozen_string_literal: true
      # Some documentation for Person
      class Person
        # Some code
      end

      Add an empty line after magic comments.
      Open

      require 'rubygems'
      Severity: Minor
      Found in Rakefile by rubocop

      Checks for a newline after the final magic comment.

      Example:

      # good
      # frozen_string_literal: true
      
      # Some documentation for Person
      class Person
        # Some code
      end
      
      # bad
      # frozen_string_literal: true
      # Some documentation for Person
      class Person
        # Some code
      end

      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

      Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency awesome_print should appear before pry.
      Open

        spec.add_development_dependency 'awesome_print', '~> 1'
      Severity: Minor
      Found in kantox-chronoscope.gemspec by rubocop

      Dependencies in the gemspec should be alphabetically sorted.

      Example:

      # bad
      spec.add_dependency 'rubocop'
      spec.add_dependency 'rspec'
      
      # good
      spec.add_dependency 'rspec'
      spec.add_dependency 'rubocop'
      
      # good
      spec.add_dependency 'rubocop'
      
      spec.add_dependency 'rspec'
      
      # bad
      spec.add_development_dependency 'rubocop'
      spec.add_development_dependency 'rspec'
      
      # good
      spec.add_development_dependency 'rspec'
      spec.add_development_dependency 'rubocop'
      
      # good
      spec.add_development_dependency 'rubocop'
      
      spec.add_development_dependency 'rspec'
      
      # bad
      spec.add_runtime_dependency 'rubocop'
      spec.add_runtime_dependency 'rspec'
      
      # good
      spec.add_runtime_dependency 'rspec'
      spec.add_runtime_dependency 'rubocop'
      
      # good
      spec.add_runtime_dependency 'rubocop'
      
      spec.add_runtime_dependency 'rspec'
      
      # good only if TreatCommentsAsGroupSeparators is true
      # For code quality
      spec.add_dependency 'rubocop'
      # For tests
      spec.add_dependency 'rspec'

      Avoid rescuing without specifying an error class.
      Open

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

      This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

      Example: EnforcedStyle: implicit

      # `implicit` will enforce using `rescue` instead of
      # `rescue StandardError`.
      
      # bad
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Example: EnforcedStyle: explicit (default)

      # `explicit` will enforce using `rescue StandardError`
      # instead of `rescue`.
      
      # bad
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency pry should appear before rspec.
      Open

        spec.add_development_dependency 'pry', '~> 0.10'
      Severity: Minor
      Found in kantox-chronoscope.gemspec by rubocop

      Dependencies in the gemspec should be alphabetically sorted.

      Example:

      # bad
      spec.add_dependency 'rubocop'
      spec.add_dependency 'rspec'
      
      # good
      spec.add_dependency 'rspec'
      spec.add_dependency 'rubocop'
      
      # good
      spec.add_dependency 'rubocop'
      
      spec.add_dependency 'rspec'
      
      # bad
      spec.add_development_dependency 'rubocop'
      spec.add_development_dependency 'rspec'
      
      # good
      spec.add_development_dependency 'rspec'
      spec.add_development_dependency 'rubocop'
      
      # good
      spec.add_development_dependency 'rubocop'
      
      spec.add_development_dependency 'rspec'
      
      # bad
      spec.add_runtime_dependency 'rubocop'
      spec.add_runtime_dependency 'rspec'
      
      # good
      spec.add_runtime_dependency 'rspec'
      spec.add_runtime_dependency 'rubocop'
      
      # good
      spec.add_runtime_dependency 'rubocop'
      
      spec.add_runtime_dependency 'rspec'
      
      # good only if TreatCommentsAsGroupSeparators is true
      # For code quality
      spec.add_dependency 'rubocop'
      # For tests
      spec.add_dependency 'rspec'

      Avoid rescuing without specifying an error class.
      Open

            rescue
      Severity: Minor
      Found in lib/kantox/chronoscope/generic.rb by rubocop

      This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

      Example: EnforcedStyle: implicit

      # `implicit` will enforce using `rescue` instead of
      # `rescue StandardError`.
      
      # bad
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      end

      Example: EnforcedStyle: explicit (default)

      # `explicit` will enforce using `rescue StandardError`
      # instead of `rescue`.
      
      # bad
      begin
        foo
      rescue
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError
        bar
      end
      
      # good
      begin
        foo
      rescue OtherError
        bar
      end
      
      # good
      begin
        foo
      rescue StandardError, SecurityError
        bar
      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

      Unnecessary utf-8 encoding comment.
      Open

      # encoding: UTF-8
      Severity: Minor
      Found in Rakefile by rubocop

      Use warn instead of $stderr.puts to allow such output to be disabled.
      Open

        $stderr.puts e.message
      Severity: Minor
      Found in Rakefile by rubocop

      This cop identifies places where $stderr.puts can be replaced by warn. The latter has the advantage of easily being disabled by, e.g. the -W0 interpreter flag, or setting $VERBOSE to nil.

      Example:

      # bad
      $stderr.puts('hello')
      
      # good
      warn('hello')

      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

      Use warn instead of $stderr.puts to allow such output to be disabled.
      Open

        $stderr.puts 'Run `bundle install` to install missing gems'
      Severity: Minor
      Found in Rakefile by rubocop

      This cop identifies places where $stderr.puts can be replaced by warn. The latter has the advantage of easily being disabled by, e.g. the -W0 interpreter flag, or setting $VERBOSE to nil.

      Example:

      # bad
      $stderr.puts('hello')
      
      # good
      warn('hello')

      Do not place comments on the same line as the def keyword.
      Open

            def ⌛(cleanup: true, count: 18, log: true) # Yes, 18 is my fave number)
      Severity: Minor
      Found in lib/kantox/chronoscope/generic.rb by rubocop

      This cop checks for comments put on the same line as some keywords. These keywords are: begin, class, def, end, module.

      Note that some comments (such as :nodoc: and rubocop:disable) are allowed.

      Example:

      # bad
      if condition
        statement
      end # end if
      
      # bad
      class X # comment
        statement
      end
      
      # bad
      def x; end # comment
      
      # good
      if condition
        statement
      end
      
      # good
      class X # :nodoc:
        y
      end

      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

      Unnecessary utf-8 encoding comment.
      Open

      # coding: utf-8
      Severity: Minor
      Found in kantox-chronoscope.gemspec by rubocop
      Severity
      Category
      Status
      Source
      Language