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

Alignment is not preserved when auto-correcting by Layout/SpaceAroundOperators #8616

Closed
khiav223577 opened this issue Aug 28, 2020 · 2 comments
Labels

Comments

@khiav223577
Copy link
Contributor

khiav223577 commented Aug 28, 2020

Expected behavior

The alignment should be preserved.

Actual behavior

Alignment is preserved only in some lines.

Steps to reproduce the problem

Add this two files:

scene_title.rb

class Scene_Title
  # -------------------------------------------------------------------------
  # ● 戰鬥測試
  # -------------------------------------------------------------------------
  def battle_test
    # 重置測量遊戲時間用的畫面計數器
    Graphics.frame_count = 0
    # 製作各種遊戲目標
    $game_temp          = Game_Temp.new
    $game_system        = Game_System.new
    $game_switches      = Game_Switches.new
    $game_variables     = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
    # 切換到戰鬥畫面
    $scene = Scene_Battle.new
  end
end

.rubocop.yml

Layout/SpaceAroundOperators:
  AllowForAlignment: true
  Enabled: true

Run auto-correcting:

rubocop scene_title.rb --auto-correct --only Layout/SpaceAroundOperators

Alignment is not preserved from this line $game_temp = Game_Temp.new to this line $game_variables = Game_Variables.new.

scene_title.rb (auto-corrected)

class Scene_Title
  # -------------------------------------------------------------------------
  # ● 戰鬥測試
  # -------------------------------------------------------------------------
  def battle_test
    # 重置測量遊戲時間用的畫面計數器
    Graphics.frame_count = 0
    # 製作各種遊戲目標
    $game_temp = Game_Temp.new
    $game_system = Game_System.new
    $game_switches = Game_Switches.new
    $game_variables = Game_Variables.new
    $game_self_switches = Game_SelfSwitches.new
    $game_screen        = Game_Screen.new
    $game_actors        = Game_Actors.new
    $game_party         = Game_Party.new
    $game_troop         = Game_Troop.new
    $game_map           = Game_Map.new
    $game_player        = Game_Player.new
    # 切換到戰鬥畫面
    $scene = Scene_Battle.new
  end
end

RuboCop version

$ [bundle exec] rubocop -V
0.89.1 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.5.5 x86_64-linux)
@koic koic added the bug label Aug 28, 2020
@dvandersluis
Copy link
Member

dvandersluis commented Oct 4, 2020

Layout/SpaceAroundOperators currently does not see comments as breaks for indentation, and in fact there's a test that would fail otherwise (currently only blank lines are seen as breaks for alignment purposes):

https://github.com/rubocop-hq/rubocop/blob/640e95175d9ef3148c72833368f3d202fab4fdca/spec/rubocop/cop/layout/space_around_operators_spec.rb#L75-L77

So the sample code is not seen as aligned operators, because these two lines are considered adjacent, but not aligned:

Graphics.frame_count = 0
# 製作各種遊戲目標
$game_temp = Game_Temp.new

@koic I was looking into fixing this and I can make it consider comments to be breaks as well, but this will change the behaviour and break tests (for Layout/ExtraSpacing as well). So this probably should remain as is. Thoughts? FWIW the comment node about AllowForAlignment is probably confusing given the behaviour.

@jonas054
Copy link
Collaborator

jonas054 commented Oct 9, 2021

I think @koic's #8906 (released in 1.0.0) fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants