Showing 209 of 211 total issues

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

  NO_HITS = { "hits" => { "total" => 0, "hits" => [] }}
Severity: Minor
Found in app/classes/document_search.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"

Missing frozen string literal comment.
Open

module Api
Severity: Minor
Found in app/controllers/api/v1/base.rb by rubocop

Helps you transition from mutable string literals to frozen string literals. It will add the # frozen_string_literal: true magic comment to the top of files to enable frozen string literals. Frozen string literals may be default in future Ruby. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Note that the cop will accept files where the comment exists but is set to false instead of true.

To require a blank line after this comment, please see Layout/EmptyLineAfterMagicComment cop.

Safety:

This cop's autocorrection is unsafe since any strings mutations will change from being accepted to raising FrozenError, as all strings will become frozen by default, and will need to be manually refactored.

Example: EnforcedStyle: always (default)

# 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

# good
# frozen_string_literal: false

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

Example: EnforcedStyle: always_true

# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false

module Baz
  # ...
end

# bad
module Baz
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Missing frozen string literal comment.
Open

class String
Severity: Minor
Found in lib/ext/string.rb by rubocop

Helps you transition from mutable string literals to frozen string literals. It will add the # frozen_string_literal: true magic comment to the top of files to enable frozen string literals. Frozen string literals may be default in future Ruby. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Note that the cop will accept files where the comment exists but is set to false instead of true.

To require a blank line after this comment, please see Layout/EmptyLineAfterMagicComment cop.

Safety:

This cop's autocorrection is unsafe since any strings mutations will change from being accepted to raising FrozenError, as all strings will become frozen by default, and will need to be manually refactored.

Example: EnforcedStyle: always (default)

# 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

# good
# frozen_string_literal: false

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

Example: EnforcedStyle: always_true

# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false

module Baz
  # ...
end

# bad
module Baz
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Use parentheses for method calls with arguments.
Open

    json.set! "#{locale}_analyzer" do
Severity: Minor
Found in lib/templatable.rb 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'}"

Avoid multi-line chains of blocks.
Open

    end.select do |locale_file_array|
Severity: Minor
Found in lib/templatable.rb by rubocop

Checks for chaining of a block after another block that spans multiple lines.

Example:

# bad
Thread.list.select do |t|
  t.alive?
end.map do |t|
  t.object_id
end

# good
alive_threads = Thread.list.select do |t|
  t.alive?
end
alive_threads.map do |t|
  t.object_id
end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      stemmer_name = degree == "standard" ? '' : "#{degree}_"
Severity: Minor
Found in lib/templatable.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"

Unnecessary spacing detected.
Open

  gem 'puma',  '~> 5.6'
Severity: Minor
Found in Gemfile by rubocop

Checks for extra/unnecessary whitespace.

Example:

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

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

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

# good only if AllowBeforeTrailingComments is true
object.method(arg)  # this is a comment

# good even if AllowBeforeTrailingComments is false or not set
object.method(arg) # this is a comment

# good with either AllowBeforeTrailingComments or AllowForAlignment
object.method(arg)         # this is a comment
another_object.method(arg) # this is another comment
some_object.method(arg)    # this is some comment

Use match? instead of match when MatchData is not used.
Open

                          unless doc_query.query.match(/".*"/)
Severity: Minor
Found in app/classes/document_query.rb by rubocop

In Ruby 2.4, String#match?, Regexp#match? and Symbol#match? have been added. The methods are faster than match. Because the methods avoid creating a MatchData object or saving backref. So, when MatchData is not used, use match? instead of match.

Example:

# bad
def foo
  if x =~ /re/
    do_something
  end
end

# bad
def foo
  if x.match(/re/)
    do_something
  end
end

# bad
def foo
  if /re/ === x
    do_something
  end
end

# good
def foo
  if x.match?(/re/)
    do_something
  end
end

# good
def foo
  if x =~ /re/
    do_something(Regexp.last_match)
  end
end

# good
def foo
  if x.match(/re/)
    do_something($~)
  end
end

# good
def foo
  if /re/ === x
    do_something($~)
  end
end

Omit the hash value.
Open

          document = Document.new(params.merge(id: id))
Severity: Minor
Found in app/controllers/api/v1/documents.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}

Space missing after colon.
Open

    document_repository.search("*:*", {size:1, sort: "updated_at:desc"}).
Severity: Minor
Found in app/models/collection.rb by rubocop

