reevoo/sapience-rb

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

Summary

Maintainability
A
45 mins
Test Coverage

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

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

          payload = event.payload
          name    = payload[:name]

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

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

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

          Sapience::Extensions::Notifications.subscribe "sql.active_record" 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"

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

Line is too long. [89/80]
Open

        # *<tt>:metric_name</tt>      - the metric name, defaults to "activerecord.query"

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

          @metric_name     = opts[:metric_name] || "activerecord.sql"

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. [89/80]
Open

        # *<tt>:include_generic</tt>  - record general (nameless) queries, off by default

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

          return if (name.nil? || name == "SQL") && !@include_generic

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. [86/80]
Open

          Sapience::Extensions::Notifications.subscribe "sql.active_record" do |event|

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

          return if name == "SCHEMA" && !@include_schema

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. [94/80]
Open

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

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

          name = name.downcase.split(/\W/).join(".") if name

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"

There are no issues that match your filters.

Category
Status