reevoo/sapience-rb

View on GitHub
lib/sapience/extensions/action_controller/notifications.rb

Summary

Maintainability
A
25 mins
Test Coverage

Method has too many lines. [22/10]
Open

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

          payload = event.payload
          method  = payload[:method].downcase

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

Missing top-level class documentation comment.
Open

      class Notifications < ::Sapience::Extensions::Notifications

This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

Example:

# bad
class Person
  # ...
end

# good
# Description/Explanation of Person class
class Person
  # ...
end

Extra blank line detected.
Open


            if payload[:view_runtime]

This cops checks for two or more consecutive blank lines.

Example:

# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method

# good
some_method
# one empty line
some_method

Line is too long. [120/80]
Open

            metrics.timing("#{metric_name}.time.db", payload[:db_runtime].round(10), tags: tags) if payload[:db_runtime]

%W-literals should be delimited by [ and ].
Open

          tags    = self.tags + %W(
            method:#{method}
            status:#{status}
            action:#{action}
            controller:#{ctrl}

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

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

          @metric_name = options[:metric_name] || "rails.request"

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

          ctrl    = payload[:controller].sub(/Controller$/, "").underscore

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"

Extra blank line detected.
Open



This cops checks for two or more consecutive blank lines.

Example:

# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method

# good
some_method
# one empty line
some_method

Line is too long. [102/80]
Open

          Sapience::Extensions::Notifications.subscribe("process_action.action_controller") do |event|

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

          Sapience::Extensions::Notifications.subscribe("process_action.action_controller") do |event|

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"

Add an empty line after magic comments.
Open

module Sapience

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

Line is too long. [101/80]
Open

              metrics.timing("#{metric_name}.time.view", payload[:view_runtime].round(2), tags: tags)

There are no issues that match your filters.

Category
Status