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

ExtraSpacing Infinite Correction Loop with AlignHash and EnforcedHashRocketStyle: table #2280

Closed
glennmatthews opened this issue Sep 28, 2015 · 1 comment
Assignees

Comments

@glennmatthews
Copy link

The current fix for #2121 isn't sufficient when using non-default style settings for Style/AlignHash:

.rubocop.yml:

Style/AlignHash:
  EnforcedHashRocketStyle: table

example.rb:

ospf_h = {
  'ospfTest'    => {
    'foo'      => {
      area: '0.0.0.0', cost: 10, hello: 30, dead: 120, pass: true },
    'longname' => {
      area: '1.1.1.38', dead: 40, pass: false },
    'vlan101'  => {
      area: '2.2.2.101', cost: 5, hello: 20, dead: 80, pass: true },
  },
  'TestOspfInt' => {
    'x'               => {
      area: '0.0.0.19' },
    'vlan290'         => {
      area: '2.2.2.29', cost: 200, hello: 30, dead: 120, pass: true },
    'port-channel100' => {
      area: '3.2.2.29', cost: 25, hello: 50, dead: 200, pass: false },
  },
}
> rubocop example.rb --only Style/AlignHash,Style/ExtraSpacing --auto-correct
Inspecting 1 file
C

Offenses:

example.rb:2:3: C: [Corrected] Align the elements of a hash literal if they span more than one line.
  'ospfTest' => {
  ^^^^^^^^^^^^^^^
example.rb:2:13: C: [Corrected] Unnecessary spacing detected.
  'ospfTest'    => {
            ^^^

0 files inspected, 2 offenses detected, 2 offenses corrected
gems/rubocop-0.34.2/lib/rubocop/runner.rb:161:in `check_for_infinite_loop': Infinite loop detected in example.rb. (RuboCop::Runner::InfiniteCorrectionLoop)
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:136:in `block in do_inspection_loop'
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:135:in `loop'
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:135:in `do_inspection_loop'
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:87:in `process_file'
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:57:in `block in inspect_files'
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:55:in `each'
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:55:in `inspect_files'
        from gems/rubocop-0.34.2/lib/rubocop/runner.rb:33:in `run'
        from gems/rubocop-0.34.2/lib/rubocop/cli.rb:26:in `run'
<snip>
> rubocop --version
0.34.2

Reverting to the default settings for Style/AlignHash means this issue is no longer seen.

@jonas054 jonas054 self-assigned this Sep 28, 2015
@jonas054
Copy link
Collaborator

My bad. If the ExtraSpacing cop removes spaces anywhere between a key and a value in a hash literal, it can unalign something that was aligned. Will fix.

bbatsov added a commit that referenced this issue Oct 4, 2015
[Fix #2280] Avoid everything between key, value in ExtraSpacing
durandom added a commit to durandom/guides that referenced this issue Jul 7, 2016
bdunne pushed a commit to ManageIQ/manageiq-style that referenced this issue May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants