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

bug in --auto-correct ? #4644

Closed
daddygongon opened this Issue Aug 3, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@daddygongon

daddygongon commented Aug 3, 2017

Dear sirs
I am really a novice of rubocop. When I try auto-correct a part of code

        3.times{|i|
          if (pos_i[i]==1.0 or pos_j[i]==1.0)
            bias = 1.0
          else
            bias = 0.0
          end
#          bias = (pos_i[i]==1.0 or pos_j[i]==1.0) ? 1.0 : 0.0
        }

by the command,

rubocop --auto-correct test.rb

the rubocop did

3.times { |i|
          bias = if pos_i[i] == (.0) || pos_j[i] == (.0)
            1.0
          else
            0.0
                 end
          #          bias = (pos_i[i]==1.0 or pos_j[i]==1.0) ? 1.0 : 0.0
        }

The values in the if-condition were incorrectly translated. Is this OK?
I know I was nuts on the comparison with the floating point... a very old code I wrote...

@mikegee

This comment has been minimized.

Show comment
Hide comment
@mikegee

mikegee Aug 3, 2017

Contributor

Is this OK?

No, it is broken.

I confirmed this behavior with the latest master.

Contributor

mikegee commented Aug 3, 2017

Is this OK?

No, it is broken.

I confirmed this behavior with the latest master.

@jonas054 jonas054 added the bug label Aug 3, 2017

@daddygongon

This comment has been minimized.

Show comment
Hide comment
@daddygongon

daddygongon Aug 11, 2017

Hello,
Thanks for the fast responce. Another typical bad example ...
cat tmp_before_auto_correct.rb tmp_after_auto_correct.rb
j_pos[1] > - @RaD && j_pos[1] < + @RaD
j_pos[1]>y-@RaD and j_pos[1]<y+@RaD

This is good one.
j_pos[1]>y-@RaD
j_pos[1] > y - @RaD

daddygongon commented Aug 11, 2017

Hello,
Thanks for the fast responce. Another typical bad example ...
cat tmp_before_auto_correct.rb tmp_after_auto_correct.rb
j_pos[1] > - @RaD && j_pos[1] < + @RaD
j_pos[1]>y-@RaD and j_pos[1]<y+@RaD

This is good one.
j_pos[1]>y-@RaD
j_pos[1] > y - @RaD

@daddygongon

This comment has been minimized.

Show comment
Hide comment
@daddygongon

daddygongon Aug 11, 2017

Sorry, the order of files is opposite.
cat tmp_before_auto_correct.rb tmp_after_auto_correct.rb
j_pos[1]>y-@RaD and j_pos[1]<y+@RaD
j_pos[1] > - @RaD && j_pos[1] < + @RaD

This is good one.
cat tmp_before_auto_correct.rb tmp_after_auto_correct.rb
j_pos[1]>y-@RaD
j_pos[1] > y - @RaD

daddygongon commented Aug 11, 2017

Sorry, the order of files is opposite.
cat tmp_before_auto_correct.rb tmp_after_auto_correct.rb
j_pos[1]>y-@RaD and j_pos[1]<y+@RaD
j_pos[1] > - @RaD && j_pos[1] < + @RaD

This is good one.
cat tmp_before_auto_correct.rb tmp_after_auto_correct.rb
j_pos[1]>y-@RaD
j_pos[1] > y - @RaD

@jonas054

This comment has been minimized.

Show comment
Hide comment
@jonas054

jonas054 Aug 22, 2017

Collaborator

The current master auto-corrects to

3.times do |i|
  bias = if (pos_i[i] == 1.0) || (pos_j[i] == 1.0)
           1.0
         else
           0.0
         end
  #          bias = (pos_i[i]==1.0 or pos_j[i]==1.0) ? 1.0 : 0.0
end

(j_pos[1] > y - @RaD) && (j_pos[1] < y + @RaD)

Fixed by #4454 apparently.

Collaborator

jonas054 commented Aug 22, 2017

The current master auto-corrects to

3.times do |i|
  bias = if (pos_i[i] == 1.0) || (pos_j[i] == 1.0)
           1.0
         else
           0.0
         end
  #          bias = (pos_i[i]==1.0 or pos_j[i]==1.0) ? 1.0 : 0.0
end

(j_pos[1] > y - @RaD) && (j_pos[1] < y + @RaD)

Fixed by #4454 apparently.

@jonas054 jonas054 closed this Aug 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment