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

rubocop reports false positives. #2912

Closed
jottr opened this issue Mar 4, 2016 · 10 comments · Fixed by #3002
Closed

rubocop reports false positives. #2912

jottr opened this issue Mar 4, 2016 · 10 comments · Fixed by #3002
Labels

Comments

@jottr
Copy link

jottr commented Mar 4, 2016

Expected behavior

rubocop should not report any errors.

Actual behavior

rubocop reports errors, which do not exist, even after running rubocop -a

Steps to reproduce the problem

$ rubocop -a app/controllers/api/wishes_controller.rb
Inspecting 1 file
C

Offenses:

app/controllers/api/wishes_controller.rb:9:15: C: [Corrected] = is not aligned with the following assignment.
    wish      = Wish.where(text: params[:text]).first
              ^
app/controllers/api/wishes_controller.rb:17:28: C: [Corrected] = is not aligned with the following assignment.
        initial_wishes     = sugg.initial_wishes
                           ^
app/controllers/api/wishes_controller.rb:47:14: C: [Corrected] = is not aligned with the following assignment.
    user_ids = Wish.find(params[:id]).user_ids
             ^
app/controllers/api/wishes_controller.rb:53:14: C: [Corrected] = is not aligned with the following assignment.
    user_ids = Wish.find(params[:id]).user_ids
             ^
app/controllers/api/wishes_controller.rb:71:11: C: [Corrected] = is not aligned with the following assignment.
    wish  = Wish.find(params[:id])
          ^
app/controllers/api/wishes_controller.rb:94:12: C: [Corrected] = is not aligned with the following assignment.
      user = wish.users.where.not('users.avatar' => nil).sample
           ^
app/controllers/api/wishes_controller.rb:121:18: C: [Corrected] = is not aligned with the following assignment.
      params[:q] = params[:q].gsub(/ich würde/i,'')
                 ^
app/controllers/api/wishes_controller.rb:142:12: C: [Corrected] = is not aligned with the following assignment.
      user = wish.users.where.not('users.avatar' => nil).sample unless params[:q]
           ^

1 file inspected, 8 offenses detected, 8 offenses corrected

$ git status
On branch develop
nothing to commit, working directory clean

$ rubocop -a app/controllers/api/wishes_controller.rb
Inspecting 1 file

[....]

1 file inspected, 8 offenses detected, 8 offenses corrected

As you can see, the same errors are reported, even after rubocop claims to have fixed them.
Here's a snippet of the first offense reported by rubocop:

# wishes_controller.rb line 9-10
 wish      = Wish.where(text: params[:text]).first
 wish      = Wish.create(params.permit(:text)) unless wish

As you can see, the alignments are properly aligned.

RuboCop version

Include the output of rubocop -V:

$ rubocop -V
0.16.0 (using Parser 2.1.2, running on ruby 2.0.0 x86_64-darwin12.4.0)
@alexdowad
Copy link
Contributor

Rubocop 0.16.0?? That is more than 2 years old. The latest version is 0.37.2.

The problem doesn't occur on master, so this issue can be closed.

@jottr
Copy link
Author

jottr commented Mar 5, 2016

Weird. Something must have messed up the rubocop version in the paste!
Let's do this again:

$ bundle exec rubocop -V
0.37.2 (using Parser 2.3.0.6, running on ruby 2.3.0 x86_64-darwin15)

Problem remains.
Edit:
Here's the relevant line in the projects Gemfile.

@alexdowad
Copy link
Contributor

Can't repro with posted code snippet. Can you post (or link to) a file which can be used to reproduce?

@jottr
Copy link
Author

jottr commented Mar 5, 2016

Sure. This is the file tripping up the cop.

@alexdowad
Copy link
Contributor

Hmm. Just ran RC master on that file, it doesn't complain about alignment of assignments. Also tried auto-correction, same deal.

@jottr
Copy link
Author

jottr commented Mar 6, 2016

That is so weird. I just nuked the complete rbenv install for the ruby version used by this project, completely uninstalled rubocop from my system, reinstalled the needed ruby version and ran bundle install again.

$ rbenv which rubocop
/Users/jottr/dev/mge/mge-rails/.bundle/bin/rubocop

Just to make sure:

$ bundle exec rubocop -V
0.37.2 (using Parser 2.3.0.6, running on ruby 2.3.0 x86_64-darwin15)

Above issue remains. I have no clue where to go from here.
If it's not too much hassle, maybe you could try and replicate from the develop branch?

@jottr
Copy link
Author

jottr commented Mar 8, 2016

I tried again with rubocop from master branch:

# ./Gemfile.lock

GIT
remote: https://github.com/bbatsov/rubocop.git
revision: 6d0a00d2b30d7a3e139455c597031e049bad959e
branch: master
specs:
  rubocop (0.37.2)
    parser (>= 2.3.0.6, < 3.0)
    powerpack (~> 0.1)
    rainbow (>= 1.99.1, < 3.0)
    ruby-progressbar (~> 1.7)
    unicode-display_width (~> 1.0, >= 1.0.1)

Same deal. Problem remains.

@alexdowad
Copy link
Contributor

Anyone here running OS X who can try inspecting this file?

@jonas054
Copy link
Collaborator

I've been able to reproduce. The key is to configure

Style/ExtraSpacing:
  ForceEqualSignAlignment: true

@jonas054 jonas054 added the bug label Mar 11, 2016
@Drenmi
Copy link
Collaborator

Drenmi commented Apr 4, 2016

I've been troubleshooting this thanks to @jonas054 reproduction step, found the issue, and created a fix for it. Now, I'm still faced with the more important task of figuring out why the tests are passing even with the old code. 😕

akihiro17 added a commit to akihiro17/rubocop that referenced this issue Apr 23, 2016
We should check whether a line is aligned with the following line if the preceding line is not an assignment statement.

This fixes rubocop#2912
bbatsov pushed a commit that referenced this issue Apr 23, 2016
We should check whether a line is aligned with the following line if the preceding line is not an assignment statement.

This fixes #2912
Neodelf pushed a commit to Neodelf/rubocop that referenced this issue Oct 15, 2016
We should check whether a line is aligned with the following line if the preceding line is not an assignment statement.

This fixes rubocop#2912
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