thoughtbot/paperclip

View on GitHub
lib/paperclip/interpolations.rb

Summary

Maintainability
A
35 mins
Test Coverage

Module has too many lines. [111/100]
Open

  module Interpolations
    extend self

    # Hash assignment of interpolations. Included only for compatibility,
    # and is not intended for normal use.
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

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

Assignment Branch Condition size for content_type_extension is too high. [21/15]
Open

    def content_type_extension attachment, style_name
      mime_type = MIME::Types[attachment.content_type]
      extensions_for_mime_type = unless mime_type.empty?
        mime_type.first.extensions
      else
Severity: Minor
Found in lib/paperclip/interpolations.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

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

    def content_type_extension attachment, style_name
      mime_type = MIME::Types[attachment.content_type]
      extensions_for_mime_type = unless mime_type.empty?
        mime_type.first.extensions
      else
Severity: Minor
Found in lib/paperclip/interpolations.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

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def id attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Use def with parentheses when there are parameters.
Open

    def dotextension attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def hash attachment=nil, style_name=nil
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

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

      pattern = args.first.instance.send(pattern) if pattern.kind_of? Symbol
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def self.[]= name, block
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def timestamp attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def content_type_extension attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def self.[] name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used. You can also write as rails_env(*) if you want the method to accept any arguments but don't care about them.
Open

    def rails_env attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Use def with parentheses when there are parameters.
Open

    def rails_env attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Redundant self detected.
Open

      self.instance_methods(false).sort!
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for redundant uses of self.

self is only needed when:

  • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Example:

    def bar :baz end

    def foo(bar) self.bar # resolves name clash with argument end

    def foo2 bar = 1 self.bar # resolves name clash with local variable end

  • Calling an attribute writer to prevent an local variable assignment

    attr_writer :bar

    def foo self.bar= 1 # Make sure above attr writer is called end

Special cases:

We allow uses of self with operators because it would be awkward otherwise.

Use def with parentheses when there are parameters.
Open

    def attachment attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def style attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use 2 (not -25) spaces for indentation.
Open

        mime_type.first.extensions
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cops checks for indentation that doesn't use two spaces.

Example:

class A
 def test
  puts 'hello'
 end
end

Use the new Ruby 1.9 hash syntax.
Open

      attachment.url(style_name, :timestamp => false, :escape => false)
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks hash literal syntax.

It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).

A separate offense is registered for each problematic pair.

The supported styles are:

  • ruby19 - forces use of the 1.9 syntax (e.g. {a: 1}) when hashes have all symbols for keys
  • hash_rockets - forces use of hash rockets for all hashes
  • nomixedkeys - simply checks for hashes with mixed syntaxes
  • ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes

Example:

"EnforcedStyle => 'ruby19'"

# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden

# bad
{:a => 2}
{b: 1, :c => 2}

Example:

"EnforcedStyle => 'hash_rockets'"

# good
{:a => 1, :b => 2}

# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}

Example:

"EnforcedStyle => 'no_mixed_keys'"

# good
{:a => 1, :b => 2}
{c: 1, d: 2}

# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}

Example:

"EnforcedStyle => 'ruby19_no_mixed_keys'"

# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}

# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets

Use def with parentheses when there are parameters.
Open

    def extension attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def updated_at attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Unused method argument - attachment. If it's necessary, use _ or _attachment as an argument name to indicate that it won't be used. You can also write as rails_root(*) if you want the method to accept any arguments but don't care about them.
Open

    def rails_root attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used. You can also write as rails_root(*) if you want the method to accept any arguments but don't care about them.
Open

    def rails_root attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Unused method argument - attachment. If it's necessary, use _ or _attachment as an argument name to indicate that it won't be used. You can also write as rails_env(*) if you want the method to accept any arguments but don't care about them.
Open

    def rails_env attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def param attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Use def with parentheses when there are parameters.
Open

    def basename attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def id_partition attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def id_partition attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Use def with parentheses when there are parameters.
Open

    def class attachment = nil, style_name = nil
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def param attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def self.interpolate pattern, *args
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Align else with unless.
Open

      else
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cops checks the alignment of else keywords. Normally they should be aligned with an if/unless/while/until/begin/def keyword, but there are special cases when they should follow the same rules as the alignment of end.

Use def with parentheses when there are parameters.
Open

    def filename attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Freeze mutable objects assigned to constants.
Open

    RIGHT_HERE = "#{__FILE__.gsub(%r{\A\./}, "")}:#{__LINE__ + 3}"
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

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

Use the new Ruby 1.9 hash syntax.
Open

      attachment.url(style_name, :timestamp => false, :escape => false)
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks hash literal syntax.

It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).

A separate offense is registered for each problematic pair.

The supported styles are:

  • ruby19 - forces use of the 1.9 syntax (e.g. {a: 1}) when hashes have all symbols for keys
  • hash_rockets - forces use of hash rockets for all hashes
  • nomixedkeys - simply checks for hashes with mixed syntaxes
  • ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes

Example:

"EnforcedStyle => 'ruby19'"

# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden

# bad
{:a => 2}
{b: 1, :c => 2}

Example:

"EnforcedStyle => 'hash_rockets'"

# good
{:a => 1, :b => 2}

# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}

Example:

"EnforcedStyle => 'no_mixed_keys'"

# good
{:a => 1, :b => 2}
{c: 1, d: 2}

# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}

Example:

"EnforcedStyle => 'ruby19_no_mixed_keys'"

# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}

# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets

end at 130, 6 is not aligned with unless at 126, 33.
Open

      end
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks whether the end keywords are aligned properly.

Three modes are supported through the AlignWith configuration parameter:

If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

Example:

# good
# keyword style
variable = if true
           end

# variable style
variable = if true
end

# start_of_line style
puts(if true
end)

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def fingerprint attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def attachment attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Use def with parentheses when there are parameters.
Open

    def rails_root attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Line is too long. [114/80]
Open

      [ basename(attachment, style_name), extension(attachment, style_name) ].delete_if(&:empty?).join(".".freeze)
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Line is too long. [87/80]
Open

      raise Errors::InfiniteInterpolationError if caller.any?{|b| b.index(RIGHT_HERE) }
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Line is too long. [83/80]
Open

      attachment.instance_read(:updated_at).in_time_zone(attachment.time_zone).to_s
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Redundant else-clause.
Open

      else
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Checks for empty else-clauses, possibly including comments and/or an explicit nil depending on the EnforcedStyle.

SupportedStyles:

Example:

# good for all styles

if condition
  statement
else
  statement
end

# good for all styles
if condition
  statement
end

Example:

# empty - warn only on empty else

# bad
if condition
  statement
else
end

# good
if condition
  statement
else
  nil
end

Example:

# nil - warn on else with nil in it

# bad
if condition
  statement
else
  nil
end

# good
if condition
  statement
else
end

Example:

# both - warn on empty else and else with nil in it

# bad
if condition
  statement
else
  nil
end

# bad
if condition
  statement
else
end

Use def with parentheses when there are parameters.
Open

    def fingerprint attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def timestamp attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Unused method argument - style_name. If it's necessary, use _ or _style_name as an argument name to indicate that it won't be used.
Open

    def basename attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

This cop checks for unused method arguments.

Example:

def some_method(used, unused, _unused_but_allowed)
  puts used
end

Line is too long. [84/80]
Open

      @interpolators_cache ||= all.reverse!.map! { |method| [method, ":#{method}"] }
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def url attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def updated_at attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def id attachment, style_name
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Surrounding space missing in default value assignment.
Open

    def hash attachment=nil, style_name=nil
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Prefer single-quoted strings inside interpolations.
Open

    RIGHT_HERE = "#{__FILE__.gsub(%r{\A\./}, "")}:#{__LINE__ + 3}"
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Space between { and | missing.
Open

      raise Errors::InfiniteInterpolationError if caller.any?{|b| b.index(RIGHT_HERE) }
Severity: Minor
Found in lib/paperclip/interpolations.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.

Do not use unless with else. Rewrite these with the positive case first.
Open

      extensions_for_mime_type = unless mime_type.empty?
        mime_type.first.extensions
      else
        []
      end
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Surrounding space missing in default value assignment.
Open

    def hash attachment=nil, style_name=nil
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Space inside square brackets detected.
Open

      [ basename(attachment, style_name), extension(attachment, style_name) ].delete_if(&:empty?).join(".".freeze)
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Space inside square brackets detected.
Open

      [ basename(attachment, style_name), extension(attachment, style_name) ].delete_if(&:empty?).join(".".freeze)
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

Space missing to the left of {.
Open

      raise Errors::InfiniteInterpolationError if caller.any?{|b| b.index(RIGHT_HERE) }
Severity: Minor
Found in lib/paperclip/interpolations.rb by rubocop

There are no issues that match your filters.

Category
Status