thoughtbot/paperclip

View on GitHub
shoulda_macros/paperclip.rb

Summary

Maintainability
A
25 mins
Test Coverage

Assignment Branch Condition size for should_validate_attachment_size is too high. [18.71/15]
Open

    def should_validate_attachment_size name, options = {}
      klass   = self.name.gsub(/Test$/, '').constantize
      min     = options[:greater_than] || (options[:in] && options[:in].first) || 0
      max     = options[:less_than]    || (options[:in] && options[:in].last)  || (1.0/0)
      range   = (min..max)
Severity: Minor
Found in shoulda_macros/paperclip.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 should_validate_attachment_size has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    def should_validate_attachment_size name, options = {}
      klass   = self.name.gsub(/Test$/, '').constantize
      min     = options[:greater_than] || (options[:in] && options[:in].first) || 0
      max     = options[:less_than]    || (options[:in] && options[:in].last)  || (1.0/0)
      range   = (min..max)
Severity: Minor
Found in shoulda_macros/paperclip.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

Use tr instead of gsub.
Open

      definition = model.gsub(" ", "_").classify.constantize.
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cop identifies places where gsub can be replaced by tr or delete.

Example:

# bad
'abc'.gsub('b', 'd')
'abc'.gsub('a', '')
'abc'.gsub(/a/, 'd')
'abc'.gsub!('a', 'd')

# good
'abc'.gsub(/.*/, 'a')
'abc'.gsub(/a+/, 'd')
'abc'.tr('b', 'd')
'a b c'.delete(' ')

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

      klass   = self.name.gsub(/Test$/, '').constantize
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

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"

Use def with parentheses when there are parameters.
Open

    def should_have_attached_file name
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Use def with parentheses when there are parameters.
Open

    def should_validate_attachment_presence name
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Unused block argument - match. You can omit the argument if you don't care about it.
Open

      path.gsub!(/:([^\/\.]+)/) do |match|
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cop checks for unused block arguments.

Example:

# bad

do_something do |used, unused|
  puts used
end

do_something do |bar|
  puts :foo
end

define_method(:foo) do |bar|
  puts :baz
end

Example:

#good

do_something do |used, _unused|
  puts used
end

do_something do
  puts :foo
end

define_method(:foo) do |_bar|
  puts :baz
end

Line is too long. [89/80]
Open

      max     = options[:less_than]    || (options[:in] && options[:in].last)  || (1.0/0)
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

Use the new Ruby 1.9 hash syntax.
Open

        FakeWeb.register_uri(:put, Regexp.new(path), :body => "OK")
Severity: Minor
Found in shoulda_macros/paperclip.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 (default)

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

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

Example: EnforcedStyle: hash_rockets

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

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

Example: EnforcedStyle: nomixedkeys

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

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

Example: EnforcedStyle: ruby19nomixed_keys

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

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

      klass   = self.name.gsub(/Test$/, '').constantize
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

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 double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

require 'paperclip/matchers'
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

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 double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

      klass   = self.name.gsub(/Test$/, '').constantize
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

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

        raise NameError, "the stub_paperclip_s3 shoulda macro requires the fakeweb gem."
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def should_validate_attachment_content_type name, options = {}
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Line is too long. [83/80]
Open

      min     = options[:greater_than] || (options[:in] && options[:in].first) || 0
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Open

      klass   = self.name.gsub(/Test$/, '').constantize
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

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"

Align attachment_definitions with model.gsub(" ", "_").classify.constantize. on line 69.
Open

                         attachment_definitions[attachment.to_sym]
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cop checks the indentation of the method name part in method calls that span more than one line.

Example: EnforcedStyle: aligned

# bad
while myvariable
.b
  # do something
end

# good
while myvariable
      .b
  # do something
end

# good
Thing.a
     .b
     .c

Example: EnforcedStyle: indented

# good
while myvariable
  .b

  # do something
end

Example: EnforcedStyle: indentedrelativeto_receiver

# good
while myvariable
        .a
        .b

  # do something
end

# good
myvariable = Thing
               .a
               .b
               .c

Surrounding space missing for operator /.
Open

      max     = options[:less_than]    || (options[:in] && options[:in].last)  || (1.0/0)
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

Checks that operators have space around them, except for ** which should not have surrounding space.

Example:

# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b

# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b

Unnecessary spacing detected.
Open

  class ActionController::Integration::Session  #:nodoc:
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cop checks for extra/unnecessary whitespace.

Example:

# good if AllowForAlignment is true
name      = "RuboCop"
# Some comment and an empty line

website  += "/bbatsov/rubocop" unless cond
puts        "rubocop"          if     debug

# bad for any configuration
set_app("RuboCop")
website  = "https://github.com/bbatsov/rubocop"

Unnecessary spacing detected.
Open

  class ActionDispatch::IntegrationTest::Session  #:nodoc:
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cop checks for extra/unnecessary whitespace.

Example:

# good if AllowForAlignment is true
name      = "RuboCop"
# Some comment and an empty line

website  += "/bbatsov/rubocop" unless cond
puts        "rubocop"          if     debug

# bad for any configuration
set_app("RuboCop")
website  = "https://github.com/bbatsov/rubocop"

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

    def stub_paperclip_s3(model, attachment, extension)
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cop checks for unused method arguments.

Example:

# bad

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

Example:

# good

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

Line is too long. [89/80]
Open

      matcher = validate_attachment_content_type(name).allowing(valid).rejecting(invalid)
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

Use def with parentheses when there are parameters.
Open

    def should_validate_attachment_size name, options = {}
Severity: Minor
Found in shoulda_macros/paperclip.rb by rubocop

This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

Example: EnforcedStyle: require_parentheses (default)

# The `require_parentheses` style requires method definitions
# to always use parentheses

# bad
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

Example: EnforcedStyle: requirenoparentheses

# The `require_no_parentheses` style requires method definitions
# to never use parentheses

# bad
def bar(num1, num2)
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

Example: EnforcedStyle: requirenoparenthesesexceptmultiline

# The `require_no_parentheses_except_multiline` style prefers no
# parantheses when method definition arguments fit on single line,
# but prefers parantheses when arguments span multiple lines.

# bad
def bar(num1, num2)
  num1 + num2
end

def foo descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name
  do_something
end

# good
def bar num1, num2
  num1 + num2
end

def foo(descriptive_var_name,
        another_descriptive_var_name,
        last_descriptive_var_name)
  do_something
end

There are no issues that match your filters.

Category
Status