Skip to content

Conversation

@github-actions
Copy link
Contributor

Rubocop challenge!

Style/TrailingCommaInHashLiteral

Safe autocorrect: Yes
✅ The autocorrect a cop does is safe (equivalent) by design.

Description

Overview

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

Examples

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

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

EnforcedStyleForMultiline: no_comma (default)

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

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

Auto generated by rubocop_challenger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant