drapergem/draper

View on GitHub
lib/draper/collection_decorator.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%

Method Draper::CollectionDecorator#context= is defined at both lib/draper/collection_decorator.rb:17 and lib/draper/collection_decorator.rb:52.
Open

    def context=(value)
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

This cop checks for duplicated instance (or singleton) method definitions.

Example:

# bad

def duplicated
  1
end

def duplicated
  2
end

Example:

# bad

def duplicated
  1
end

alias duplicated other_duplicated

Example:

# good

def duplicated
  1
end

def other_duplicated
  2
end

Prefer single-quoted strings inside interpolations.
Open

      "#<#{self.class.name} of #{decorator_class || "inferred decorators"} for #{object.inspect}>"
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

This cop checks that quotes inside the string interpolation match the configured preference.

Example: EnforcedStyle: single_quotes (default)

# bad
result = "Tests #{success ? "PASS" : "FAIL"}"

# good
result = "Tests #{success ? 'PASS' : 'FAIL'}"

Example: EnforcedStyle: double_quotes

# bad
result = "Tests #{success ? 'PASS' : 'FAIL'}"

# good
result = "Tests #{success ? "PASS" : "FAIL"}"

Space between { and | missing.
Open

      @decorated_collection ||= object.map{|item| decorate_item(item)}
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.

Example: EnforcedStyle: space (default)

# The `space` style enforces that block braces have
# surrounding space.

# bad
some_array.each {puts e}

# good
some_array.each { puts e }

Example: EnforcedStyle: no_space

# The `no_space` style enforces that block braces don't
# have surrounding space.

# bad
some_array.each { puts e }

# good
some_array.each {puts e}

Example: EnforcedStyleForEmptyBraces: no_space (default)

# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.

# bad
some_array.each {   }
some_array.each {  }
some_array.each { }

# good
some_array.each {}

Example: EnforcedStyleForEmptyBraces: space

# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.

# bad
some_array.each {}

# good
some_array.each { }
some_array.each {  }
some_array.each {   }

Example: SpaceBeforeBlockParameters: true (default)

# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each {|n| n * 2 }

# good
[1, 2, 3].each { |n| n * 2 }

Example: SpaceBeforeBlockParameters: true

# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each { |n| n * 2 }

# good
[1, 2, 3].each {|n| n * 2 }

Missing top-level class documentation comment.
Open

  class CollectionDecorator
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

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

Use alias decorated_with? instance_of? instead of alias :decorated_with? :instance_of?.
Open

    alias :decorated_with? :instance_of?
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

Example: EnforcedStyle: prefer_alias (default)

# bad
alias_method :bar, :foo
alias :bar :foo

# good
alias bar foo

Example: EnforcedStyle: preferaliasmethod

# bad
alias :bar :foo
alias bar foo

# good
alias_method :bar, :foo

Space missing to the left of {.
Open

      @decorated_collection ||= object.map{|item| decorate_item(item)}
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

Checks that block braces have or don't have a space before the opening brace depending on configuration.

Example:

# bad
foo.map{ |a|
  a.bar.to_s
}

# good
foo.map { |a|
  a.bar.to_s
}

Space between { and | missing.
Open

      each {|item| item.context = value } if @decorated_collection
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.

Example: EnforcedStyle: space (default)

# The `space` style enforces that block braces have
# surrounding space.

# bad
some_array.each {puts e}

# good
some_array.each { puts e }

Example: EnforcedStyle: no_space

# The `no_space` style enforces that block braces don't
# have surrounding space.

# bad
some_array.each { puts e }

# good
some_array.each {puts e}

Example: EnforcedStyleForEmptyBraces: no_space (default)

# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.

# bad
some_array.each {   }
some_array.each {  }
some_array.each { }

# good
some_array.each {}

Example: EnforcedStyleForEmptyBraces: space

# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.

# bad
some_array.each {}

# good
some_array.each { }
some_array.each {  }
some_array.each {   }

Example: SpaceBeforeBlockParameters: true (default)

# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each {|n| n * 2 }

# good
[1, 2, 3].each { |n| n * 2 }

Example: SpaceBeforeBlockParameters: true

# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each { |n| n * 2 }

# good
[1, 2, 3].each {|n| n * 2 }

Use alias decorate new instead of alias :decorate :new.
Open

      alias :decorate :new
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

Example: EnforcedStyle: prefer_alias (default)

# bad
alias_method :bar, :foo
alias :bar :foo

# good
alias bar foo

Example: EnforcedStyle: preferaliasmethod

# bad
alias :bar :foo
alias bar foo

# good
alias_method :bar, :foo

Prefer Object#is_a? over Object#kind_of?.
Open

      decorated_collection.kind_of?(klass) || super
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

This cop enforces consistent use of Object#is_a? or Object#kind_of?.

Example: EnforcedStyle: is_a? (default)

# bad
var.kind_of?(Date)
var.kind_of?(Integer)

# good
var.is_a?(Date)
var.is_a?(Integer)

Example: EnforcedStyle: kind_of?

# bad
var.is_a?(Time)
var.is_a?(String)

# good
var.kind_of?(Time)
var.kind_of?(String)

Missing magic comment # frozen_string_literal: true.
Open

module Draper
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

This cop is designed to help upgrade to Ruby 3.0. It will add the comment # frozen_string_literal: true to the top of files to enable frozen string literals. Frozen string literals may be default in Ruby 3.0. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Example: EnforcedStyle: when_needed (default)

# The `when_needed` style will add the frozen string literal comment
# to files only when the `TargetRubyVersion` is set to 2.3+.
# bad
module Foo
  # ...
end

# good
# frozen_string_literal: true

module Foo
  # ...
end

Example: EnforcedStyle: always

# The `always` style will always add the frozen string literal comment
# to a file, regardless of the Ruby version or if `freeze` or `<<` are
# called on a string literal.
# bad
module Bar
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Example: EnforcedStyle: never

# The `never` will enforce that the frozen string literal comment does
# not exist in a file.
# bad
# frozen_string_literal: true

module Baz
  # ...
end

# good
module Baz
  # ...
end

Space missing inside }.
Open

      @decorated_collection ||= object.map{|item| decorate_item(item)}
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

Checks that block braces have or don't have surrounding space inside them on configuration. For blocks taking parameters, it checks that the left brace has or doesn't have trailing space depending on configuration.

Example: EnforcedStyle: space (default)

# The `space` style enforces that block braces have
# surrounding space.

# bad
some_array.each {puts e}

# good
some_array.each { puts e }

Example: EnforcedStyle: no_space

# The `no_space` style enforces that block braces don't
# have surrounding space.

# bad
some_array.each { puts e }

# good
some_array.each {puts e}

Example: EnforcedStyleForEmptyBraces: no_space (default)

# The `no_space` EnforcedStyleForEmptyBraces style enforces that
# block braces don't have a space in between when empty.

# bad
some_array.each {   }
some_array.each {  }
some_array.each { }

# good
some_array.each {}

Example: EnforcedStyleForEmptyBraces: space

# The `space` EnforcedStyleForEmptyBraces style enforces that
# block braces have at least a spece in between when empty.

# bad
some_array.each {}

# good
some_array.each { }
some_array.each {  }
some_array.each {   }

Example: SpaceBeforeBlockParameters: true (default)

# The SpaceBeforeBlockParameters style set to `true` enforces that
# there is a space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each {|n| n * 2 }

# good
[1, 2, 3].each { |n| n * 2 }

Example: SpaceBeforeBlockParameters: true

# The SpaceBeforeBlockParameters style set to `false` enforces that
# there is no space between `{` and `|`. Overrides `EnforcedStyle`
# if there is a conflict.

# bad
[1, 2, 3].each { |n| n * 2 }

# good
[1, 2, 3].each {|n| n * 2 }

Use alias instead of alias_method in a class body.
Open

    alias_method :is_a?, :kind_of?
Severity: Minor
Found in lib/draper/collection_decorator.rb by rubocop

This cop enforces the use of either #alias or #alias_method depending on configuration. It also flags uses of alias :symbol rather than alias bareword.

Example: EnforcedStyle: prefer_alias (default)

# bad
alias_method :bar, :foo
alias :bar :foo

# good
alias bar foo

Example: EnforcedStyle: preferaliasmethod

# bad
alias :bar :foo
alias bar foo

# good
alias_method :bar, :foo

There are no issues that match your filters.

Category
Status