Showing 208 of 210 total issues

Do not use :: for method calls.
Open

    TestServices::delete_es_indexes
Severity: Minor
Found in spec/rails_helper.rb by rubocop

Checks for methods invoked via the :: operator instead of the . operator (like FileUtils::rmdir instead of FileUtils.rmdir).

Example:

# bad
Timeout::timeout(500) { do_something }
FileUtils::rmdir(dir)
Marshal::dump(obj)

# good
Timeout.timeout(500) { do_something }
FileUtils.rmdir(dir)
Marshal.dump(obj)

Omit the hash value.
Open

      token: token
Severity: Minor
Found in spec/models/collection_spec.rb by rubocop

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

This cop has EnforcedShorthandSyntax option. It can enforce either the use of the explicit hash value syntax or the use of Ruby 3.1's hash value shorthand syntax.

The supported styles are:

  • always - forces use of the 3.1 syntax (e.g. {foo:})
  • never - forces use of explicit hash literal value
  • either - accepts both shorthand and explicit use of hash literal value
  • consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash

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}

Example: EnforcedShorthandSyntax: always (default)

# bad
{foo: foo, bar: bar}

# good
{foo:, bar:}

Example: EnforcedShorthandSyntax: never

# bad
{foo:, bar:}

# good
{foo: foo, bar: bar}

Example: EnforcedShorthandSyntax: either

# good
{foo: foo, bar: bar}

# good
{foo:, bar:}

Example: EnforcedShorthandSyntax: consistent

# bad - `foo` and `bar` values can be omitted
{foo: foo, bar: bar}

# bad - `bar` value can be omitted
{foo:, bar: bar}

# bad - mixed syntaxes
{foo:, bar: baz}

# good
{foo:, bar:}

# good - can't omit `baz`
{foo: foo, bar: baz}

Prefer response.parsed_body to JSON.parse(response.body).
Open

        let(:body) { JSON.parse(response.body) }

Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.
Open

      'status' => 503,

Checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the HashAlignment cop.

By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

Example: EnforcedStyle: specialinsideparentheses (default)

# The `special_inside_parentheses` style enforces that the first key
# in a hash literal where the opening brace and the first key are on
# separate lines is indented one step (two spaces) more than the
# position inside the opening parentheses.

# bad
hash = {
  key: :value
}
and_in_a_method_call({
  no: :difference
                     })
takes_multi_pairs_hash(x: {
  a: 1,
  b: 2
},
                       y: {
                         c: 1,
                         d: 2
                       })

# good
special_inside_parentheses
hash = {
  key: :value
}
but_in_a_method_call({
                       its_like: :this
                     })
takes_multi_pairs_hash(x: {
                         a: 1,
                         b: 2
                       },
                       y: {
                         c: 1,
                         d: 2
                       })

Example: EnforcedStyle: consistent

# The `consistent` style enforces that the first key in a hash
# literal where the opening brace and the first key are on
# separate lines is indented the same as a hash literal which is not
# defined inside a method call.

# bad
hash = {
  key: :value
}
but_in_a_method_call({
                       its_like: :this
                      })

# good
hash = {
  key: :value
}
and_in_a_method_call({
  no: :difference
})

Example: EnforcedStyle: align_braces

# The `align_brackets` style enforces that the opening and closing
# braces are indented to the same position.

# bad
and_now_for_something = {
                          completely: :different
}
takes_multi_pairs_hash(x: {
  a: 1,
  b: 2
},
                        y: {
                             c: 1,
                             d: 2
                           })

# good
and_now_for_something = {
                          completely: :different
                        }
takes_multi_pairs_hash(x: {
                            a: 1,
                            b: 2
                          },
                       y: {
                            c: 1,
                            d: 2
                          })

Do not use should when describing your tests.
Open

    it 'should extract an array of SiteFilter instances' do
Severity: Minor
Found in spec/classes/query_parser_spec.rb by rubocop

Do not use should when describing your tests.
Open

    it 'should make the resulting query available' do
Severity: Minor
Found in spec/classes/query_parser_spec.rb by rubocop

Add an empty line after the last let.
Open

    let(:params) { { some_param: value_to_validate } }