Checks for colon (:) not followed by some kind of space. N.B. this cop does not handle spaces after a ternary operator, which are instead handled by Layout/SpaceAroundOperators.

Example:

# bad
def f(a:, b:2); {a:3}; end

# good
def f(a:, b: 2); {a: 3}; end

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

    document_repository.search("*:*", {size:1, sort: "updated_at:desc"}).
Severity: Minor
Found in app/models/collection.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 Rails.root.join('path/to').
Open

    Dir[Rails.root.join('app', 'templates', '*.rb')].each do |template_generator|
Severity: Minor
Found in lib/tasks/i14y.rake by rubocop

This cop is used to identify usages of file path joining process to use Rails.root.join clause. It is used to add uniformity when joining paths.

Example: EnforcedStyle: arguments (default)

# bad
Rails.root.join('app/models/goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app', 'models', 'goober')

Example: EnforcedStyle: slashes

# bad
Rails.root.join('app', 'models', 'goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"

# good
Rails.root.join('app/models/goober')

Use parentheses for method calls with arguments.
Open

      json.set! field, lines
Severity: Minor
Found in lib/templatable.rb 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'}"

Prefer single-quoted strings when you don't need string interpolation or special symbols.
Open

      [locale, Rails.root.join("config", "locales", "analysis", "#{locale}_#{type}.txt")]
Severity: Minor
Found in lib/templatable.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 single-quoted strings when you don't need string interpolation or special symbols.
Open

      json.tokenizer "icu_tokenizer"
Severity: Minor
Found in lib/templatable.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"

Missing frozen string literal comment.
Open

class MaxBytes < Grape::Validations::Validators::Base
Severity: Minor
Found in lib/validations/max_bytes.rb by rubocop

Helps you transition from mutable string literals to frozen string literals. It will add the # frozen_string_literal: true magic comment to the top of files to enable frozen string literals. Frozen string literals may be default in future Ruby. The comment will be added below a shebang and encoding comment. The frozen string literal comment is only valid in Ruby 2.3+.

Note that the cop will accept files where the comment exists but is set to false instead of true.

To require a blank line after this comment, please see Layout/EmptyLineAfterMagicComment cop.

Safety:

This cop's autocorrection is unsafe since any strings mutations will change from being accepted to raising FrozenError, as all strings will become frozen by default, and will need to be manually refactored.

Example: EnforcedStyle: always (default)

# 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

# good
# frozen_string_literal: false

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

Example: EnforcedStyle: always_true

# The `always_true` style enforces that the frozen string literal
# comment is set to `true`. This is a stricter option than `always`
# and forces projects to use frozen string literals.
# bad
# frozen_string_literal: false

module Baz
  # ...
end

# bad
module Baz
  # ...
end

# good
# frozen_string_literal: true

module Bar
  # ...
end

Redundant begin block detected.
Open

    @full_text_fields ||= begin
Severity: Minor
Found in app/classes/document_query.rb by rubocop

Checks for redundant begin blocks.

Currently it checks for code like this:

Example:

# bad
def redundant
  begin
    ala
    bala
  rescue StandardError => e
    something
  end
end

# good
def preferred
  ala
  bala
rescue StandardError => e
  something
end

# bad
begin
  do_something
end

# good
do_something

# bad
# When using Ruby 2.5 or later.
do_something do
  begin
    something
  rescue => ex
    anything
  end
end

# good
# In Ruby 2.5 or later, you can omit `begin` in `do-end` block.
do_something do
  something
rescue => ex
  anything
end

# good
# Stabby lambdas don't support implicit `begin` in `do-end` blocks.
-> do
  begin
    foo
  rescue Bar
    baz
  end
end

Use =~ in places where the MatchData returned by #match will not be used.
Open

                          unless doc_query.query.match(/".*"/)
Severity: Minor
Found in app/classes/document_query.rb by rubocop

This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

Example:

# bad
do_something if str.match(/regex/)
while regex.match('str')
  do_something
end

# good
method(str =~ /regex/)
return value unless regex =~ 'str'

Omit the hash value.
Open

          { status: 200, developer_message: 'OK', user_message: user_message }
Severity: Minor
Found in app/controllers/api/v1/documents.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}

Use parentheses for method calls with arguments.
Open

      json.index_patterns "*-#{I14y::APP_NAME}-collections-*"
Severity: Minor
Found in app/templates/collections.rb 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'}"
Severity
Category
Status
Source
Language