reevoo/sapience-rb

View on GitHub

Showing 1,401 of 1,401 total issues

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

      def call(log, _logger) # rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity
        # Date & time
        message = time_format.nil? ? "" : "#{format_time(log.time)} "

        # Log level and process info
Severity: Minor
Found in lib/sapience/formatters/default.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

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

    def each_exception # rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity
      # With thanks to https://github.com/bugsnag/bugsnag-ruby/blob/6348306e44323eee347896843d16c690cd7c4362/lib/bugsnag/notification.rb#L81
      depth      = 0
      exceptions = []
      ex         = exception
Severity: Minor
Found in lib/sapience/log.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

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

        def record(event) # rubocop:disable AbcSize, CyclomaticComplexity, PerceivedComplexity
          return unless record?

          payload = event.payload
          name    = payload[:name]
Severity: Minor
Found in lib/sapience/extensions/active_record/notifications.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

Method log_with_level has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def log_with_level(level, message = nil, payload = nil, exception = nil, &block)
Severity: Minor
Found in lib/sapience/log_methods.rb - About 35 mins to fix

    Method log_with_exception has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def log_with_exception(level, message = nil, payload = nil, exception = nil, &block)
    Severity: Minor
    Found in lib/sapience/log_methods.rb - About 35 mins to fix

      Method log_internal has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def log_internal(level, index, message = nil, payload = nil, exception = nil)
      Severity: Minor
      Found in lib/sapience/base.rb - About 35 mins to fix

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

          def self.constantize(class_name)
            return class_name unless class_name.is_a?(String)
            if RUBY_VERSION.to_i >= 2
              Object.const_get(class_name)
            else
        Severity: Minor
        Found in lib/sapience/sapience.rb - About 35 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

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

          module Extensions
            module Grape
              module Timings
                extend self
        
        
        Severity: Minor
        Found in lib/sapience/extensions/grape/timings.rb and 1 other location - About 25 mins to fix
        lib/sapience/extensions/sinatra/timings.rb on lines 3..21

        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 31.

        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

          module Extensions
            module Sinatra
              module Timings
                extend self
        
        
        Severity: Minor
        Found in lib/sapience/extensions/sinatra/timings.rb and 1 other location - About 25 mins to fix
        lib/sapience/extensions/grape/timings.rb on lines 3..21

        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 31.

        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 record has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

                def record(event) # rubocop:disable AbcSize
                  return unless record?
        
                  payload = event.payload
                  method  = payload[:method].downcase
        Severity: Minor
        Found in lib/sapience/extensions/action_controller/notifications.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

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

            def duration_to_s
              return unless duration
              format((duration < 10.0 ? "%.3fms" : "%.1fms"), duration)
            end
        Severity: Minor
        Found in lib/sapience/log.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

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

              def yaml_safe_load(yaml_code, filename)
                if YAML.respond_to?(:safe_load) # Ruby 2.1+
                  if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
                    SafeYAML.load(yaml_code, filename,
                      whitelisted_tags: %w(!ruby/regexp),
        Severity: Minor
        Found in lib/sapience/config_loader.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

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

                def self.included(base) # rubocop:disable AbcSize
                  base.extend(ClassMethods)
                  base.class_eval do
                    const_set(:SAPIENCE_MODEL_CREATE_METRICS_KEY,  "model.#{tableized_name}.create")
                    const_set(:SAPIENCE_MODEL_UPDATE_METRICS_KEY,  "model.#{tableized_name}.update")
        Severity: Minor
        Found in lib/sapience/extensions/active_record/model_metrics.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

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

          def self.namify(appname, sep = "_")
            return unless appname.is_a?(String)
            return if appname.empty?
        
            # Turn unwanted chars into the separator
        Severity: Minor
        Found in lib/sapience/sapience.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

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

            def backtrace_to_s
              trace = ""
              each_exception do |exception, i|
                if i == 0
                  trace += (exception.backtrace || []).join("\n")
        Severity: Minor
        Found in lib/sapience/log.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

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

          task :merge do
            hide_coverage_config
            require "json"
            require "simplecov/version"
            require "simplecov/result"
        Severity: Minor
        Found in lib/tasks/coverage.rake 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.

        Line is too long. [86/80]
        Open

        # from scratch. The latter is a flawed and unsustainable approach (the more migrations
        Severity: Minor
        Found in test_apps/rails_4_2/db/schema.rb by rubocop

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

          gem "test-unit"
        Severity: Minor
        Found in test_apps/rails_4_2/Gemfile by rubocop

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Prefer single-quoted strings when you don't need string interpolation or special symbols.
        Open

        Rails.application.config.session_store :cookie_store, key: "_rails_4_2_session"

        Checks if uses of quotes match the configured preference.

        Example: EnforcedStyle: single_quotes (default)

        # bad
        "No special symbols"
        "No string interpolation"
        "Just text"
        
        # good
        'No special symbols'
        'No string interpolation'
        'Just text'
        "Wait! What's #{this}!"

        Example: EnforcedStyle: double_quotes

        # bad
        'Just some text'
        'No special chars or interpolation'
        
        # good
        "Just some text"
        "No special chars or interpolation"
        "Every string in #{project} uses double_quotes"

        Line is too long. [85/80]
        Open

          # Settings specified here will take precedence over those in config/application.rb.
        Severity
        Category
        Status
        Source
        Language