Prefer response.parsed_body to JSON.parse(response.body).
Open

        expect(JSON.parse(response.body)).to match(

Beware of using before(:all) as it may cause state to leak between tests. If you are using rspec-rails, and use_transactional_fixtures is enabled, then records created in before(:all) are not automatically rolled back.
Open

  before(:all) do

Incorrect indentation detected (column 0 instead of 2).
Open

# with RSpec, but feel free to customize to your heart's content.
Severity: Minor
Found in spec/spec_helper.rb by rubocop

Checks the indentation of comments.

Example:

# bad
  # comment here
def method_name
end

  # comment here
a = 'hello'

# yet another comment
  if true
    true
  end

# good
# comment here
def method_name
end

# comment here
a = 'hello'

# yet another comment
if true
  true
end

Example: AllowForAlignment: false (default)

# bad
a = 1 # A really long comment
      # spanning two lines.

# good
# A really long comment spanning one line.
a = 1

Example: AllowForAlignment: true

# good
a = 1 # A really long comment
      # spanning two lines.

Omit the hash value.
Open

        { handles: handles, language: :en, query: query, size: 10, offset: 0, include: %w[searchgov_custom1

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

This cop has EnforcedShorthandSyntax option. It can enforce either the use of the explicit hash value syntax or the use of Ruby 3.1's hash value shorthand syntax.

The supported styles are:

  • always - forces use of the 3.1 syntax (e.g. {foo:})
  • never - forces use of explicit hash literal value
  • either - accepts both shorthand and explicit use of hash literal value
  • consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash

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}

Example: EnforcedShorthandSyntax: always (default)

# bad
{foo: foo, bar: bar}

# good
{foo:, bar:}

Example: EnforcedShorthandSyntax: never

# bad
{foo:, bar:}

# good
{foo: foo, bar: bar}

Example: EnforcedShorthandSyntax: either

# good
{foo: foo, bar: bar}

# good
{foo:, bar:}

Example: EnforcedShorthandSyntax: consistent

# bad - `foo` and `bar` values can be omitted
{foo: foo, bar: bar}

# bad - `bar` value can be omitted
{foo:, bar: bar}

# bad - mixed syntaxes
{foo:, bar: baz}

# good
{foo:, bar:}

# good - can't omit `baz`
{foo: foo, bar: baz}

Omit the hash value.
Open

                             content: content

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

This cop has EnforcedShorthandSyntax option. It can enforce either the use of the explicit hash value syntax or the use of Ruby 3.1's hash value shorthand syntax.

The supported styles are:

  • always - forces use of the 3.1 syntax (e.g. {foo:})
  • never - forces use of explicit hash literal value
  • either - accepts both shorthand and explicit use of hash literal value
  • consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash

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}

Example: EnforcedShorthandSyntax: always (default)

# bad
{foo: foo, bar: bar}

# good
{foo:, bar:}

Example: EnforcedShorthandSyntax: never

# bad
{foo:, bar:}

# good
{foo: foo, bar: bar}

Example: EnforcedShorthandSyntax: either

# good
{foo: foo, bar: bar}

# good
{foo:, bar:}

Example: EnforcedShorthandSyntax: consistent

# bad - `foo` and `bar` values can be omitted
{foo: foo, bar: bar}

# bad - `bar` value can be omitted
{foo:, bar: bar}

# bad - mixed syntaxes
{foo:, bar: baz}

# good
{foo:, bar:}

# good - can't omit `baz`
{foo: foo, bar: baz}

Indent the right brace the same as the first position after the preceding left parenthesis.
Open

      }))

Checks the indentation of the first key in a hash literal where the opening brace and the first key are on separate lines. The other keys' indentations are handled by the HashAlignment cop.

By default, Hash literals that are arguments in a method call with parentheses, and where the opening curly brace of the hash is on the same line as the opening parenthesis of the method call, shall have their first key indented one step (two spaces) more than the position inside the opening parenthesis.

Other hash literals shall have their first key indented one step more than the start of the line where the opening curly brace is.

This default style is called 'specialinsideparentheses'. Alternative styles are 'consistent' and 'align_braces'. Here are examples:

Example: EnforcedStyle: specialinsideparentheses (default)

# The `special_inside_parentheses` style enforces that the first key
# in a hash literal where the opening brace and the first key are on
# separate lines is indented one step (two spaces) more than the
# position inside the opening parentheses.

# bad
hash = {
  key: :value
}
and_in_a_method_call({
  no: :difference
                     })
takes_multi_pairs_hash(x: {
  a: 1,
  b: 2
},
                       y: {
                         c: 1,
                         d: 2
                       })

# good
special_inside_parentheses
hash = {
  key: :value
}
but_in_a_method_call({
                       its_like: :this
                     })
takes_multi_pairs_hash(x: {
                         a: 1,
                         b: 2
                       },
                       y: {
                         c: 1,
                         d: 2
                       })

Example: EnforcedStyle: consistent

# The `consistent` style enforces that the first key in a hash
# literal where the opening brace and the first key are on
# separate lines is indented the same as a hash literal which is not
# defined inside a method call.

# bad
hash = {
  key: :value
}
but_in_a_method_call({
                       its_like: :this
                      })

# good
hash = {
  key: :value
}
and_in_a_method_call({
  no: :difference
})

Example: EnforcedStyle: align_braces

# The `align_brackets` style enforces that the opening and closing
# braces are indented to the same position.

# bad
and_now_for_something = {
                          completely: :different
}
takes_multi_pairs_hash(x: {
  a: 1,
  b: 2
},
                        y: {
                             c: 1,
                             d: 2
                           })

# good
and_now_for_something = {
                          completely: :different
                        }
takes_multi_pairs_hash(x: {
                            a: 1,
                            b: 2
                          },
                       y: {
                            c: 1,
                            d: 2
                          })

Prefer not_to over to_not.
Open

        expect { validator.validate_param!(:some_param, params) }.to_not raise_error

Use parentheses for method calls with arguments.
Open

SimpleCov.start 'rails' do
Severity: Minor
Found in .simplecov by rubocop

Enforces the presence (default) or absence of parentheses in method calls containing parameters.

In the default style (require_parentheses), macro methods are allowed. Additional methods can be added to the AllowedMethods or AllowedPatterns list. These options are valid only in the default style. Macros can be included by either setting IgnoreMacros to false or adding specific macros to the IncludedMacros list.

Precedence of options is all follows:

  1. AllowedMethods
  2. AllowedPatterns
  3. IncludedMacros

eg. If a method is listed in both IncludedMacros and AllowedMethods, then the latter takes precedence (that is, the method is allowed).

In the alternative style (omit_parentheses), there are three additional options.

  1. AllowParenthesesInChaining is false by default. Setting it to true allows the presence of parentheses in the last call during method chaining.

  2. AllowParenthesesInMultilineCall is false by default. Setting it to true allows the presence of parentheses in multi-line method calls.

  3. AllowParenthesesInCamelCaseMethod is false by default. This allows the presence of parentheses when calling a method whose name begins with a capital letter and which has no arguments. Setting it to true allows the presence of parentheses in such a method call even with arguments.

NOTE: Parentheses are still allowed in cases where omitting them results in ambiguous or syntactically incorrect code. For example, parentheses are required around a method with arguments when inside an endless method definition introduced in Ruby 3.0. Parentheses are also allowed when forwarding arguments with the triple-dot syntax introduced in Ruby 2.7 as omitting them starts an endless range. And Ruby 3.1's hash omission syntax has a case that requires parentheses because of the following issue: https://bugs.ruby-lang.org/issues/18396.

Example: EnforcedStyle: require_parentheses (default)

# bad
array.delete e

# good
array.delete(e)

# good
# Operators don't need parens
foo == bar

# good
# Setter methods don't need parens
foo.bar = baz

# okay with `puts` listed in `AllowedMethods`
puts 'test'

# okay with `^assert` listed in `AllowedPatterns`
assert_equal 'test', x

Example: EnforcedStyle: omit_parentheses

# bad
array.delete(e)

# good
array.delete e

# bad
foo.enforce(strict: true)

# good
foo.enforce strict: true

# good
# Allows parens for calls that won't produce valid Ruby or be ambiguous.
model.validate strict(true)

# good
# Allows parens for calls that won't produce valid Ruby or be ambiguous.
yield path, File.basename(path)

# good
# Operators methods calls with parens
array&.[](index)

# good
# Operators methods without parens, if you prefer
array.[] index

# good
# Operators methods calls with parens
array&.[](index)

# good
# Operators methods without parens, if you prefer
array.[] index

Example: IgnoreMacros: true (default)

# good
class Foo
  bar :baz
end

Example: IgnoreMacros: false

# bad
class Foo
  bar :baz
end

Example: AllowParenthesesInMultilineCall: false (default)

# bad
foo.enforce(
  strict: true
)

# good
foo.enforce \
  strict: true

Example: AllowParenthesesInMultilineCall: true

# good
foo.enforce(
  strict: true
)

# good
foo.enforce \
  strict: true

Example: AllowParenthesesInChaining: false (default)

# bad
foo().bar(1)

# good
foo().bar 1

Example: AllowParenthesesInChaining: true

# good
foo().bar(1)

# good
foo().bar 1

Example: AllowParenthesesInCamelCaseMethod: false (default)

# bad
Array(1)

# good
Array 1

Example: AllowParenthesesInCamelCaseMethod: true

# good
Array(1)

# good
Array 1

Example: AllowParenthesesInStringInterpolation: false (default)

# bad
"#{t('this.is.bad')}"

# good
"#{t 'this.is.better'}"

Example: AllowParenthesesInStringInterpolation: true

# good
"#{t('this.is.good')}"

# good
"#{t 'this.is.also.good'}"

Use expand_path('../config/environment', __dir__) instead of expand_path('../../config/environment', __FILE__).
Open

require File.expand_path('../../config/environment', __FILE__)
Severity: Minor
Found in spec/rails_helper.rb by rubocop

Checks for use of the File.expand_path arguments. Likewise, it also checks for the Pathname.new argument.

Contrastive bad case and good case are alternately shown in the following examples.

Example:

# bad
File.expand_path('..', __FILE__)

# good
File.expand_path(__dir__)

# bad
File.expand_path('../..', __FILE__)

# good
File.expand_path('..', __dir__)

# bad
File.expand_path('.', __FILE__)

# good
File.expand_path(__FILE__)

# bad
Pathname(__FILE__).parent.expand_path

# good
Pathname(__dir__).expand_path

# bad
Pathname.new(__FILE__).parent.expand_path

# good
Pathname.new(__dir__).expand_path

Indent the first argument one step more than hash_including(.
Open

        language: 'en',
        path: 'http://www.agency.gov/page1.html'

Checks the indentation of the first argument in a method call. Arguments after the first one are checked by Layout/ArgumentAlignment, not by this cop.

For indenting the first parameter of method definitions, check out Layout/FirstParameterIndentation.

This cop will respect Layout/ArgumentAlignment and will not work when EnforcedStyle: with_fixed_indentation is specified for Layout/ArgumentAlignment.

Example:

# bad
some_method(
first_param,
second_param)

foo = some_method(
first_param,
second_param)

foo = some_method(nested_call(
nested_first_param),
second_param)

foo = some_method(
nested_call(
nested_first_param),
second_param)

some_method nested_call(
nested_first_param),
second_param

Example: EnforcedStyle: specialforinnermethodcallinparentheses (default)

# Same as `special_for_inner_method_call` except that the special rule
# only applies if the outer method call encloses its arguments in
# parentheses.

# good
some_method(
  first_param,
second_param)

foo = some_method(
  first_param,
second_param)

foo = some_method(nested_call(
                    nested_first_param),
second_param)

foo = some_method(
  nested_call(
    nested_first_param),
second_param)

some_method nested_call(
  nested_first_param),
second_param

Example: EnforcedStyle: consistent

# The first argument should always be indented one step more than the
# preceding line.

# good
some_method(
  first_param,
second_param)

foo = some_method(
  first_param,
second_param)

foo = some_method(nested_call(
  nested_first_param),
second_param)

foo = some_method(
  nested_call(
    nested_first_param),
second_param)

some_method nested_call(
  nested_first_param),
second_param

Example: EnforcedStyle: consistentrelativeto_receiver

# The first argument should always be indented one level relative to
# the parent that is receiving the argument

# good
some_method(
  first_param,
second_param)

foo = some_method(
        first_param,
second_param)

foo = some_method(nested_call(
                    nested_first_param),
second_param)

foo = some_method(
        nested_call(
          nested_first_param),
second_param)

some_method nested_call(
              nested_first_param),
second_params

Example: EnforcedStyle: specialforinnermethodcall

# The first argument should normally be indented one step more than
# the preceding line, but if it's a argument for a method call that
# is itself a argument in a method call, then the inner argument
# should be indented relative to the inner method.

# good
some_method(
  first_param,
second_param)

foo = some_method(
  first_param,
second_param)

foo = some_method(nested_call(
                    nested_first_param),
second_param)

foo = some_method(
  nested_call(
    nested_first_param),
second_param)

some_method nested_call(
              nested_first_param),
second_param

Prefer response.parsed_body to JSON.parse(response.body).
Open

        expect(JSON.parse(response.body)).to match(

Prefer not_to over to_not.
Open

        expect { validator.validate_param!(:some_param, params) }.to_not raise_error

Prefer be over eq.
Open

        expect(document.promote).to eq(true)
Severity
Category
Status
Source
Language