efigence/has_reindexable_associations

View on GitHub

Showing 22 of 22 total issues

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

  included do
    after_commit :reindex_associations

    private

Severity: Minor
Found in lib/has_reindexable_associations.rb 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.

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

    def reindex_associations_describe_old_polymorphic_association(key, type)
      if (previous_changes[key] && previous_changes[key].first) || (previous_changes[type] && previous_changes[type].first)
        old_klass = previous_changes[type].first rescue NameError
        send(type).constantize if old_klass == NameError # old_klass
      end
Severity: Minor
Found in lib/has_reindexable_associations.rb - About 2 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

Assignment Branch Condition size for reindex_associations_describe_old_polymorphic_association is too high. [17.49/15]
Open

    def reindex_associations_describe_old_polymorphic_association(key, type)
      if (previous_changes[key] && previous_changes[key].first) || (previous_changes[type] && previous_changes[type].first)
        old_klass = previous_changes[type].first rescue NameError
        send(type).constantize if old_klass == NameError # old_klass
      end
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Cyclomatic complexity for reindex_associations_describe_old_polymorphic_association is too high. [8/6]
Open

    def reindex_associations_describe_old_polymorphic_association(key, type)
      if (previous_changes[key] && previous_changes[key].first) || (previous_changes[type] && previous_changes[type].first)
        old_klass = previous_changes[type].first rescue NameError
        send(type).constantize if old_klass == NameError # old_klass
      end
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Perceived complexity for reindex_associations_describe_old_polymorphic_association is too high. [8/7]
Open

    def reindex_associations_describe_old_polymorphic_association(key, type)
      if (previous_changes[key] && previous_changes[key].first) || (previous_changes[type] && previous_changes[type].first)
        old_klass = previous_changes[type].first rescue NameError
        send(type).constantize if old_klass == NameError # old_klass
      end
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

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

Gem::Specification.new do |spec|
  spec.name          = 'has_reindexable_associations'
  spec.version       = HasReindexableAssociations::VERSION
  spec.authors       = ['Marcin Kalita']
  spec.email         = ['mkalita@efigence.com']

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.

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

  spec.add_development_dependency 'bundler', '~> 1.11'

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'

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

  spec.add_development_dependency 'minitest', '~> 5.0'

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'

Line is too long. [123/120]
Open

      if (previous_changes[key] && previous_changes[key].first) || (previous_changes[type] && previous_changes[type].first)
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

Dependencies should be sorted in an alphabetical order within their section of the gemspec. Dependency codeclimate-test-reporter should appear before simplecov.
Open

  spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.5.0'

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'

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

  if spec.respond_to?(:metadata)

Use a guard clause instead of wrapping the code inside a conditional expression

Example:

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Rename has_reindexable_associations to reindexable_associations?.
Open

    def has_reindexable_associations(*args)
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

This cop makes sure that predicates are named properly.

Example:

# bad
def is_even?(value)
end

# good
def even?(value)
end

# bad
def has_value?
end

# good
def value?
end

Unnecessary utf-8 encoding comment.
Open

# coding: utf-8

Avoid using rescue in its modifier form.
Open

        old_klass = previous_changes[type].first rescue NameError
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

This cop checks for uses of rescue in its modifier form.

Example:

# bad
some_method rescue handle_error

# good
begin
  some_method
rescue
  handle_error
end

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

  spec.add_development_dependency 'coveralls', '~> 0.8.13'

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'

Line is too long. [123/120]
Open

  spec.description   = 'Keep specified associations in sync with ease using async reindexing (searchkick gem is required).'

Provide an exception class and message as arguments to raise.
Open

      raise NoMethodError.new("foreign key '#{reindexable_association}' is not defined, verify has_reindexable_associations options")
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

This cop checks the args passed to fail and raise. For exploded style (default), it recommends passing the exception class and message to raise, rather than construct an instance of the error. It will still allow passing just a message, or the construction of an error with more than one argument.

The exploded style works identically, but with the addition that it will also suggest constructing error objects when the exception is passed multiple arguments.

Example: EnforcedStyle: exploded (default)

# bad
raise StandardError.new("message")

# good
raise StandardError, "message"
fail "message"
raise MyCustomError.new(arg1, arg2, arg3)
raise MyKwArgError.new(key1: val1, key2: val2)

Example: EnforcedStyle: compact

# bad
raise StandardError, "message"
raise RuntimeError, arg1, arg2, arg3

# good
raise StandardError.new("message")
raise MyCustomError.new(arg1, arg2, arg3)
fail "message"

Freeze mutable objects assigned to constants.
Open

  VERSION = '0.1.4'

This cop checks whether some constant value isn't a mutable literal (e.g. array or hash).

Example:

# bad
CONST = [1, 2, 3]

# good
CONST = [1, 2, 3].freeze

Do not suppress exceptions.
Open

    rescue NameError
Severity: Minor
Found in lib/has_reindexable_associations.rb by rubocop

This cop checks for rescue blocks with no body.

Example:

# bad

def some_method
  do_something
rescue
  # do nothing
end

Example:

# bad

begin
  do_something
rescue
  # do nothing
end

Example:

# good

def some_method
  do_something
rescue
  handle_exception
end

Example:

# good

begin
  do_something
rescue
  handle_exception
end

Add an empty line after magic comments.
Open

lib = File.expand_path('../lib', __FILE__)

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
Severity
Category
Status
Source
Language