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

Add new Layout/SpaceBeforeBrackets cop #9231

Merged
merged 1 commit into from Dec 15, 2020

Conversation

koic
Copy link
Member

@koic koic commented Dec 15, 2020

Follow rubocop/ruby-style-guide#856.

This PR adds new Layout/SpaceBeforeBrackets cop.

# bad
collection [index_or_key]

# good
collection[index_or_key]

This cop is marked as unsafe because it can occur false positives for do_something [this_is_an_array_literal_argument] that take an array without parentheses as an argument.

I noticed this issue below.
https://github.com/rsim/oracle-enhanced/pull/2076/files#diff-0d21136da5aee9b25213dcf874f62418fa24a06a90237e069642a5af54e7b2efL494-R494


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.

@koic koic force-pushed the add_new_layout_space_before_brackets branch from c5b8207 to 4fedf92 Compare December 15, 2020 07:16
@koic koic changed the title Add new Layout/SpaceBeforeBrackets cop [WIP] Add new Layout/SpaceBeforeBrackets cop Dec 15, 2020
Follow rubocop/ruby-style-guide#856.

This PR adds new `Layout/SpaceBeforeBrackets` cop.

```ruby
# bad
collection [index_or_key]

# good
collection[index_or_key]
```

This cop is marked as unsafe because it can occur false positives
for `do_something [this_is_an_array_literal_argument]` that take
an array without parentheses as an argument.

I noticed this issue below.
https://github.com/rsim/oracle-enhanced/pull/2076/files#
diff-0d21136da5aee9b25213dcf874f62418fa24a06a90237e069642a5af54e7b2efL494-R494
@koic koic force-pushed the add_new_layout_space_before_brackets branch from 4fedf92 to 9cfced1 Compare December 15, 2020 07:51
@koic koic changed the title [WIP] Add new Layout/SpaceBeforeBrackets cop Add new Layout/SpaceBeforeBrackets cop Dec 15, 2020
@bbatsov bbatsov merged commit edbfb12 into rubocop:master Dec 15, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 15, 2020

Thanks!

@koic koic deleted the add_new_layout_space_before_brackets branch December 15, 2020 08:48
koic added a commit that referenced this pull request Dec 17, 2020
Follow #9231.

This commit removes unused `def_node_matcher`.
It was not removed from the generator template.
@eamonn-webster
Copy link

Is it meant to apply in the following case

paths %w[lib]

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 27, 2020

This case will be ignored, unless paths is resolved to some variable identifier.

@eamonn-webster
Copy link

Just seen the fix #9291.

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

3 participants