Rubocop: Layout/SpaceAroundOperators incorrectly flags word arrays when used as first argument to method

Created on 30 Dec 2020  路  2Comments  路  Source: rubocop-hq/rubocop

Given:

a method call with one argument as a word-array (example taken from a Guardfile):

directories %w[app config lib test]

Expected behavior

No rubocop offenses.

Actual behavior

Guardfile:3:12: C: [Correctable] Layout/SpaceBeforeBrackets: Remove the space before the opening brackets.
directories %w[app config lib test]

Actual (auto-correct) behavior

Guardfile:3:12: C: [Corrected] Layout/SpaceAroundOperators: Surrounding space missing for operator %.
directories%w[app config lib test]
           ^
Guardfile:3:12: C: [Corrected] Layout/SpaceBeforeBrackets: Remove the space before the opening brackets.
directories %w[app config lib test]
           ^
Guardfile:3:13: C: Lint/Void: Operator % used in void context.
directories % w[app config lib test]
            ^

RuboCop version

bundle exec rubocop -V
1.7.0 (using Parser 3.0.0.0, rubocop-ast 1.3.0, running on ruby 2.5.8 x86_64-darwin19)
  - rubocop-minitest 0.10.2
  - rubocop-performance 1.9.1
  - rubocop-rails 2.9.1
  - rubocop-rake 0.5.1
duplicate

Most helpful comment

Thanks for both the issue report (@rmm5t ) and the fix (@koic)

is there a way to push for a release, since in my perspective, the suggested auto-fix is pretty serously wrong with 1.7.0

This is what happened for me:

rubocop lib/capistrano/tasks/setup.rake
Inspecting 1 file
C

Offenses:

lib/capistrano/tasks/setup.rake:157:20: C: [Correctable] Layout/SpaceBeforeBrackets: Remove the space before the opening brackets.
        yum_install %w(nodejs yarn)
                   ^

1 file inspected, 1 offense detected, 1 offense auto-correctable


$ rubocop -A lib/capistrano/tasks/setup.rake
Inspecting 1 file
C

Offenses:

lib/capistrano/tasks/setup.rake:157:20: C: [Corrected] Layout/SpaceAroundOperators: Surrounding space missing for operator %.
        yum_install%w(nodejs yarn)
                   ^
lib/capistrano/tasks/setup.rake:157:20: C: [Corrected] Layout/SpaceBeforeBrackets: Remove the space before the opening brackets.
        yum_install %w(nodejs yarn)
                   ^
lib/capistrano/tasks/setup.rake:157:23: C: [Corrected] Style/NestedParenthesizedCalls: Add parentheses to nested method call nodejs yarn.
        yum_install%w(nodejs yarn)
                      ^^^^^^^^^^^

1 file inspected, 3 offenses detected, 3 offenses corrected

The problem is that all these fixes will yield a clearly wrong result:

$ git diff -U-0 -- lib/capistrano/tasks/setup.rake 
diff --git a/lib/capistrano/tasks/setup.rake b/lib/capistrano/tasks/setup.rake
index 6f98919..2cb9253 100644
--- a/lib/capistrano/tasks/setup.rake
+++ b/lib/capistrano/tasks/setup.rake
@@ -157 +157 @@ namespace :setup do
-        yum_install %w(nodejs yarn)
+        yum_install % w(nodejs(yarn))

So my point is that we would need a bugfix release as fast as possible. My question is therefore on how I can help pushing for a new bugfix release now?

All 2 comments

This issue dup with #9290 and it has been fixed by #9291. Please wait the next release. Thank you.

Thanks for both the issue report (@rmm5t ) and the fix (@koic)

is there a way to push for a release, since in my perspective, the suggested auto-fix is pretty serously wrong with 1.7.0

This is what happened for me:

rubocop lib/capistrano/tasks/setup.rake
Inspecting 1 file
C

Offenses:

lib/capistrano/tasks/setup.rake:157:20: C: [Correctable] Layout/SpaceBeforeBrackets: Remove the space before the opening brackets.
        yum_install %w(nodejs yarn)
                   ^

1 file inspected, 1 offense detected, 1 offense auto-correctable


$ rubocop -A lib/capistrano/tasks/setup.rake
Inspecting 1 file
C

Offenses:

lib/capistrano/tasks/setup.rake:157:20: C: [Corrected] Layout/SpaceAroundOperators: Surrounding space missing for operator %.
        yum_install%w(nodejs yarn)
                   ^
lib/capistrano/tasks/setup.rake:157:20: C: [Corrected] Layout/SpaceBeforeBrackets: Remove the space before the opening brackets.
        yum_install %w(nodejs yarn)
                   ^
lib/capistrano/tasks/setup.rake:157:23: C: [Corrected] Style/NestedParenthesizedCalls: Add parentheses to nested method call nodejs yarn.
        yum_install%w(nodejs yarn)
                      ^^^^^^^^^^^

1 file inspected, 3 offenses detected, 3 offenses corrected

The problem is that all these fixes will yield a clearly wrong result:

$ git diff -U-0 -- lib/capistrano/tasks/setup.rake 
diff --git a/lib/capistrano/tasks/setup.rake b/lib/capistrano/tasks/setup.rake
index 6f98919..2cb9253 100644
--- a/lib/capistrano/tasks/setup.rake
+++ b/lib/capistrano/tasks/setup.rake
@@ -157 +157 @@ namespace :setup do
-        yum_install %w(nodejs yarn)
+        yum_install % w(nodejs(yarn))

So my point is that we would need a bugfix release as fast as possible. My question is therefore on how I can help pushing for a new bugfix release now?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deivid-rodriguez picture deivid-rodriguez  路  3Comments

ecbrodie picture ecbrodie  路  3Comments

mikegee picture mikegee  路  3Comments

lepieru picture lepieru  路  3Comments

mlammers picture mlammers  路  3Comments