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: a space is incorrectly added to strip_whitespace % w[name email] #9290

Closed
oanstein opened this issue Dec 25, 2020 · 2 comments · Fixed by #9291
Closed
Labels

Comments

@oanstein
Copy link

Expected behavior

Does noting to before_validation { to_downcase %w[email] }

Actual behavior

Layout/SpaceBeforeBrackets: a space is incorrectly added to before_validation { to_downcase %w[email] } => before_validation { to_downcase % w[email] }

Steps to reproduce the problem

Add before_validation { to_downcase %w[email] }to model file

RuboCop version

$ [bundle exec] rubocop -V
1.7.0 (using Parser 2.7.2.0, rubocop-ast 1.3.0, running on ruby 2.7.2 x86_64-linux)
  - rubocop-performance 1.9.1
  - rubocop-rails 2.9.1
  - rubocop-rspec 2.1.0
@zhuravel
Copy link
Contributor

Another example that should not generate a warning:

link_to [@site, person] do
  content_tag(:span, person.email)
end

@6temes
Copy link

6temes commented Dec 25, 2020

Actually, this fails with any method that accepts an array as params, if not using parenthesis (which is quite common in DSLs)

@koic koic added the bug label Dec 25, 2020
koic added a commit to koic/rubocop that referenced this issue Dec 27, 2020
Fixes rubocop#9290.

This PR fixes a false positive for `Layout/SpaceBeforeBrackets`
when using array literal argument for method call.

If receiver is a method call, it is difficult to prevent false positives.
Therefore, This PR change behaviour to detect only when receiver is a variable.

As a result, safe detection is possible.
bbatsov pushed a commit that referenced this issue Dec 27, 2020
Fixes #9290.

This PR fixes a false positive for `Layout/SpaceBeforeBrackets`
when using array literal argument for method call.

If receiver is a method call, it is difficult to prevent false positives.
Therefore, This PR change behaviour to detect only when receiver is a variable.

As a result, safe detection is possible.
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.

4 participants