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

Layout/SpaceBeforeBrackets generates invalid code #9499

Closed
adfoster-r7 opened this issue Feb 9, 2021 · 0 comments · Fixed by #9501
Closed

Layout/SpaceBeforeBrackets generates invalid code #9499

adfoster-r7 opened this issue Feb 9, 2021 · 0 comments · Fixed by #9501
Labels

Comments

@adfoster-r7
Copy link

Input

foo = "hello world!"
foo[  6, 5]  = "rubocop"
foo

Command

$ rubocop -a --only Layout/SpaceBeforeBrackets foo.rb
Inspecting 1 file
C

Offenses:

foo.rb:2:4: C: [Corrected] Layout/SpaceBeforeBrackets: Remove the space before the opening brackets.
foo[  6, 5]  = "rubocop"
   ^^

###Output

foo = "hello world!"
foo 6, 5]  = "rubocop"
foo

The code is now invalid:

ruby foo.rb 
foo.rb:2: syntax error, unexpected ']', expecting end-of-input
foo 6, 5]  = "rubocop"

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

1.9.1 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-darwin19)
@koic koic added the bug label Feb 10, 2021
koic added a commit to koic/rubocop that referenced this issue Feb 10, 2021
Fixes rubocop#9499.

This PR fixes a false positive for `Layout/SpaceBeforeBrackets`
when multiple spaces are inserted inside the left bracket.
koic added a commit that referenced this issue Feb 10, 2021
…ace_before_brackets

[Fix #9499] Fix a false positive for `Layout/SpaceBeforeBrackets`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants