Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check newline in empty reference bracket on Layout/SpaceInsideReferenceBrackets #11131

Merged

Conversation

r7kamura
Copy link
Contributor

This is the reference bracket version of the following Pull Request:

which will add the following rule about newline in empty reference bracket:

# bad
foo[
]

# good - EnforcedStyleForEmptyBrackets: no_space (default)
foo[]

# good - EnforcedStyleForEmptyBrackets: space
foo[ ]

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@r7kamura
Copy link
Contributor Author

r7kamura commented Oct 27, 2022

I think this is a topic that should be handled by a separate Pull Request or Issue, but let me mention it.

There is not much consistency in the following cops about how they handle redundant spaces on EnforcedStyleForEmptyX: space case.

  • Layout/SpaceInsideHashLiteralBraces
  • Layout/SpaceInsideReferenceBrackets
# Layout/SpaceInsideHashLiteralBraces:
#   EnforcedStyleForEmptyBraces: space

# bad
foo = {}

# good
foo = { }
foo = {    }
# Layout/SpaceInsideReferenceBrackets:
#   EnforcedStyleForEmptyBrackets: space

# bad
foo[]
foo[    ]

# good
foo[ ]

In other words, there is ambiguity as to whether the opposite of "space" is "any spaces" or "only one space".

My personal opinion is that the Layout/SpaceInsideReferenceBrackets rule is preferable, so I think that this is more of Layout/SpaceInsideHashLiteralBraces thing that should be fixed. What do you think?

@bbatsov bbatsov merged commit a469efb into rubocop:master Oct 30, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Oct 30, 2022

My personal opinion is that the Layout/SpaceInsideReferenceBrackets rule is preferable, so I think that this is more of Layout/SpaceInsideHashLiteralBraces thing that should be fixed. What do you think?

Agreed. space should mean exactly one space. Perhaps we should have named this single_space, but that ship has sailed.

@r7kamura r7kamura deleted the feature/newline-inside-empty-reference branch October 30, 2022 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants