delonnewman/dragnet

View on GitHub

Showing 227 of 227 total issues

Avoid parameter lists longer than 5 parameters. [6/5]
Open

  def icon_button(label, path = nil, icon:, icon_type: 'fas', method: :post, **html_options)
Severity: Minor
Found in app/helpers/url_helper.rb by rubocop

Checks for methods with too many parameters.

The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count, as they add less complexity than positional or optional parameters.

Any number of arguments for initialize method inside a block of Struct.new and Data.define like this is always allowed:

Struct.new(:one, :two, :three, :four, :five, keyword_init: true) do
  def initialize(one:, two:, three:, four:, five:)
  end
end

This is because checking the number of arguments of the initialize method does not make sense.

NOTE: Explicit block argument &block is not counted to prevent erroneous change that is avoided by making block argument implicit.

Example: Max: 3

# good
def foo(a, b, c = 1)
end

Example: Max: 2

# bad
def foo(a, b, c = 1)
end

Example: CountKeywordArgs: true (default)

# counts keyword args towards the maximum

# bad (assuming Max is 3)
def foo(a, b, c, d: 1)
end

# good (assuming Max is 3)
def foo(a, b, c: 1)
end

Example: CountKeywordArgs: false

# don't count keyword args towards the maximum

# good (assuming Max is 3)
def foo(a, b, c, d: 1)
end

This cop also checks for the maximum number of optional parameters. This can be configured using the MaxOptionalParameters config option.

Example: MaxOptionalParameters: 3 (default)

# good
def foo(a = 1, b = 2, c = 3)
end

Example: MaxOptionalParameters: 2

# bad
def foo(a = 1, b = 2, c = 3)
end

Line is too long. [121/120]
Open

    Dragnet::DataGridPresenter.new(Dragnet::DataGrid.whole.find_or_create!(survey, user: current_user), data_grid_params)

Checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

  • ArgumentAlignment
  • ArrayAlignment
  • BlockAlignment
  • BlockDelimiters
  • BlockEndNewline
  • ClosingParenthesisIndentation
  • FirstArgumentIndentation
  • FirstArrayElementIndentation
  • FirstHashElementIndentation
  • FirstParameterIndentation
  • HashAlignment
  • IndentationWidth
  • MultilineArrayLineBreaks
  • MultilineBlockLayout
  • MultilineHashBraceLayout
  • MultilineHashKeyLineBreaks
  • MultilineMethodArgumentLineBreaks
  • MultilineMethodParameterLineBreaks
  • ParameterAlignment

Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

Example:

# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}

# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}

# good (with recommended cops enabled)
{
  foo: "0000000000",
  bar: "0000000000",
  baz: "0000000000",
}

Non-idiomatic code found in (if prefix prefix (-> entity :entity/type name))
Open

        prefix (if prefix prefix (-> entity :entity/type name))

Consider using:

(or prefix (-> entity :entity/type name))

instead of:

(if prefix prefix (-> entity :entity/type name))

%w-literals should be delimited by [ and ].
Open

  rails = dsl.rails(view_extensions: %w(erb haml slim))
Severity: Minor
Found in Guardfile by rubocop

Enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Omit the hash value.
Open

    User.new(name: name, login: login, email: email, nickname: nick, password: pass)

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: foo, 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}

Non-idiomatic code found in (-> {:entity/id (->uuid id), :entity/type :question-type, :question.type/name name, :question.type/slug slug, :question.type/settings settings} validate-question-type!)
Open

  (-> {:entity/id (->uuid id)

Consider using:

(validate-question-type!
  {:entity/id (->uuid id),
   :entity/type :question-type,
   :question.type/name name,
   :question.type/slug slug,
   :question.type/settings settings})

instead of:

(-> {:entity/id (->uuid id),
     :entity/type :question-type,
     :question.type/name name,
     :question.type/slug slug,
     :question.type/settings settings}
 validate-question-type!)

Final newline missing.
Open

end

Looks for trailing blank lines and a final newline in the source code.

Example: EnforcedStyle: final_newline (default)

# `final_newline` looks for one newline at the end of files.

# bad
class Foo; end

# EOF

# bad
class Foo; end # EOF

# good
class Foo; end
# EOF

Example: EnforcedStyle: finalblankline

# `final_blank_line` looks for one blank line followed by a new line
# at the end of files.

# bad
class Foo; end
# EOF

# bad
class Foo; end # EOF

# good
class Foo; end

# EOF

Omit the hash value.
Open

      if user.can_preview_survey?(survey, wants_preview: wants_preview)

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: foo, 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 string interpolation to string concatenation.
Open

          output:       e.message + "\n" + e.backtrace.to_s,

Checks for places where string concatenation can be replaced with string interpolation.

The cop can autocorrect simple cases but will skip autocorrecting more complex cases where the resulting code would be harder to read. In those cases, it might be useful to extract statements to local variables or methods which you can then interpolate in a string.

NOTE: When concatenation between two strings is broken over multiple lines, this cop does not register an offense; instead, Style/LineEndConcatenation will pick up the offense if enabled.

Two modes are supported: 1. aggressive style checks and corrects all occurrences of + where either the left or right side of + is a string literal. 2. conservative style on the other hand, checks and corrects only if left side (receiver of + method call) is a string literal. This is useful when the receiver is some expression that returns string like Pathname instead of a string literal.

Safety:

This cop is unsafe in aggressive mode, as it cannot be guaranteed that the receiver is actually a string, which can result in a false positive.

Example: Mode: aggressive (default)

# bad
email_with_name = user.name + ' <' + user.email + '>'
Pathname.new('/') + 'test'

# good
email_with_name = "#{user.name} <#{user.email}>"
email_with_name = format('%s <%s>', user.name, user.email)
"#{Pathname.new('/')}test"

# accepted, line-end concatenation
name = 'First' +
  'Last'

Example: Mode: conservative

# bad
'Hello' + user.name

# good
"Hello #{user.name}"
user.name + '!!'
Pathname.new('/') + 'test'

Tagging a string as html safe may be a security risk.
Open

      end.join.html_safe
Severity: Minor
Found in app/helpers/application_helper.rb by rubocop

This cop checks for the use of output safety calls like html_safe, raw, and safe_concat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.

Example:

user_content = "hi"

# bad
"

#{user_content}

".html_safe # => ActiveSupport::SafeBuffer "

hi

" # good content_tag(:p, user_content) # => ActiveSupport::SafeBuffer "

<b>hi</b>

" # bad out = "" out << "
  • #{user_content}
  • " out << "
  • #{user_content}
  • " out.html_safe # => ActiveSupport::SafeBuffer "
  • hi
  • hi
  • " # good out = [] out << content_tag(:li, user_content) out << content_tag(:li, user_content) safe_join(out) # => ActiveSupport::SafeBuffer # "
  • <b>hi</b>
  • <b>hi</b>
  • " # bad out = "

    trusted content

    ".html_safe out.safe_concat(user_content) # => ActiveSupport::SafeBuffer "

    trusted_content

    hi" # good out = "

    trusted content

    ".html_safe out.concat(user_content) # => ActiveSupport::SafeBuffer # "

    trusted_content

    <b>hi</b>" # safe, though maybe not good style out = "trusted content" result = out.concat(user_content) # => String "trusted contenthi" # because when rendered in ERB the String will be escaped: # <%= result %> # => trusted content<b>hi</b> # bad (user_content + " " + content_tag(:span, user_content)).html_safe # => ActiveSupport::SafeBuffer "hi <span><b>hi</b></span>" # good safe_join([user_content, " ", content_tag(:span, user_content)]) # => ActiveSupport::SafeBuffer # "<b>hi</b> <span>&lt;b&gt;hi&lt;/b&gt;</span>"

    Tagging a string as html safe may be a security risk.
    Open

          label.html_safe + ' ' + column_sort_icon(grid, column).html_safe
    Severity: Minor
    Found in app/helpers/data_grid_helper.rb by rubocop

    This cop checks for the use of output safety calls like html_safe, raw, and safe_concat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.

    Example:

    user_content = "hi"
    
    # bad
    "

    #{user_content}

    ".html_safe # => ActiveSupport::SafeBuffer "

    hi

    " # good content_tag(:p, user_content) # => ActiveSupport::SafeBuffer "

    <b>hi</b>

    " # bad out = "" out << "
  • #{user_content}
  • " out << "
  • #{user_content}
  • " out.html_safe # => ActiveSupport::SafeBuffer "
  • hi
  • hi
  • " # good out = [] out << content_tag(:li, user_content) out << content_tag(:li, user_content) safe_join(out) # => ActiveSupport::SafeBuffer # "
  • <b>hi</b>
  • <b>hi</b>
  • " # bad out = "

    trusted content

    ".html_safe out.safe_concat(user_content) # => ActiveSupport::SafeBuffer "

    trusted_content

    hi" # good out = "

    trusted content

    ".html_safe out.concat(user_content) # => ActiveSupport::SafeBuffer # "

    trusted_content

    <b>hi</b>" # safe, though maybe not good style out = "trusted content" result = out.concat(user_content) # => String "trusted contenthi" # because when rendered in ERB the String will be escaped: # <%= result %> # => trusted content<b>hi</b> # bad (user_content + " " + content_tag(:span, user_content)).html_safe # => ActiveSupport::SafeBuffer "hi <span><b>hi</b></span>" # good safe_join([user_content, " ", content_tag(:span, user_content)]) # => ActiveSupport::SafeBuffer # "<b>hi</b> <span>&lt;b&gt;hi&lt;/b&gt;</span>"

    Put empty method definitions on a single line.
    Open

        def data_grid_edit_input(_answers)
        end
    Severity: Minor
    Found in app/helpers/dragnet/type/view.rb by rubocop

    Checks for the formatting of empty method definitions. By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the end to go on its own line (expanded style).

    NOTE: A method definition is not considered empty if it contains comments.

    NOTE: Autocorrection will not be applied for the compact style if the resulting code is longer than the Max configuration for Layout/LineLength, but an offense will still be registered.

    Example: EnforcedStyle: compact (default)

    # bad
    def foo(bar)
    end
    
    def self.foo(bar)
    end
    
    # good
    def foo(bar); end
    
    def foo(bar)
      # baz
    end
    
    def self.foo(bar); end

    Example: EnforcedStyle: expanded

    # bad
    def foo(bar); end
    
    def self.foo(bar); end
    
    # good
    def foo(bar)
    end
    
    def self.foo(bar)
    end

    Omit the hash value.
    Open

          tag.input(class: 'form-check-input', type: 'checkbox', role: 'switch', id: id, **input_attributes) +
    Severity: Minor
    Found in app/helpers/form_helper.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: foo, 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}

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

      def survey_form_code(survey_id, base_url = request.base_url)

    Checks for unused method arguments.

    Example:

    # bad
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end
    
    # good
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Example: AllowUnusedKeywordArguments: false (default)

    # bad
    def do_something(used, unused: 42)
      used
    end

    Example: AllowUnusedKeywordArguments: true

    # good
    def do_something(used, unused: 42)
      used
    end

    Example: IgnoreEmptyMethods: true (default)

    # good
    def do_something(unused)
    end

    Example: IgnoreEmptyMethods: false

    # bad
    def do_something(unused)
    end

    Example: IgnoreNotImplementedMethods: true (default)

    # good
    def do_something(unused)
      raise NotImplementedError
    end
    
    def do_something_else(unused)
      fail "TODO"
    end

    Example: IgnoreNotImplementedMethods: false

    # bad
    def do_something(unused)
      raise NotImplementedError
    end
    
    def do_something_else(unused)
      fail "TODO"
    end

    Put a comma after the last item of a multiline hash.
    Open

        svg: 'image/svg+xml'
    Severity: Minor
    Found in app/helpers/qr_code_helper.rb by rubocop

    Checks for trailing comma in hash literals. The configuration options are:

    • consistent_comma: Requires a comma after the last item of all non-empty, multiline hash literals.
    • comma: Requires a comma after the last item in a hash, but only when each item is on its own line.
    • no_comma: Does not require a comma after the last item in a hash

    Example: EnforcedStyleForMultiline: consistent_comma

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = { foo: 1, bar: 2 }
    
    # good
    a = {
      foo: 1, bar: 2,
      qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2, qux: 3,
    }
    
    # good
    a = {
      foo: 1,
      bar: 2,
    }

    Example: EnforcedStyleForMultiline: comma

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = { foo: 1, bar: 2 }
    
    # bad
    a = {
      foo: 1, bar: 2,
      qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2,
      qux: 3
    }
    
    # bad
    a = {
      foo: 1, bar: 2, qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2, qux: 3
    }
    
    # good
    a = {
      foo: 1,
      bar: 2,
    }

    Example: EnforcedStyleForMultiline: no_comma (default)

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = {
      foo: 1,
      bar: 2
    }

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

    guard :rspec, cmd: "bundle exec rspec" do
    Severity: Minor
    Found in Guardfile 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

      require "guard/rspec/dsl"
    Severity: Minor
    Found in Guardfile 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"

    Put a comma after the last item of a multiline hash.
    Open

          complete: 'complete-submission-form'
    Severity: Minor
    Found in app/models/dragnet/reply_tracker.rb by rubocop

    Checks for trailing comma in hash literals. The configuration options are:

    • consistent_comma: Requires a comma after the last item of all non-empty, multiline hash literals.
    • comma: Requires a comma after the last item in a hash, but only when each item is on its own line.
    • no_comma: Does not require a comma after the last item in a hash

    Example: EnforcedStyleForMultiline: consistent_comma

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = { foo: 1, bar: 2 }
    
    # good
    a = {
      foo: 1, bar: 2,
      qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2, qux: 3,
    }
    
    # good
    a = {
      foo: 1,
      bar: 2,
    }

    Example: EnforcedStyleForMultiline: comma

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = { foo: 1, bar: 2 }
    
    # bad
    a = {
      foo: 1, bar: 2,
      qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2,
      qux: 3
    }
    
    # bad
    a = {
      foo: 1, bar: 2, qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2, qux: 3
    }
    
    # good
    a = {
      foo: 1,
      bar: 2,
    }

    Example: EnforcedStyleForMultiline: no_comma (default)

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = {
      foo: 1,
      bar: 2
    }

    Put a comma after the last item of a multiline hash.
    Open

        23 => 0

    Checks for trailing comma in hash literals. The configuration options are:

    • consistent_comma: Requires a comma after the last item of all non-empty, multiline hash literals.
    • comma: Requires a comma after the last item in a hash, but only when each item is on its own line.
    • no_comma: Does not require a comma after the last item in a hash

    Example: EnforcedStyleForMultiline: consistent_comma

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = { foo: 1, bar: 2 }
    
    # good
    a = {
      foo: 1, bar: 2,
      qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2, qux: 3,
    }
    
    # good
    a = {
      foo: 1,
      bar: 2,
    }

    Example: EnforcedStyleForMultiline: comma

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = { foo: 1, bar: 2 }
    
    # bad
    a = {
      foo: 1, bar: 2,
      qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2,
      qux: 3
    }
    
    # bad
    a = {
      foo: 1, bar: 2, qux: 3,
    }
    
    # good
    a = {
      foo: 1, bar: 2, qux: 3
    }
    
    # good
    a = {
      foo: 1,
      bar: 2,
    }

    Example: EnforcedStyleForMultiline: no_comma (default)

    # bad
    a = { foo: 1, bar: 2, }
    
    # good
    a = {
      foo: 1,
      bar: 2
    }

    Omit the hash value.
    Open

            result.reply = Reply.create!(survey: survey)

    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: foo, 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}
    Severity
    Category
    Status
    Source
    Language