From 7911fa32451214b39c133b16b14ecfe834a2a393 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 21:43:57 +0200 Subject: [PATCH 01/29] Change spaces_after_comma to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../align_hash_keys.rb.spec | 2 +- .../array_literal.rb.spec | 130 +++++------ .../formatter_source_specs/blocks.rb.spec | 94 ++++---- .../calls_with_receiver.rb.spec | 72 +++--- .../hash_literal.rb.spec | 2 +- .../method_calls.rb.spec | 220 +++++++++--------- .../multiple_assignments.rb.spec | 40 ++-- .../spaces_after_comma.rb.spec | 74 ------ 10 files changed, 281 insertions(+), 356 deletions(-) diff --git a/.rufo b/.rufo index 473176c5..44923546 100644 --- a/.rufo +++ b/.rufo @@ -6,7 +6,6 @@ spaces_in_ternary :one spaces_in_suffix :one spaces_in_commands :dynamic spaces_around_block_brace :one -spaces_after_comma :dynamic spaces_around_hash_arrow :one spaces_around_when :one spaces_around_dot :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 2f549ca3..4cfa9592 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -8,7 +8,7 @@ def init_settings(options) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) spaces_around_block_brace options.fetch(:spaces_around_block_brace, :dynamic) - spaces_after_comma options.fetch(:spaces_after_comma, :dynamic) + spaces_after_comma options.fetch(:spaces_after_comma, :one) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec b/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec index e9e9e299..06914980 100644 --- a/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec @@ -246,7 +246,7 @@ foo 1, :bar => 2 , :baz => 3 #~# EXPECTED -foo 1, :bar => 2, :baz => 3 +foo 1, :bar => 2, :baz => 3 #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec b/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec index 2e6ca930..15d2557a 100644 --- a/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec @@ -1,39 +1,39 @@ -#~# ORIGINAL +#~# ORIGINAL - [ ] + [ ] #~# EXPECTED [] -#~# ORIGINAL +#~# ORIGINAL - [ 1 ] + [ 1 ] #~# EXPECTED [ 1 ] -#~# ORIGINAL +#~# ORIGINAL - [ 1 , 2 ] + [ 1 , 2 ] #~# EXPECTED [ 1, 2 ] -#~# ORIGINAL +#~# ORIGINAL - [ 1 , 2 , ] + [ 1 , 2 , ] #~# EXPECTED [ 1, 2 ] -#~# ORIGINAL +#~# ORIGINAL - [ - 1 , 2 ] + [ + 1 , 2 ] #~# EXPECTED @@ -41,10 +41,10 @@ 1, 2 ] -#~# ORIGINAL +#~# ORIGINAL - [ - 1 , 2, ] + [ + 1 , 2, ] #~# EXPECTED @@ -52,11 +52,11 @@ 1, 2, ] -#~# ORIGINAL +#~# ORIGINAL - [ - 1 , 2 , - 3 , 4 ] + [ + 1 , 2 , + 3 , 4 ] #~# EXPECTED @@ -65,11 +65,11 @@ 3, 4 ] -#~# ORIGINAL +#~# ORIGINAL - [ - 1 , - 2] + [ + 1 , + 2] #~# EXPECTED @@ -78,11 +78,11 @@ 2 ] -#~# ORIGINAL +#~# ORIGINAL - [ # comment - 1 , - 2] + [ # comment + 1 , + 2] #~# EXPECTED @@ -91,11 +91,11 @@ 2 ] -#~# ORIGINAL +#~# ORIGINAL - [ - 1 , # comment - 2] + [ + 1 , # comment + 2] #~# EXPECTED @@ -104,11 +104,11 @@ 2 ] -#~# ORIGINAL +#~# ORIGINAL - [ 1 , - 2, 3, - 4 ] + [ 1 , + 2, 3, + 4 ] #~# EXPECTED @@ -116,11 +116,11 @@ 2, 3, 4 ] -#~# ORIGINAL +#~# ORIGINAL - [ 1 , - 2, 3, - 4, ] + [ 1 , + 2, 3, + 4, ] #~# EXPECTED @@ -128,12 +128,12 @@ 2, 3, 4 ] -#~# ORIGINAL +#~# ORIGINAL - [ 1 , - 2, 3, + [ 1 , + 2, 3, 4, - ] + ] #~# EXPECTED @@ -141,12 +141,12 @@ 2, 3, 4 ] -#~# ORIGINAL +#~# ORIGINAL - [ 1 , - 2, 3, - 4, # foo - ] + [ 1 , + 2, 3, + 4, # foo + ] #~# EXPECTED @@ -155,12 +155,12 @@ 4 # foo ] -#~# ORIGINAL +#~# ORIGINAL begin - [ - 1 , 2 ] - end + [ + 1 , 2 ] + end #~# EXPECTED @@ -170,9 +170,9 @@ begin ] end -#~# ORIGINAL +#~# ORIGINAL - [ + [ 1 # foo ] @@ -182,31 +182,31 @@ end 1 # foo ] -#~# ORIGINAL +#~# ORIGINAL - [ *x ] + [ *x ] #~# EXPECTED [ *x ] -#~# ORIGINAL +#~# ORIGINAL - [ *x , 1 ] + [ *x , 1 ] #~# EXPECTED [ *x, 1 ] -#~# ORIGINAL +#~# ORIGINAL - [ 1, *x ] + [ 1, *x ] #~# EXPECTED [ 1, *x ] -#~# ORIGINAL +#~# ORIGINAL x = [{ foo: 1 @@ -218,15 +218,15 @@ x = [{ foo: 1 }] -#~# ORIGINAL +#~# ORIGINAL [1, 2] #~# EXPECTED -[1, 2] +[1, 2] -#~# ORIGINAL +#~# ORIGINAL [ 1, @@ -242,7 +242,7 @@ x = [{ 2, ] -#~# ORIGINAL +#~# ORIGINAL [ *a, @@ -256,7 +256,7 @@ x = [{ b, ] -#~# ORIGINAL +#~# ORIGINAL [ 1, *a, diff --git a/spec/lib/rufo/formatter_source_specs/blocks.rb.spec b/spec/lib/rufo/formatter_source_specs/blocks.rb.spec index 1e32f697..f9ce5df7 100644 --- a/spec/lib/rufo/formatter_source_specs/blocks.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/blocks.rb.spec @@ -1,4 +1,4 @@ -#~# ORIGINAL +#~# ORIGINAL foo {} @@ -6,7 +6,7 @@ foo {} foo {} -#~# ORIGINAL +#~# ORIGINAL foo { } @@ -14,7 +14,7 @@ foo { } foo { } -#~# ORIGINAL +#~# ORIGINAL foo { 1 } @@ -22,7 +22,7 @@ foo { 1 } foo { 1 } -#~# ORIGINAL +#~# ORIGINAL foo { 1 ; 2 } @@ -30,9 +30,9 @@ foo { 1 ; 2 } foo { 1; 2 } -#~# ORIGINAL +#~# ORIGINAL -foo { 1 +foo { 1 2 } #~# EXPECTED @@ -42,9 +42,9 @@ foo { 2 } -#~# ORIGINAL +#~# ORIGINAL -foo { +foo { 1 } #~# EXPECTED @@ -53,10 +53,10 @@ foo { 1 } -#~# ORIGINAL +#~# ORIGINAL -begin - foo { 1 } +begin + foo { 1 } end #~# EXPECTED @@ -65,7 +65,7 @@ begin foo { 1 } end -#~# ORIGINAL +#~# ORIGINAL foo { | x , y | } @@ -73,7 +73,7 @@ foo { | x , y | } foo { |x, y| } -#~# ORIGINAL +#~# ORIGINAL foo { | x , | } @@ -81,7 +81,7 @@ foo { | x , | } foo { |x, | } -#~# ORIGINAL +#~# ORIGINAL foo { | x , y, | bar} @@ -89,7 +89,7 @@ foo { | x , y, | bar} foo { |x, y, | bar} -#~# ORIGINAL +#~# ORIGINAL foo { || } @@ -97,7 +97,7 @@ foo { || } foo { } -#~# ORIGINAL +#~# ORIGINAL foo { | | } @@ -105,7 +105,7 @@ foo { | | } foo { } -#~# ORIGINAL +#~# ORIGINAL foo { | ( x ) , z | } @@ -113,7 +113,7 @@ foo { | ( x ) , z | } foo { |(x), z| } -#~# ORIGINAL +#~# ORIGINAL foo { | ( x , y ) , z | } @@ -121,7 +121,7 @@ foo { | ( x , y ) , z | } foo { |(x, y), z| } -#~# ORIGINAL +#~# ORIGINAL foo { | ( x , ( y , w ) ) , z | } @@ -129,7 +129,7 @@ foo { | ( x , ( y , w ) ) , z | } foo { |(x, (y, w)), z| } -#~# ORIGINAL +#~# ORIGINAL foo { | bar: 1 , baz: 2 | } @@ -137,7 +137,7 @@ foo { | bar: 1 , baz: 2 | } foo { |bar: 1, baz: 2| } -#~# ORIGINAL +#~# ORIGINAL foo { | *z | } @@ -145,7 +145,7 @@ foo { | *z | } foo { |*z| } -#~# ORIGINAL +#~# ORIGINAL foo { | **z | } @@ -153,7 +153,7 @@ foo { | **z | } foo { |**z| } -#~# ORIGINAL +#~# ORIGINAL foo { | bar = 1 | } @@ -161,7 +161,7 @@ foo { | bar = 1 | } foo { |bar = 1| } -#~# ORIGINAL +#~# ORIGINAL foo { | x , y | 1 } @@ -169,9 +169,9 @@ foo { | x , y | 1 } foo { |x, y| 1 } -#~# ORIGINAL +#~# ORIGINAL -foo { | x | +foo { | x | 1 } #~# EXPECTED @@ -180,10 +180,10 @@ foo { |x| 1 } -#~# ORIGINAL +#~# ORIGINAL -foo { | x , - y | +foo { | x , + y | 1 } #~# EXPECTED @@ -193,7 +193,7 @@ foo { |x, 1 } -#~# ORIGINAL +#~# ORIGINAL foo do end @@ -201,7 +201,7 @@ foo do end foo do end -#~# ORIGINAL +#~# ORIGINAL foo do 1 end @@ -209,10 +209,10 @@ foo do 1 end foo do 1 end -#~# ORIGINAL +#~# ORIGINAL -bar foo { - 1 +bar foo { + 1 }, 2 #~# EXPECTED @@ -221,10 +221,10 @@ bar foo { 1 }, 2 -#~# ORIGINAL +#~# ORIGINAL -bar foo { - 1 +bar foo { + 1 } + 2 #~# EXPECTED @@ -233,7 +233,7 @@ bar foo { 1 } + 2 -#~# ORIGINAL +#~# ORIGINAL foo { |;x| } @@ -241,7 +241,7 @@ foo { |;x| } foo { |; x| } -#~# ORIGINAL +#~# ORIGINAL foo { | ;x| } @@ -250,7 +250,7 @@ foo { | foo { |; x| } -#~# ORIGINAL +#~# ORIGINAL foo { |;x, y| } @@ -258,7 +258,7 @@ foo { |;x, y| } foo { |; x, y| } -#~# ORIGINAL +#~# ORIGINAL foo { |a, b;x, y| } @@ -266,15 +266,15 @@ foo { |a, b;x, y| } foo { |a, b; x, y| } -#~# ORIGINAL +#~# ORIGINAL proc { |(x, *y),z| } #~# EXPECTED -proc { |(x, *y),z| } +proc { |(x, *y), z| } -#~# ORIGINAL +#~# ORIGINAL proc { |(w, *x, y), z| } @@ -282,7 +282,7 @@ proc { |(w, *x, y), z| } proc { |(w, *x, y), z| } -#~# ORIGINAL +#~# ORIGINAL foo { |(*x, y), z| } @@ -290,7 +290,7 @@ foo { |(*x, y), z| } foo { |(*x, y), z| } -#~# ORIGINAL +#~# ORIGINAL foo { begin; end; } @@ -298,7 +298,7 @@ foo { begin; end; } foo { begin; end } -#~# ORIGINAL +#~# ORIGINAL foo { |i| } diff --git a/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec b/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec index e49b4a58..9b36dfe7 100644 --- a/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec @@ -1,4 +1,4 @@ -#~# ORIGINAL +#~# ORIGINAL foo . bar . baz @@ -6,7 +6,7 @@ foo . bar . baz foo . bar . baz -#~# ORIGINAL +#~# ORIGINAL foo . bar( 1 , 2 ) @@ -14,9 +14,9 @@ foo . bar( 1 , 2 ) foo . bar(1, 2) -#~# ORIGINAL +#~# ORIGINAL -foo . +foo . bar #~# EXPECTED @@ -24,10 +24,10 @@ foo . foo . bar -#~# ORIGINAL +#~# ORIGINAL -foo . - bar . +foo . + bar . baz #~# EXPECTED @@ -36,9 +36,9 @@ foo . bar . baz -#~# ORIGINAL +#~# ORIGINAL -foo +foo . bar #~# EXPECTED @@ -46,10 +46,10 @@ foo foo . bar -#~# ORIGINAL +#~# ORIGINAL -foo - . bar +foo + . bar . baz #~# EXPECTED @@ -58,7 +58,7 @@ foo . bar . baz -#~# ORIGINAL +#~# ORIGINAL foo.bar .baz @@ -68,7 +68,7 @@ foo.bar foo.bar .baz -#~# ORIGINAL +#~# ORIGINAL foo.bar(1) .baz(2) @@ -80,7 +80,7 @@ foo.bar(1) .baz(2) .qux(3) -#~# ORIGINAL +#~# ORIGINAL foobar.baz .with( @@ -94,10 +94,10 @@ foobar.baz 1 ) -#~# ORIGINAL +#~# ORIGINAL -foo.bar 1, - x: 1, +foo.bar 1, + x: 1, y: 2 #~# EXPECTED @@ -106,7 +106,7 @@ foo.bar 1, x: 1, y: 2 -#~# ORIGINAL +#~# ORIGINAL foo .bar # x @@ -118,7 +118,7 @@ foo .bar # x .baz -#~# ORIGINAL +#~# ORIGINAL c.x w 1 @@ -126,7 +126,7 @@ c.x w 1 c.x w 1 -#~# ORIGINAL +#~# ORIGINAL foo.bar .baz @@ -138,7 +138,7 @@ foo.bar .baz .baz -#~# ORIGINAL +#~# ORIGINAL foo.bar .baz @@ -150,7 +150,7 @@ foo.bar .baz .baz -#~# ORIGINAL +#~# ORIGINAL foo.bar(1) .baz([ @@ -164,7 +164,7 @@ foo.bar(1) 2, ]) -#~# ORIGINAL +#~# ORIGINAL foo.bar(1) .baz( @@ -178,7 +178,7 @@ foo.bar(1) 2, ) -#~# ORIGINAL +#~# ORIGINAL foo.bar(1) .baz( @@ -196,7 +196,7 @@ foo.bar(1) ) ) -#~# ORIGINAL +#~# ORIGINAL foo.bar(1) .baz( @@ -214,7 +214,7 @@ foo.bar(1) ) ) -#~# ORIGINAL +#~# ORIGINAL foo.bar( 1 @@ -226,7 +226,7 @@ foo.bar( 1 ) -#~# ORIGINAL +#~# ORIGINAL foo 1, [ 2, @@ -242,7 +242,7 @@ foo 1, [ 3, ] -#~# ORIGINAL +#~# ORIGINAL foo :x, { :foo1 => :bar, @@ -266,7 +266,7 @@ multiline :call, :foo => :bar, :foo => bar -#~# ORIGINAL +#~# ORIGINAL x .foo.bar @@ -278,7 +278,7 @@ x .foo.bar .baz -#~# ORIGINAL +#~# ORIGINAL x .foo.bar.baz @@ -290,7 +290,7 @@ x .foo.bar.baz .qux -#~# ORIGINAL +#~# ORIGINAL x .foo(a.b).bar(c.d).baz(e.f) @@ -304,15 +304,15 @@ x .qux.z(a.b) .final -#~# ORIGINAL +#~# ORIGINAL x.y 1, 2 #~# EXPECTED -x.y 1, 2 +x.y 1, 2 -#~# ORIGINAL +#~# ORIGINAL x.y \ 1, 2 @@ -320,4 +320,4 @@ x.y \ #~# EXPECTED x.y \ - 1, 2 + 1, 2 diff --git a/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec b/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec index b816c8fc..01359227 100644 --- a/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec @@ -124,7 +124,7 @@ #~# EXPECTED -{foo: 1, bar: 2} +{foo: 1, bar: 2} #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec index fa0a81ca..94ec81da 100644 --- a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec @@ -6,7 +6,7 @@ foo foo -#~# ORIGINAL +#~# ORIGINAL foo() @@ -14,7 +14,7 @@ foo() foo() -#~# ORIGINAL +#~# ORIGINAL foo () @@ -22,7 +22,7 @@ foo () foo () -#~# ORIGINAL +#~# ORIGINAL foo( ) @@ -30,9 +30,9 @@ foo( ) foo() -#~# ORIGINAL +#~# ORIGINAL -foo( +foo( ) @@ -40,7 +40,7 @@ foo( foo() -#~# ORIGINAL +#~# ORIGINAL foo( 1 ) @@ -48,15 +48,15 @@ foo( 1 ) foo(1) -#~# ORIGINAL +#~# ORIGINAL foo( 1 , 2 ) #~# EXPECTED -foo(1, 2) +foo(1, 2) -#~# ORIGINAL +#~# ORIGINAL foo 1 @@ -64,83 +64,83 @@ foo 1 foo 1 -#~# ORIGINAL +#~# ORIGINAL foo 1, 2 #~# EXPECTED -foo 1, 2 +foo 1, 2 -#~# ORIGINAL +#~# ORIGINAL foo 1, *x #~# EXPECTED -foo 1, *x +foo 1, *x -#~# ORIGINAL +#~# ORIGINAL -foo 1, *x , 2 +foo 1, *x , 2 #~# EXPECTED -foo 1, *x, 2 +foo 1, *x, 2 -#~# ORIGINAL +#~# ORIGINAL -foo 1, *x , 2 , 3 +foo 1, *x , 2 , 3 #~# EXPECTED -foo 1, *x, 2, 3 +foo 1, *x, 2, 3 -#~# ORIGINAL +#~# ORIGINAL foo 1, *x , 2 , 3 , *z , *w , 4 #~# EXPECTED -foo 1, *x, 2, 3, *z, *w, 4 +foo 1, *x, 2, 3, *z, *w, 4 -#~# ORIGINAL +#~# ORIGINAL -foo *x +foo *x #~# EXPECTED foo *x -#~# ORIGINAL +#~# ORIGINAL -foo 1, - *x +foo 1, + *x #~# EXPECTED foo 1, *x -#~# ORIGINAL +#~# ORIGINAL -foo 1, *x , *y +foo 1, *x , *y #~# EXPECTED -foo 1, *x, *y +foo 1, *x, *y -#~# ORIGINAL +#~# ORIGINAL foo 1, **x #~# EXPECTED -foo 1, **x +foo 1, **x -#~# ORIGINAL +#~# ORIGINAL -foo 1, +foo 1, **x #~# EXPECTED @@ -148,25 +148,25 @@ foo 1, foo 1, **x -#~# ORIGINAL +#~# ORIGINAL foo 1, **x , **y #~# EXPECTED -foo 1, **x, **y +foo 1, **x, **y -#~# ORIGINAL +#~# ORIGINAL foo 1, bar: 2 , baz: 3 #~# EXPECTED -foo 1, bar: 2, baz: 3 +foo 1, bar: 2, baz: 3 -#~# ORIGINAL +#~# ORIGINAL -foo 1, +foo 1, bar: 2 , baz: 3 #~# EXPECTED @@ -174,9 +174,9 @@ foo 1, foo 1, bar: 2, baz: 3 -#~# ORIGINAL +#~# ORIGINAL -foo 1, +foo 1, 2 #~# EXPECTED @@ -184,9 +184,9 @@ foo 1, foo 1, 2 -#~# ORIGINAL +#~# ORIGINAL -foo(1, +foo(1, 2) #~# EXPECTED @@ -194,10 +194,10 @@ foo(1, foo(1, 2) -#~# ORIGINAL +#~# ORIGINAL foo( -1, +1, 2) #~# EXPECTED @@ -207,10 +207,10 @@ foo( 2 ) -#~# ORIGINAL +#~# ORIGINAL foo( -1, +1, 2,) #~# EXPECTED @@ -220,11 +220,11 @@ foo( 2, ) -#~# ORIGINAL +#~# ORIGINAL foo( -1, - 2 +1, + 2 ) #~# EXPECTED @@ -234,13 +234,13 @@ foo( 2 ) -#~# ORIGINAL +#~# ORIGINAL begin foo( -1, - 2 -) +1, + 2 +) end #~# EXPECTED @@ -252,12 +252,12 @@ begin ) end -#~# ORIGINAL +#~# ORIGINAL begin - foo(1, - 2 - ) + foo(1, + 2 + ) end #~# EXPECTED @@ -267,12 +267,12 @@ begin 2) end -#~# ORIGINAL +#~# ORIGINAL begin - foo(1, - 2, - ) + foo(1, + 2, + ) end #~# EXPECTED @@ -282,13 +282,13 @@ begin 2) end -#~# ORIGINAL +#~# ORIGINAL begin foo( - 1, - 2, - ) + 1, + 2, + ) end #~# EXPECTED @@ -300,12 +300,12 @@ begin ) end -#~# ORIGINAL +#~# ORIGINAL begin foo( - 1, - 2, ) + 1, + 2, ) end #~# EXPECTED @@ -317,12 +317,12 @@ begin ) end -#~# ORIGINAL +#~# ORIGINAL begin foo( -1, - 2) +1, + 2) end #~# EXPECTED @@ -334,13 +334,13 @@ begin ) end -#~# ORIGINAL +#~# ORIGINAL begin foo( -1, +1, 2 # comment -) +) end #~# EXPECTED @@ -352,7 +352,7 @@ begin ) end -#~# ORIGINAL +#~# ORIGINAL foo(bar( 1, @@ -364,7 +364,7 @@ foo(bar( 1, )) -#~# ORIGINAL +#~# ORIGINAL foo(bar( 1, @@ -382,7 +382,7 @@ foo(bar( ) )) -#~# ORIGINAL +#~# ORIGINAL foo &block @@ -390,23 +390,23 @@ foo &block foo &block -#~# ORIGINAL +#~# ORIGINAL foo 1 , &block #~# EXPECTED -foo 1, &block +foo 1, &block -#~# ORIGINAL +#~# ORIGINAL foo(1 , &block) #~# EXPECTED -foo(1, &block) +foo(1, &block) -#~# ORIGINAL +#~# ORIGINAL x y z @@ -414,7 +414,7 @@ x y z x y z -#~# ORIGINAL +#~# ORIGINAL x y z w, q @@ -422,7 +422,7 @@ x y z w, q x y z w, q -#~# ORIGINAL +#~# ORIGINAL x(*y, &z) @@ -430,7 +430,7 @@ x(*y, &z) x(*y, &z) -#~# ORIGINAL +#~# ORIGINAL foo \ 1, 2 @@ -440,7 +440,7 @@ foo \ foo \ 1, 2 -#~# ORIGINAL +#~# ORIGINAL a( *b) @@ -451,7 +451,7 @@ a( *b ) -#~# ORIGINAL +#~# ORIGINAL foo( x: 1, @@ -465,7 +465,7 @@ foo( y: 2 ) -#~# ORIGINAL +#~# ORIGINAL foo bar( 1, @@ -477,7 +477,7 @@ foo bar( 1, ) -#~# ORIGINAL +#~# ORIGINAL foo 1, { x: y, @@ -489,7 +489,7 @@ foo 1, { x: y, } -#~# ORIGINAL +#~# ORIGINAL foo 1, [ 1, @@ -501,7 +501,7 @@ foo 1, [ 1, ] -#~# ORIGINAL +#~# ORIGINAL foo 1, [ <<-EOF, @@ -517,7 +517,7 @@ foo 1, [ EOF ] -#~# ORIGINAL +#~# ORIGINAL foo bar( # foo 1, # bar @@ -529,7 +529,7 @@ foo bar( # foo 1, # bar ) -#~# ORIGINAL +#~# ORIGINAL foo bar { 1 @@ -541,7 +541,7 @@ foo bar { 1 } -#~# ORIGINAL +#~# ORIGINAL foo x: 1 @@ -549,7 +549,7 @@ foo x: 1 foo x: 1 -#~# ORIGINAL +#~# ORIGINAL foo( &block @@ -561,7 +561,7 @@ foo( &block ) -#~# ORIGINAL +#~# ORIGINAL foo( 1, @@ -575,7 +575,7 @@ foo( &block ) -#~# ORIGINAL +#~# ORIGINAL foo(& block) @@ -583,7 +583,7 @@ foo(& block) foo(&block) -#~# ORIGINAL +#~# ORIGINAL foo 1, [ 2, @@ -595,7 +595,7 @@ foo 1, [ 2, ] -#~# ORIGINAL +#~# ORIGINAL foo 1, [ 2, @@ -607,7 +607,7 @@ foo 1, [ 2, ] -#~# ORIGINAL +#~# ORIGINAL foo bar( 2 @@ -619,7 +619,7 @@ foo bar( 2 ) -#~# ORIGINAL +#~# ORIGINAL foo bar( 2 @@ -631,7 +631,7 @@ foo bar( 2 ) -#~# ORIGINAL +#~# ORIGINAL foo bar { 2 @@ -643,7 +643,7 @@ foo bar { 2 } -#~# ORIGINAL +#~# ORIGINAL foo bar { 2 @@ -655,7 +655,7 @@ foo bar { 2 } -#~# ORIGINAL +#~# ORIGINAL foobar 1, 2 @@ -665,7 +665,7 @@ foobar 1, foobar 1, 2 -#~# ORIGINAL +#~# ORIGINAL begin foobar 1, @@ -679,7 +679,7 @@ begin 2 end -#~# ORIGINAL +#~# ORIGINAL foo([ 1, @@ -691,7 +691,7 @@ foo([ 1, ]) -#~# ORIGINAL +#~# ORIGINAL begin foo([ @@ -707,7 +707,7 @@ begin ]) end -#~# ORIGINAL +#~# ORIGINAL (a b).c([ 1, @@ -719,7 +719,7 @@ end 1, ]) -#~# ORIGINAL +#~# ORIGINAL foobar 1, "foo diff --git a/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec b/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec index 21554227..147dfb25 100644 --- a/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec @@ -1,28 +1,28 @@ -#~# ORIGINAL +#~# ORIGINAL a = 1 , 2 #~# EXPECTED -a = 1, 2 +a = 1, 2 -#~# ORIGINAL +#~# ORIGINAL -a , b = 2 +a , b = 2 #~# EXPECTED a, b = 2 -#~# ORIGINAL +#~# ORIGINAL -a , b, ( c, d ) = 2 +a , b, ( c, d ) = 2 #~# EXPECTED a, b, (c, d) = 2 -#~# ORIGINAL +#~# ORIGINAL *x = 1 @@ -30,7 +30,7 @@ a, b, (c, d) = 2 *x = 1 -#~# ORIGINAL +#~# ORIGINAL a , b , *x = 1 @@ -38,7 +38,7 @@ a, b, (c, d) = 2 a, b, *x = 1 -#~# ORIGINAL +#~# ORIGINAL *x , a , b = 1 @@ -46,7 +46,7 @@ a, b, *x = 1 *x, a, b = 1 -#~# ORIGINAL +#~# ORIGINAL a, b, *x, c, d = 1 @@ -54,7 +54,7 @@ a, b, *x = 1 a, b, *x, c, d = 1 -#~# ORIGINAL +#~# ORIGINAL a, b, = 1 @@ -62,7 +62,7 @@ a, b, = 1 a, b, = 1 -#~# ORIGINAL +#~# ORIGINAL a = b, *c @@ -70,7 +70,7 @@ a = b, *c a = b, *c -#~# ORIGINAL +#~# ORIGINAL a = b, *c, *d @@ -78,7 +78,7 @@ a = b, *c, *d a = b, *c, *d -#~# ORIGINAL +#~# ORIGINAL a, = b @@ -86,7 +86,7 @@ a, = b a, = b -#~# ORIGINAL +#~# ORIGINAL a = b, c, *d @@ -94,7 +94,7 @@ a = b, c, *d a = b, c, *d -#~# ORIGINAL +#~# ORIGINAL a = b, c, *d, e @@ -102,7 +102,7 @@ a = b, c, *d, e a = b, c, *d, e -#~# ORIGINAL +#~# ORIGINAL *, y = z @@ -110,7 +110,7 @@ a = b, c, *d, e *, y = z -#~# ORIGINAL +#~# ORIGINAL w, (x,), y = z @@ -118,7 +118,7 @@ w, (x,), y = z w, (x,), y = z -#~# ORIGINAL +#~# ORIGINAL a, b=1, 2 @@ -126,7 +126,7 @@ a, b=1, 2 a, b=1, 2 -#~# ORIGINAL +#~# ORIGINAL * = 1 diff --git a/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec index e39ae89b..834b4ee3 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec @@ -7,15 +7,6 @@ foo 1, 2, 3 foo 1, 2, 3 -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -foo 1, 2, 3 - -#~# EXPECTED - -foo 1, 2, 3 - #~# ORIGINAL #~# spaces_after_comma: :one @@ -25,15 +16,6 @@ foo(1, 2, 3) foo(1, 2, 3) -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -foo(1, 2, 3) - -#~# EXPECTED - -foo(1, 2, 3) - #~# ORIGINAL #~# spaces_after_comma: :one @@ -43,15 +25,6 @@ foo(1,2,3,x:1,y:2) foo(1, 2, 3, x:1, y:2) -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -foo(1,2,3,x:1,y:2) - -#~# EXPECTED - -foo(1,2,3,x:1,y:2) - #~# ORIGINAL #~# spaces_after_comma: :one @@ -63,17 +36,6 @@ end def foo(x, y) end -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -def foo(x,y) -end - -#~# EXPECTED - -def foo(x,y) -end - #~# ORIGINAL #~# spaces_after_comma: :one @@ -83,15 +45,6 @@ end [1, 2, 3] -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -[1, 2, 3] - -#~# EXPECTED - -[1, 2, 3] - #~# ORIGINAL #~# spaces_after_comma: :one @@ -101,15 +54,6 @@ end [1, 2, 3] -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -[1,2,3] - -#~# EXPECTED - -[1,2,3] - #~# ORIGINAL #~# spaces_after_comma: :one @@ -119,15 +63,6 @@ a , b = 1, 2 a, b = 1, 2 -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -a , b = 1, 2 - -#~# EXPECTED - -a, b = 1, 2 - #~# ORIGINAL #~# spaces_after_comma: :one @@ -137,12 +72,3 @@ a,b = 1,2 a, b = 1, 2 -#~# ORIGINAL -#~# spaces_after_comma: :dynamic - -a,b = 1,2 - -#~# EXPECTED - -a,b = 1,2 - From 1abe3f16dd71013ac4f177aeec03176dbf5c31dd Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 21:46:25 +0200 Subject: [PATCH 02/29] Format code base --- lib/rufo/formatter/settings.rb | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 4cfa9592..a9238827 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -1,28 +1,28 @@ class Rufo::Formatter def init_settings(options) - indent_size options.fetch(:indent_size, 2) - spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) - spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) - spaces_around_equal options.fetch(:spaces_around_equal, :dynamic) - spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) - spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) - spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_block_brace options.fetch(:spaces_around_block_brace, :dynamic) - spaces_after_comma options.fetch(:spaces_after_comma, :one) - spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) - spaces_around_when options.fetch(:spaces_around_when, :dynamic) - spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) - spaces_after_lambda_arrow options.fetch(:spaces_after_lambda_arrow, :dynamic) - spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) - spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) - spaces_after_method_name options.fetch(:spaces_after_method_name, :dynamic) + indent_size options.fetch(:indent_size, 2) + spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) + spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) + spaces_around_equal options.fetch(:spaces_around_equal, :dynamic) + spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) + spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) + spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) + spaces_around_block_brace options.fetch(:spaces_around_block_brace, :dynamic) + spaces_after_comma options.fetch(:spaces_after_comma, :one) + spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) + spaces_around_when options.fetch(:spaces_around_when, :dynamic) + spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) + spaces_after_lambda_arrow options.fetch(:spaces_after_lambda_arrow, :dynamic) + spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) + spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) + spaces_after_method_name options.fetch(:spaces_after_method_name, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) - parens_in_def options.fetch(:parens_in_def, :dynamic) - double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic) - visibility_indent options.fetch(:visibility_indent, :dynamic) - align_case_when options.fetch(:align_case_when, false) - align_chained_calls options.fetch(:align_chained_calls, false) - trailing_commas options.fetch(:trailing_commas, :dynamic) + parens_in_def options.fetch(:parens_in_def, :dynamic) + double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic) + visibility_indent options.fetch(:visibility_indent, :dynamic) + align_case_when options.fetch(:align_case_when, false) + align_chained_calls options.fetch(:align_chained_calls, false) + trailing_commas options.fetch(:trailing_commas, :dynamic) end def indent_size(value) From e8d0feec35b054e78b0d0b7650da9aee95417aa2 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 21:52:37 +0200 Subject: [PATCH 03/29] Remove spaces_after_comma config --- lib/rufo/formatter.rb | 8 +++----- lib/rufo/formatter/settings.rb | 4 ---- .../formatter_source_specs/spaces_after_comma.rb.spec | 8 -------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index d509531f..c9738c8b 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -1689,7 +1689,7 @@ def visit_comma_separated_list(nodes) check :on_comma write "," next_token - skip_space_or_newline_using_setting(@spaces_after_comma, base_column || @indent) + skip_space_or_newline_using_setting(:one, base_column || @indent) end end @@ -2103,7 +2103,7 @@ def write_params_comma check :on_comma write "," next_token - skip_space_or_newline_using_setting(@spaces_after_comma) + skip_space_or_newline_using_setting(:one) end def visit_array(node) @@ -2681,9 +2681,7 @@ def visit_literal_elements(elements, inside_hash: false, inside_array: false, to write_indent end end - elsif !is_last && first_space && @spaces_after_comma == :dynamic - write_space first_space[2] - elsif @spaces_after_comma == :one + else write_space unless is_last end end diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index a9238827..2dab3ed3 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -8,7 +8,6 @@ def init_settings(options) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) spaces_around_block_brace options.fetch(:spaces_around_block_brace, :dynamic) - spaces_after_comma options.fetch(:spaces_after_comma, :one) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) @@ -57,9 +56,6 @@ def spaces_around_block_brace(value) @spaces_around_block_brace = one_dynamic("spaces_around_block_brace", value) end - def spaces_after_comma(value) - @spaces_after_comma = one_dynamic("spaces_after_comma", value) - end def spaces_around_hash_arrow(value) @spaces_around_hash_arrow = one_dynamic("spaces_around_hash_arrow", value) diff --git a/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec index 834b4ee3..f3951ee3 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_after_comma: :one foo 1, 2, 3 @@ -8,7 +7,6 @@ foo 1, 2, 3 foo 1, 2, 3 #~# ORIGINAL -#~# spaces_after_comma: :one foo(1, 2, 3) @@ -17,7 +15,6 @@ foo(1, 2, 3) foo(1, 2, 3) #~# ORIGINAL -#~# spaces_after_comma: :one foo(1,2,3,x:1,y:2) @@ -26,7 +23,6 @@ foo(1,2,3,x:1,y:2) foo(1, 2, 3, x:1, y:2) #~# ORIGINAL -#~# spaces_after_comma: :one def foo(x,y) end @@ -37,7 +33,6 @@ def foo(x, y) end #~# ORIGINAL -#~# spaces_after_comma: :one [1, 2, 3] @@ -46,7 +41,6 @@ end [1, 2, 3] #~# ORIGINAL -#~# spaces_after_comma: :one [1,2,3] @@ -55,7 +49,6 @@ end [1, 2, 3] #~# ORIGINAL -#~# spaces_after_comma: :one a , b = 1, 2 @@ -64,7 +57,6 @@ a , b = 1, 2 a, b = 1, 2 #~# ORIGINAL -#~# spaces_after_comma: :one a,b = 1,2 From ead784c9f0663f8fdc3ac9fbd3df0669fdeb354d Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 22:15:27 +0200 Subject: [PATCH 04/29] Change spaces_after_lambda_arrow config --- .rufo | 1 - lib/rufo/formatter/settings.rb | 3 +- spec/lib/rufo/command_spec.rb | 6 +-- .../formatter_source_specs/lambdas.rb.spec | 50 +++++++++---------- .../spaces_after_lambda_arrow.rb.spec | 20 -------- .../spaces_around_block_brace.rb.spec | 4 +- 6 files changed, 31 insertions(+), 53 deletions(-) diff --git a/.rufo b/.rufo index 44923546..1c7bf55d 100644 --- a/.rufo +++ b/.rufo @@ -9,7 +9,6 @@ spaces_around_block_brace :one spaces_around_hash_arrow :one spaces_around_when :one spaces_around_dot :no -spaces_after_lambda_arrow :no spaces_around_unary :no spaces_around_binary :one parens_in_def :yes diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 2dab3ed3..f7a814ed 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -11,7 +11,7 @@ def init_settings(options) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) - spaces_after_lambda_arrow options.fetch(:spaces_after_lambda_arrow, :dynamic) + spaces_after_lambda_arrow options.fetch(:spaces_after_lambda_arrow, :one) spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_after_method_name options.fetch(:spaces_after_method_name, :dynamic) @@ -56,7 +56,6 @@ def spaces_around_block_brace(value) @spaces_around_block_brace = one_dynamic("spaces_around_block_brace", value) end - def spaces_around_hash_arrow(value) @spaces_around_hash_arrow = one_dynamic("spaces_around_hash_arrow", value) end diff --git a/spec/lib/rufo/command_spec.rb b/spec/lib/rufo/command_spec.rb index ed85ffd0..de5f2827 100644 --- a/spec/lib/rufo/command_spec.rb +++ b/spec/lib/rufo/command_spec.rb @@ -39,7 +39,7 @@ def status_code describe "files" do describe "check" do - subject { ->{ described_class.run(["-c", file]) } } + subject { -> { described_class.run(["-c", file]) } } context "missing file" do let(:file) { "missing.rb" } @@ -107,7 +107,7 @@ def status_code describe "STDIN" do describe "check" do - subject { ->{ described_class.run(["-c"]) } } + subject { -> { described_class.run(["-c"]) } } before(:example) { expect(STDIN).to receive(:read).and_return code } context "no code" do @@ -132,7 +132,7 @@ def status_code end describe "format" do - subject { ->{ described_class.run([]) } } + subject { -> { described_class.run([]) } } before(:example) { expect(STDIN).to receive(:read).and_return code } context "no code" do diff --git a/spec/lib/rufo/formatter_source_specs/lambdas.rb.spec b/spec/lib/rufo/formatter_source_specs/lambdas.rb.spec index 16effedb..4ab15959 100644 --- a/spec/lib/rufo/formatter_source_specs/lambdas.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/lambdas.rb.spec @@ -1,51 +1,51 @@ -#~# ORIGINAL +#~# ORIGINAL --> { } +-> { } #~# EXPECTED -> { } -#~# ORIGINAL +#~# ORIGINAL -->{ } +->{ } #~# EXPECTED -->{ } +-> { } -#~# ORIGINAL +#~# ORIGINAL -->{ 1 } +->{ 1 } #~# EXPECTED -->{ 1 } +-> { 1 } -#~# ORIGINAL +#~# ORIGINAL -->{ 1 ; 2 } +->{ 1 ; 2 } #~# EXPECTED -->{ 1; 2 } +-> { 1; 2 } -#~# ORIGINAL +#~# ORIGINAL -->{ 1 - 2 } +->{ 1 + 2 } #~# EXPECTED -->{ +-> { 1 2 } -#~# ORIGINAL +#~# ORIGINAL --> do 1 - 2 end +-> do 1 + 2 end #~# EXPECTED @@ -54,22 +54,22 @@ 2 end -#~# ORIGINAL +#~# ORIGINAL -->do 1 - 2 end +->do 1 + 2 end #~# EXPECTED -->do +-> do 1 2 end -#~# ORIGINAL +#~# ORIGINAL -->( x ){ } +->( x ){ } #~# EXPECTED -->(x) { } +-> (x) { } diff --git a/spec/lib/rufo/formatter_source_specs/spaces_after_lambda_arrow.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_after_lambda_arrow.rb.spec index 969e0a5f..46fe9ad9 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_after_lambda_arrow.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_after_lambda_arrow.rb.spec @@ -1,23 +1,4 @@ #~# ORIGINAL -#~# spaces_after_lambda_arrow: :dynamic - --> { } - -#~# EXPECTED - --> { } - -#~# ORIGINAL -#~# spaces_after_lambda_arrow: :no - --> { } - -#~# EXPECTED - -->{ } - -#~# ORIGINAL -#~# spaces_after_lambda_arrow: :one -> { } @@ -26,7 +7,6 @@ -> { } #~# ORIGINAL -#~# spaces_after_lambda_arrow: :one ->{ } diff --git a/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec index 85d2260f..538d90e8 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec @@ -59,7 +59,7 @@ foo { 1 } #~# EXPECTED -->{1} +-> {1} #~# ORIGINAL #~# spaces_around_block_brace: :one @@ -68,5 +68,5 @@ foo { 1 } #~# EXPECTED -->{ 1 } +-> { 1 } From 53b58ba7f9036ec7165fc1b200d9a87d746f30de Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 22:24:29 +0200 Subject: [PATCH 05/29] Remove space_after_lambda_arrow config --- lib/rufo/formatter.rb | 2 +- lib/rufo/formatter/settings.rb | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index c9738c8b..6a142f94 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -2450,7 +2450,7 @@ def visit_lambda(node) next_token first_space = skip_space - write_space_using_setting(first_space, @spaces_after_lambda_arrow) + write_space_using_setting(first_space, :one) if empty_params?(params) if current_token_kind == :on_lparen diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index f7a814ed..dc95f46c 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -11,7 +11,6 @@ def init_settings(options) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) - spaces_after_lambda_arrow options.fetch(:spaces_after_lambda_arrow, :one) spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_after_method_name options.fetch(:spaces_after_method_name, :dynamic) @@ -68,10 +67,6 @@ def spaces_around_dot(value) @spaces_around_dot = no_dynamic("spaces_around_dot", value) end - def spaces_after_lambda_arrow(value) - @spaces_after_lambda_arrow = one_no_dynamic("spaces_after_lambda_arrow", value) - end - def spaces_around_unary(value) @spaces_around_unary = no_dynamic("spaces_around_unary", value) end From 1120ebf0556855ee1322d76e695174564bd7824e Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 22:29:34 +0200 Subject: [PATCH 06/29] Remove spaces_after_method_name config --- lib/rufo/formatter.rb | 3 --- lib/rufo/formatter/settings.rb | 5 ---- .../spaces_after_method_name.rb.spec | 24 ------------------- 3 files changed, 32 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 6a142f94..be40d4fb 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -1952,11 +1952,8 @@ def visit_def_from_name(name, params, body) skip_space_or_newline check :on_rparen next_token - write_space_using_setting(first_space, @spaces_after_method_name) write "()" else - write_space_using_setting(first_space, @spaces_after_method_name) - write "(" if newline? || comment? diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index dc95f46c..1eaf1be1 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -13,7 +13,6 @@ def init_settings(options) spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) - spaces_after_method_name options.fetch(:spaces_after_method_name, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic) @@ -75,10 +74,6 @@ def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end - def spaces_after_method_name(value) - @spaces_after_method_name = no_dynamic("spaces_after_method_name", value) - end - def spaces_in_inline_expressions(value) @spaces_in_inline_expressions = one_dynamic("spaces_in_inline_expressions", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_after_method_name.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_after_method_name.rb.spec index 7e9ba994..baa92056 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_after_method_name.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_after_method_name.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_after_method_name: :no def foo (x) end @@ -9,19 +8,8 @@ end def foo(x) end -#~# ORIGINAL -#~# spaces_after_method_name: :dynamic - -def foo (x) -end - -#~# EXPECTED - -def foo (x) -end #~# ORIGINAL -#~# spaces_after_method_name: :no def self.foo (x) end @@ -30,15 +18,3 @@ end def self.foo(x) end - -#~# ORIGINAL -#~# spaces_after_method_name: :dynamic - -def self.foo (x) -end - -#~# EXPECTED - -def self.foo (x) -end - From 7fdf8268d0d17b88d6fe7670246fd1bd058d3bb4 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 22:37:02 +0200 Subject: [PATCH 07/29] Change spaces_around_block_brace config to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../formatter_source_specs/blocks.rb.spec | 14 +++---- .../spaces_around_block_brace.rb.spec | 40 ------------------- 4 files changed, 8 insertions(+), 49 deletions(-) diff --git a/.rufo b/.rufo index 1c7bf55d..f9fbb1fe 100644 --- a/.rufo +++ b/.rufo @@ -5,7 +5,6 @@ spaces_around_equal :one spaces_in_ternary :one spaces_in_suffix :one spaces_in_commands :dynamic -spaces_around_block_brace :one spaces_around_hash_arrow :one spaces_around_when :one spaces_around_dot :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 1eaf1be1..1b6c4f9a 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -7,7 +7,7 @@ def init_settings(options) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_block_brace options.fetch(:spaces_around_block_brace, :dynamic) + spaces_around_block_brace options.fetch(:spaces_around_block_brace, :one) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/blocks.rb.spec b/spec/lib/rufo/formatter_source_specs/blocks.rb.spec index f9ce5df7..89fcb051 100644 --- a/spec/lib/rufo/formatter_source_specs/blocks.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/blocks.rb.spec @@ -4,7 +4,7 @@ foo {} #~# EXPECTED -foo {} +foo { } #~# ORIGINAL @@ -12,7 +12,7 @@ foo { } #~# EXPECTED -foo { } +foo { } #~# ORIGINAL @@ -20,7 +20,7 @@ foo { 1 } #~# EXPECTED -foo { 1 } +foo { 1 } #~# ORIGINAL @@ -28,7 +28,7 @@ foo { 1 ; 2 } #~# EXPECTED -foo { 1; 2 } +foo { 1; 2 } #~# ORIGINAL @@ -37,7 +37,7 @@ foo { 1 #~# EXPECTED -foo { +foo { 1 2 } @@ -62,7 +62,7 @@ begin #~# EXPECTED begin - foo { 1 } + foo { 1 } end #~# ORIGINAL @@ -87,7 +87,7 @@ foo { | x , y, | bar} #~# EXPECTED -foo { |x, y, | bar} +foo { |x, y, | bar } #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec index 538d90e8..87316a80 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_around_block_brace.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_around_block_brace: :one foo{1} @@ -8,7 +7,6 @@ foo{1} foo { 1 } #~# ORIGINAL -#~# spaces_around_block_brace: :one foo{|x|1} @@ -17,25 +15,6 @@ foo{|x|1} foo { |x| 1 } #~# ORIGINAL -#~# spaces_around_block_brace: :dynamic - -foo{1} - -#~# EXPECTED - -foo{1} - -#~# ORIGINAL -#~# spaces_around_block_brace: :dynamic - -foo{|x|1} - -#~# EXPECTED - -foo{|x|1} - -#~# ORIGINAL -#~# spaces_around_block_brace: :one foo { 1 } @@ -44,25 +23,6 @@ foo { 1 } foo { 1 } #~# ORIGINAL -#~# spaces_around_block_brace: :dynamic - -foo { 1 } - -#~# EXPECTED - -foo { 1 } - -#~# ORIGINAL -#~# spaces_around_block_brace: :dynamic - -->{1} - -#~# EXPECTED - --> {1} - -#~# ORIGINAL -#~# spaces_around_block_brace: :one ->{1} From 44d6becc6296810e094c6fab6d4e037b52827fe1 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 22:44:01 +0200 Subject: [PATCH 08/29] Remove spaces_around_block_brace config --- lib/rufo/formatter.rb | 14 +++++++------- lib/rufo/formatter/settings.rb | 5 ----- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index be40d4fb..01591bc0 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -1251,7 +1251,7 @@ def visit_call_with_block(node) visit call if block[0] == :brace_block - consume_one_dynamic_space @spaces_around_block_brace + consume_one_dynamic_space :one else consume_space end @@ -1273,7 +1273,7 @@ def visit_brace_block(node) if void_exps?(body) consume_token :on_lbrace consume_block_args args - consume_one_dynamic_space @spaces_around_block_brace + consume_one_dynamic_space :one consume_token :on_rbrace return end @@ -1284,14 +1284,14 @@ def visit_brace_block(node) if current_token_line == closing_brace_token[0][0] consume_token :on_lbrace consume_block_args args - consume_one_dynamic_space @spaces_around_block_brace + consume_one_dynamic_space :one visit_exps body, with_lines: false while semicolon? next_token end - consume_one_dynamic_space @spaces_around_block_brace + consume_one_dynamic_space :one consume_token :on_rbrace return @@ -1338,7 +1338,7 @@ def visit_do_block(node) def consume_block_args(args) if args - consume_one_dynamic_space_or_newline @spaces_around_block_brace + consume_one_dynamic_space_or_newline :one # + 1 because of |...| # ^ indent(@column + 1) do @@ -2478,9 +2478,9 @@ def visit_lambda(node) if current_token_line == closing_brace_token[0][0] consume_token :on_tlambeg - consume_space unless !space? && @spaces_around_block_brace == :dynamic + consume_space visit_exps body, with_lines: false - consume_space unless !space? && @spaces_around_block_brace == :dynamic + consume_space consume_token :on_rbrace return diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 1b6c4f9a..b9003128 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -7,7 +7,6 @@ def init_settings(options) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_block_brace options.fetch(:spaces_around_block_brace, :one) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) @@ -50,10 +49,6 @@ def spaces_in_commands(value) @spaces_in_commands = one_dynamic("spaces_in_commands", value) end - def spaces_around_block_brace(value) - @spaces_around_block_brace = one_dynamic("spaces_around_block_brace", value) - end - def spaces_around_hash_arrow(value) @spaces_around_hash_arrow = one_dynamic("spaces_around_hash_arrow", value) end From 5cd2152a66e9944300256df80163d0118b4b9205 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 22:52:23 +0200 Subject: [PATCH 09/29] Change spaces_around_dot config to :no --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../formatter_source_specs/2.3/lonely.rb.spec | 4 +-- .../2.3/lonely_operator.rb.spec | 4 +-- .../2.3/lonely_property_setters.rb.spec | 4 +-- .../align_chained_calls.rb.spec | 26 +++++++------- .../calls_with_receiver.rb.spec | 16 ++++----- .../global_variables.rb.spec | 6 ++-- .../property_setters.rb.spec | 34 +++++++++---------- .../spaces_around_dot.rb.spec | 20 ----------- 10 files changed, 48 insertions(+), 69 deletions(-) diff --git a/.rufo b/.rufo index f9fbb1fe..5d255dce 100644 --- a/.rufo +++ b/.rufo @@ -7,7 +7,6 @@ spaces_in_suffix :one spaces_in_commands :dynamic spaces_around_hash_arrow :one spaces_around_when :one -spaces_around_dot :no spaces_around_unary :no spaces_around_binary :one parens_in_def :yes diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index b9003128..df962e97 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -9,7 +9,7 @@ def init_settings(options) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) - spaces_around_dot options.fetch(:spaces_around_dot, :dynamic) + spaces_around_dot options.fetch(:spaces_around_dot, :no) spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/2.3/lonely.rb.spec b/spec/lib/rufo/formatter_source_specs/2.3/lonely.rb.spec index 44d763ec..f8407edb 100644 --- a/spec/lib/rufo/formatter_source_specs/2.3/lonely.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/2.3/lonely.rb.spec @@ -1,7 +1,7 @@ -#~# ORIGINAL +#~# ORIGINAL foo &. bar #~# EXPECTED -foo &. bar +foo&.bar diff --git a/spec/lib/rufo/formatter_source_specs/2.3/lonely_operator.rb.spec b/spec/lib/rufo/formatter_source_specs/2.3/lonely_operator.rb.spec index 42b48a43..e7c0f245 100644 --- a/spec/lib/rufo/formatter_source_specs/2.3/lonely_operator.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/2.3/lonely_operator.rb.spec @@ -1,7 +1,7 @@ -#~# ORIGINAL +#~# ORIGINAL foo&. bar #~# EXPECTED -foo&. bar +foo&.bar diff --git a/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec b/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec index 2cbd1a49..430c1bd5 100644 --- a/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec @@ -1,7 +1,7 @@ -#~# ORIGINAL +#~# ORIGINAL foo&. bar = 1 #~# EXPECTED -foo&. bar = 1 +foo&.bar = 1 diff --git a/spec/lib/rufo/formatter_source_specs/align_chained_calls.rb.spec b/spec/lib/rufo/formatter_source_specs/align_chained_calls.rb.spec index 84f9fb02..7b027761 100644 --- a/spec/lib/rufo/formatter_source_specs/align_chained_calls.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/align_chained_calls.rb.spec @@ -1,39 +1,39 @@ #~# ORIGINAL #~# align_chained_calls: true -foo . bar +foo . bar . baz #~# EXPECTED -foo . bar - . baz +foo.bar + .baz #~# ORIGINAL #~# align_chained_calls: true -foo . bar - . baz +foo . bar + . baz . qux #~# EXPECTED -foo . bar - . baz - . qux +foo.bar + .baz + .qux #~# ORIGINAL #~# align_chained_calls: true -foo . bar( x.y ) - . baz +foo . bar( x.y ) + . baz . qux #~# EXPECTED -foo . bar(x.y) - . baz - . qux +foo.bar(x.y) + .baz + .qux #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec b/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec index 9b36dfe7..ced593d5 100644 --- a/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec @@ -4,7 +4,7 @@ foo . bar . baz #~# EXPECTED -foo . bar . baz +foo.bar.baz #~# ORIGINAL @@ -12,7 +12,7 @@ foo . bar( 1 , 2 ) #~# EXPECTED -foo . bar(1, 2) +foo.bar(1, 2) #~# ORIGINAL @@ -21,7 +21,7 @@ foo . #~# EXPECTED -foo . +foo. bar #~# ORIGINAL @@ -32,8 +32,8 @@ foo . #~# EXPECTED -foo . - bar . +foo. + bar. baz #~# ORIGINAL @@ -44,7 +44,7 @@ foo #~# EXPECTED foo - . bar + .bar #~# ORIGINAL @@ -55,8 +55,8 @@ foo #~# EXPECTED foo - . bar - . baz + .bar + .baz #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/global_variables.rb.spec b/spec/lib/rufo/formatter_source_specs/global_variables.rb.spec index 07a9e265..145ef693 100644 --- a/spec/lib/rufo/formatter_source_specs/global_variables.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/global_variables.rb.spec @@ -1,4 +1,4 @@ -#~# ORIGINAL +#~# ORIGINAL $abc @@ -6,10 +6,10 @@ $abc $abc -#~# ORIGINAL +#~# ORIGINAL $abc . d #~# EXPECTED -$abc . d +$abc.d diff --git a/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec b/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec index cc08a5e6..13d80fab 100644 --- a/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec @@ -1,55 +1,55 @@ -#~# ORIGINAL +#~# ORIGINAL foo . bar = 1 #~# EXPECTED -foo . bar = 1 +foo.bar = 1 -#~# ORIGINAL +#~# ORIGINAL -foo . bar = +foo . bar = 1 #~# EXPECTED -foo . bar = +foo.bar = 1 -#~# ORIGINAL +#~# ORIGINAL -foo . - bar = +foo . + bar = 1 #~# EXPECTED -foo . +foo. bar = 1 -#~# ORIGINAL +#~# ORIGINAL foo:: bar = 1 #~# EXPECTED -foo:: bar = 1 +foo::bar = 1 -#~# ORIGINAL +#~# ORIGINAL -foo:: bar = +foo:: bar = 1 #~# EXPECTED -foo:: bar = +foo::bar = 1 -#~# ORIGINAL +#~# ORIGINAL -foo:: - bar = +foo:: + bar = 1 #~# EXPECTED diff --git a/spec/lib/rufo/formatter_source_specs/spaces_around_dot.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_around_dot.rb.spec index fb47ef37..916da15d 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_around_dot.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_around_dot.rb.spec @@ -1,23 +1,4 @@ #~# ORIGINAL -#~# spaces_around_dot: :dynamic - -foo . bar - -#~# EXPECTED - -foo . bar - -#~# ORIGINAL -#~# spaces_around_dot: :dynamic - -foo . bar = 1 - -#~# EXPECTED - -foo . bar = 1 - -#~# ORIGINAL -#~# spaces_around_dot: :no foo . bar @@ -26,7 +7,6 @@ foo . bar foo.bar #~# ORIGINAL -#~# spaces_around_dot: :no foo . bar = 1 From 3e6d94ffd66db4c5c1995730fa1280b8b7d5552b Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 22:55:07 +0200 Subject: [PATCH 10/29] Remove spaces_around_dot config --- lib/rufo/formatter.rb | 8 ++++---- lib/rufo/formatter/settings.rb | 5 ----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 01591bc0..08745ad7 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -924,7 +924,7 @@ def visit_call_with_receiver(node) write_indent(next_indent) end else - write_space_using_setting(first_space, @spaces_around_dot) + write_space_using_setting(first_space, :no) end # Remember dot column, but only if there isn't one already set @@ -935,7 +935,7 @@ def visit_call_with_receiver(node) consume_call_dot - skip_space_or_newline_using_setting(@spaces_around_dot, next_indent) + skip_space_or_newline_using_setting(:no, next_indent) if name == :call # :call means it's .() @@ -2386,7 +2386,7 @@ def visit_setter(node) visit receiver - skip_space_or_newline_using_setting(@spaces_around_dot, @dot_column || next_indent) + skip_space_or_newline_using_setting(:no, @dot_column || next_indent) # Remember dot column dot_column = @column @@ -2394,7 +2394,7 @@ def visit_setter(node) consume_call_dot - skip_space_or_newline_using_setting(@spaces_around_dot, next_indent) + skip_space_or_newline_using_setting(:no, next_indent) visit name diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index df962e97..6e685909 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -9,7 +9,6 @@ def init_settings(options) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) - spaces_around_dot options.fetch(:spaces_around_dot, :no) spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) @@ -57,10 +56,6 @@ def spaces_around_when(value) @spaces_around_when = one_dynamic("spaces_around_when", value) end - def spaces_around_dot(value) - @spaces_around_dot = no_dynamic("spaces_around_dot", value) - end - def spaces_around_unary(value) @spaces_around_unary = no_dynamic("spaces_around_unary", value) end From 16ededb9c6dffadba76a1f4961eafd301c3f1c58 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:04:59 +0200 Subject: [PATCH 11/29] Change spaces_around_equal config to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../2.3/lonely_property_setters.rb.spec | 2 +- .../align_hash_keys.rb.spec | 4 +- .../array_setter.rb.spec | 8 +- .../assignment_operators.rb.spec | 10 +- .../assignments.rb.spec | 50 +++---- .../method_definition.rb.spec | 130 +++++++++--------- .../multiple_assignments.rb.spec | 8 +- .../property_setters.rb.spec | 12 +- .../spaces_around_equal.rb.spec | 49 ------- 11 files changed, 113 insertions(+), 163 deletions(-) diff --git a/.rufo b/.rufo index 5d255dce..42df0e19 100644 --- a/.rufo +++ b/.rufo @@ -1,7 +1,6 @@ indent_size 2 spaces_inside_hash_brace :never spaces_inside_array_bracket :never -spaces_around_equal :one spaces_in_ternary :one spaces_in_suffix :one spaces_in_commands :dynamic diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 6e685909..9762b8ec 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -3,7 +3,7 @@ def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) - spaces_around_equal options.fetch(:spaces_around_equal, :dynamic) + spaces_around_equal options.fetch(:spaces_around_equal, :one) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec b/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec index 430c1bd5..1dd00d42 100644 --- a/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/2.3/lonely_property_setters.rb.spec @@ -4,4 +4,4 @@ foo&. bar = 1 #~# EXPECTED -foo&.bar = 1 +foo&.bar = 1 diff --git a/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec b/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec index 06914980..f6ee931f 100644 --- a/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec @@ -164,8 +164,8 @@ a = b :foo => x, #~# EXPECTED -a = b :foo => x, - :baar => x +a = b :foo => x, + :baar => x #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec b/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec index 13f39cf2..65207f38 100644 --- a/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec @@ -1,15 +1,15 @@ -#~# ORIGINAL +#~# ORIGINAL foo[ ] = 1 #~# EXPECTED -foo[ ] = 1 +foo[ ] = 1 -#~# ORIGINAL +#~# ORIGINAL foo[ 1 , 2 ] = 3 #~# EXPECTED -foo[ 1, 2 ] = 3 +foo[ 1, 2 ] = 3 diff --git a/spec/lib/rufo/formatter_source_specs/assignment_operators.rb.spec b/spec/lib/rufo/formatter_source_specs/assignment_operators.rb.spec index 56c0064f..7ded6b07 100644 --- a/spec/lib/rufo/formatter_source_specs/assignment_operators.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/assignment_operators.rb.spec @@ -1,4 +1,4 @@ -#~# ORIGINAL +#~# ORIGINAL a += 2 @@ -6,9 +6,9 @@ a += 2 a += 2 -#~# ORIGINAL +#~# ORIGINAL -a += +a += 2 #~# EXPECTED @@ -16,10 +16,10 @@ a += a += 2 -#~# ORIGINAL +#~# ORIGINAL a+=1 #~# EXPECTED -a+=1 +a += 1 diff --git a/spec/lib/rufo/formatter_source_specs/assignments.rb.spec b/spec/lib/rufo/formatter_source_specs/assignments.rb.spec index f0755cd7..e4381b3d 100644 --- a/spec/lib/rufo/formatter_source_specs/assignments.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/assignments.rb.spec @@ -1,35 +1,35 @@ -#~# ORIGINAL +#~# ORIGINAL a = 1 #~# EXPECTED -a = 1 +a = 1 -#~# ORIGINAL +#~# ORIGINAL -a = +a = 2 #~# EXPECTED -a = +a = 2 -#~# ORIGINAL +#~# ORIGINAL -a = # hello +a = # hello 2 #~# EXPECTED -a = # hello +a = # hello 2 -#~# ORIGINAL +#~# ORIGINAL -a = if 1 - 2 +a = if 1 + 2 end #~# EXPECTED @@ -38,10 +38,10 @@ a = if 1 2 end -#~# ORIGINAL +#~# ORIGINAL -a = unless 1 - 2 +a = unless 1 + 2 end #~# EXPECTED @@ -50,10 +50,10 @@ a = unless 1 2 end -#~# ORIGINAL +#~# ORIGINAL a = begin -1 +1 end #~# EXPECTED @@ -62,11 +62,11 @@ a = begin 1 end -#~# ORIGINAL +#~# ORIGINAL a = case - when 1 - 2 + when 1 + 2 end #~# EXPECTED @@ -76,7 +76,7 @@ a = case 2 end -#~# ORIGINAL +#~# ORIGINAL a = begin 1 @@ -88,7 +88,7 @@ a = begin 1 end -#~# ORIGINAL +#~# ORIGINAL a = begin 1 @@ -104,7 +104,7 @@ a = begin 2 end -#~# ORIGINAL +#~# ORIGINAL a = begin 1 @@ -120,15 +120,15 @@ a = begin 2 end -#~# ORIGINAL +#~# ORIGINAL a=1 #~# EXPECTED -a=1 +a = 1 -#~# ORIGINAL +#~# ORIGINAL a = \ begin diff --git a/spec/lib/rufo/formatter_source_specs/method_definition.rb.spec b/spec/lib/rufo/formatter_source_specs/method_definition.rb.spec index a3a91217..34d11227 100644 --- a/spec/lib/rufo/formatter_source_specs/method_definition.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/method_definition.rb.spec @@ -1,6 +1,6 @@ -#~# ORIGINAL +#~# ORIGINAL - def foo + def foo end #~# EXPECTED @@ -8,7 +8,7 @@ def foo end -#~# ORIGINAL +#~# ORIGINAL def foo ; end @@ -16,9 +16,9 @@ end def foo; end -#~# ORIGINAL +#~# ORIGINAL - def foo() + def foo() end #~# EXPECTED @@ -26,7 +26,7 @@ def foo; end def foo() end -#~# ORIGINAL +#~# ORIGINAL def foo() 1 end @@ -34,10 +34,10 @@ end def foo() 1 end -#~# ORIGINAL +#~# ORIGINAL - def foo( - ) + def foo( + ) end #~# EXPECTED @@ -45,9 +45,9 @@ def foo() 1 end def foo() end -#~# ORIGINAL +#~# ORIGINAL - def foo( x ) + def foo( x ) end #~# EXPECTED @@ -55,9 +55,9 @@ end def foo(x) end -#~# ORIGINAL +#~# ORIGINAL - def foo( x , y ) + def foo( x , y ) end #~# EXPECTED @@ -65,9 +65,9 @@ end def foo(x, y) end -#~# ORIGINAL +#~# ORIGINAL - def foo x + def foo x end #~# EXPECTED @@ -75,9 +75,9 @@ end def foo x end -#~# ORIGINAL +#~# ORIGINAL - def foo x , y + def foo x , y end #~# EXPECTED @@ -85,10 +85,10 @@ end def foo x, y end -#~# ORIGINAL +#~# ORIGINAL - def foo - 1 + def foo + 1 end #~# EXPECTED @@ -97,10 +97,10 @@ def foo 1 end -#~# ORIGINAL +#~# ORIGINAL - def foo( * x ) - 1 + def foo( * x ) + 1 end #~# EXPECTED @@ -109,10 +109,10 @@ def foo(*x) 1 end -#~# ORIGINAL +#~# ORIGINAL - def foo( a , * x ) - 1 + def foo( a , * x ) + 1 end #~# EXPECTED @@ -121,10 +121,10 @@ def foo(a, *x) 1 end -#~# ORIGINAL +#~# ORIGINAL - def foo( a , * x, b ) - 1 + def foo( a , * x, b ) + 1 end #~# EXPECTED @@ -133,29 +133,29 @@ def foo(a, *x, b) 1 end -#~# ORIGINAL +#~# ORIGINAL - def foo( x = 1 ) + def foo( x = 1 ) end #~# EXPECTED -def foo(x = 1) +def foo(x = 1) end -#~# ORIGINAL +#~# ORIGINAL - def foo( x = 1, * y ) + def foo( x = 1, * y ) end #~# EXPECTED -def foo(x = 1, *y) +def foo(x = 1, *y) end -#~# ORIGINAL +#~# ORIGINAL - def foo( & block ) + def foo( & block ) end #~# EXPECTED @@ -163,9 +163,9 @@ end def foo(&block) end -#~# ORIGINAL +#~# ORIGINAL - def foo( a: , b: ) + def foo( a: , b: ) end #~# EXPECTED @@ -173,9 +173,9 @@ end def foo(a:, b:) end -#~# ORIGINAL +#~# ORIGINAL - def foo( a: 1 , b: 2 ) + def foo( a: 1 , b: 2 ) end #~# EXPECTED @@ -183,10 +183,10 @@ end def foo(a: 1, b: 2) end -#~# ORIGINAL +#~# ORIGINAL - def foo( x, - y ) + def foo( x, + y ) end #~# EXPECTED @@ -195,10 +195,10 @@ def foo(x, y) end -#~# ORIGINAL +#~# ORIGINAL - def foo( a: 1, - b: 2 ) + def foo( a: 1, + b: 2 ) end #~# EXPECTED @@ -207,11 +207,11 @@ def foo(a: 1, b: 2) end -#~# ORIGINAL +#~# ORIGINAL def foo( - x, - y ) + x, + y ) end #~# EXPECTED @@ -221,9 +221,9 @@ def foo( y) end -#~# ORIGINAL +#~# ORIGINAL - def foo( a: 1, &block ) + def foo( a: 1, &block ) end #~# EXPECTED @@ -231,10 +231,10 @@ end def foo(a: 1, &block) end -#~# ORIGINAL +#~# ORIGINAL - def foo( a: 1, - &block ) + def foo( a: 1, + &block ) end #~# EXPECTED @@ -243,9 +243,9 @@ def foo(a: 1, &block) end -#~# ORIGINAL +#~# ORIGINAL - def foo(*) + def foo(*) end #~# EXPECTED @@ -253,9 +253,9 @@ end def foo(*) end -#~# ORIGINAL +#~# ORIGINAL - def foo(**) + def foo(**) end #~# EXPECTED @@ -263,7 +263,7 @@ end def foo(**) end -#~# ORIGINAL +#~# ORIGINAL def `(cmd) end @@ -273,7 +273,7 @@ end def `(cmd) end -#~# ORIGINAL +#~# ORIGINAL module_function def foo 1 @@ -285,7 +285,7 @@ module_function def foo 1 end -#~# ORIGINAL +#~# ORIGINAL private def foo 1 @@ -297,7 +297,7 @@ private def foo 1 end -#~# ORIGINAL +#~# ORIGINAL some class Foo 1 @@ -309,7 +309,7 @@ some class Foo 1 end -#~# ORIGINAL +#~# ORIGINAL def foo; 1; end def bar; 2; end @@ -319,7 +319,7 @@ def bar; 2; end def foo; 1; end def bar; 2; end -#~# ORIGINAL +#~# ORIGINAL def foo; 1; end diff --git a/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec b/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec index 147dfb25..2f06af51 100644 --- a/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/multiple_assignments.rb.spec @@ -4,7 +4,7 @@ a = 1 , 2 #~# EXPECTED -a = 1, 2 +a = 1, 2 #~# ORIGINAL @@ -12,7 +12,7 @@ a , b = 2 #~# EXPECTED -a, b = 2 +a, b = 2 #~# ORIGINAL @@ -20,7 +20,7 @@ a , b, ( c, d ) = 2 #~# EXPECTED -a, b, (c, d) = 2 +a, b, (c, d) = 2 #~# ORIGINAL @@ -124,7 +124,7 @@ a, b=1, 2 #~# EXPECTED -a, b=1, 2 +a, b = 1, 2 #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec b/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec index 13d80fab..dcd9560b 100644 --- a/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/property_setters.rb.spec @@ -4,7 +4,7 @@ foo . bar = 1 #~# EXPECTED -foo.bar = 1 +foo.bar = 1 #~# ORIGINAL @@ -13,7 +13,7 @@ foo . bar = #~# EXPECTED -foo.bar = +foo.bar = 1 #~# ORIGINAL @@ -25,7 +25,7 @@ foo . #~# EXPECTED foo. - bar = + bar = 1 #~# ORIGINAL @@ -34,7 +34,7 @@ foo:: bar = 1 #~# EXPECTED -foo::bar = 1 +foo::bar = 1 #~# ORIGINAL @@ -43,7 +43,7 @@ foo:: bar = #~# EXPECTED -foo::bar = +foo::bar = 1 #~# ORIGINAL @@ -55,5 +55,5 @@ foo:: #~# EXPECTED foo:: - bar = + bar = 1 diff --git a/spec/lib/rufo/formatter_source_specs/spaces_around_equal.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_around_equal.rb.spec index 61421e95..9a4cd5ad 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_around_equal.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_around_equal.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_around_equal: :one a=1 @@ -8,7 +7,6 @@ a=1 a = 1 #~# ORIGINAL -#~# spaces_around_equal: :one a = 1 @@ -17,16 +15,6 @@ a = 1 a = 1 #~# ORIGINAL -#~# spaces_around_equal: :dynamic - -a = 1 - -#~# EXPECTED - -a = 1 - -#~# ORIGINAL -#~# spaces_around_equal: :one a = 1 @@ -35,7 +23,6 @@ a = 1 a = 1 #~# ORIGINAL -#~# spaces_around_equal: :one a+=1 @@ -44,7 +31,6 @@ a+=1 a += 1 #~# ORIGINAL -#~# spaces_around_equal: :one a += 1 @@ -53,16 +39,6 @@ a += 1 a += 1 #~# ORIGINAL -#~# spaces_around_equal: :dynamic - -a += 1 - -#~# EXPECTED - -a += 1 - -#~# ORIGINAL -#~# spaces_around_equal: :one a += 1 @@ -71,7 +47,6 @@ a += 1 a += 1 #~# ORIGINAL -#~# spaces_around_equal: :one def foo(x = 1) end @@ -82,7 +57,6 @@ def foo(x = 1) end #~# ORIGINAL -#~# spaces_around_equal: :one def foo(x=1) end @@ -91,26 +65,3 @@ end def foo(x = 1) end - -#~# ORIGINAL -#~# spaces_around_equal: :dynamic - -def foo(x = 1) -end - -#~# EXPECTED - -def foo(x = 1) -end - -#~# ORIGINAL -#~# spaces_around_equal: :dynamic - -def foo(x=1) -end - -#~# EXPECTED - -def foo(x=1) -end - From ba5389bb2e9cf54294ab6c7dac6b3684f8431e00 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:07:51 +0200 Subject: [PATCH 12/29] Remove spaces_around_equal config --- lib/rufo/formatter.rb | 15 +++++++-------- lib/rufo/formatter/settings.rb | 5 ----- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 08745ad7..a0e2b83a 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -722,7 +722,7 @@ def visit_assign(node) line = @line visit target - consume_one_dynamic_space @spaces_around_equal + consume_one_dynamic_space :one track_assignment consume_op "=" @@ -740,7 +740,7 @@ def visit_op_assign(node) line = @line visit target - consume_one_dynamic_space @spaces_around_equal + consume_one_dynamic_space :one # [:@op, "+=", [1, 2]], check :on_op @@ -772,7 +772,7 @@ def visit_multiple_assign(node) first_space = skip_space end - write_space_using_setting(first_space, @spaces_around_equal) + write_space_using_setting(first_space, :one) track_assignment consume_op "=" @@ -795,11 +795,10 @@ def visit_assign_value(value) visit(value) end else - want_space = first_space || @spaces_around_equal == :one indent_after_space value, sticky: sticky, - want_space: want_space, + want_space: true, first_space: first_space, - preserve_whitespace: @spaces_around_equal == :dynamic + preserve_whitespace: false end end @@ -2028,9 +2027,9 @@ def visit_params(node) write_params_comma if needs_comma visit_comma_separated_list(args_with_default) do |arg, default| visit arg - consume_one_dynamic_space @spaces_around_equal + consume_one_dynamic_space :one consume_op "=" - consume_one_dynamic_space @spaces_around_equal + consume_one_dynamic_space :one visit default end needs_comma = true diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 9762b8ec..bc02d543 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -3,7 +3,6 @@ def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) - spaces_around_equal options.fetch(:spaces_around_equal, :one) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) @@ -32,10 +31,6 @@ def spaces_inside_array_bracket(value) @spaces_inside_array_bracket = dynamic_always_never_match("spaces_inside_array_bracket", value) end - def spaces_around_equal(value) - @spaces_around_equal = one_dynamic("spaces_around_equal", value) - end - def spaces_in_ternary(value) @spaces_in_ternary = one_dynamic("spaces_in_ternary", value) end From 1a14d32a17e0b45cf934b69c5d0f8ed313c2696c Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:17:08 +0200 Subject: [PATCH 13/29] Change config spaces_around_hash_arrow to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../align_hash_keys.rb.spec | 18 ++++++------- .../hash_literal.rb.spec | 26 +++++++++---------- .../method_calls.rb.spec | 6 ++--- .../spaces_after_comma.rb.spec | 2 +- 6 files changed, 27 insertions(+), 28 deletions(-) diff --git a/.rufo b/.rufo index 42df0e19..012ca226 100644 --- a/.rufo +++ b/.rufo @@ -4,7 +4,6 @@ spaces_inside_array_bracket :never spaces_in_ternary :one spaces_in_suffix :one spaces_in_commands :dynamic -spaces_around_hash_arrow :one spaces_around_when :one spaces_around_unary :no spaces_around_binary :one diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index bc02d543..d411cc9c 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -6,7 +6,7 @@ def init_settings(options) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :dynamic) + spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :one) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec b/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec index f6ee931f..c7ca6c6c 100644 --- a/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/align_hash_keys.rb.spec @@ -173,7 +173,7 @@ a = b :foo => x, #~# EXPECTED -{:foo => 1 } +{:foo => 1 } #~# ORIGINAL @@ -181,7 +181,7 @@ a = b :foo => x, #~# EXPECTED -{:foo => 1} +{:foo => 1} #~# ORIGINAL @@ -189,7 +189,7 @@ a = b :foo => x, #~# EXPECTED -{ :foo => 1 } +{ :foo => 1 } #~# ORIGINAL @@ -197,7 +197,7 @@ a = b :foo => x, #~# EXPECTED -{ :foo => 1, 2 => 3 } +{ :foo => 1, 2 => 3 } #~# ORIGINAL @@ -208,8 +208,8 @@ a = b :foo => x, #~# EXPECTED { - :foo => 1, - 2 => 3 + :foo => 1, + 2 => 3 } #~# ORIGINAL @@ -219,8 +219,8 @@ a = b :foo => x, #~# EXPECTED -{ foo: 1, - bar: 2 } +{ foo: 1, + bar: 2 } #~# ORIGINAL @@ -246,7 +246,7 @@ foo 1, :bar => 2 , :baz => 3 #~# EXPECTED -foo 1, :bar => 2, :baz => 3 +foo 1, :bar => 2, :baz => 3 #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec b/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec index 01359227..fdc9b6f6 100644 --- a/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/hash_literal.rb.spec @@ -12,7 +12,7 @@ #~# EXPECTED -{:foo => 1 } +{:foo => 1 } #~# ORIGINAL @@ -20,7 +20,7 @@ #~# EXPECTED -{:foo => 1} +{:foo => 1} #~# ORIGINAL @@ -28,7 +28,7 @@ #~# EXPECTED -{ :foo => 1 } +{ :foo => 1 } #~# ORIGINAL @@ -36,7 +36,7 @@ #~# EXPECTED -{ :foo => 1, 2 => 3 } +{ :foo => 1, 2 => 3 } #~# ORIGINAL @@ -47,8 +47,8 @@ #~# EXPECTED { - :foo => 1, - 2 => 3 + :foo => 1, + 2 => 3 } #~# ORIGINAL @@ -65,7 +65,7 @@ #~# EXPECTED -{foo: 1} +{foo: 1} #~# ORIGINAL @@ -73,7 +73,7 @@ #~# EXPECTED -{ foo: 1 } +{ foo: 1 } #~# ORIGINAL @@ -82,7 +82,7 @@ #~# EXPECTED -{ :foo => 1 } +{ :foo => 1 } #~# ORIGINAL @@ -106,7 +106,7 @@ #~# EXPECTED -{ :"one two" => 3 } +{ :"one two" => 3 } #~# ORIGINAL @@ -115,8 +115,8 @@ #~# EXPECTED -{ foo: 1, - bar: 2 } +{ foo: 1, + bar: 2 } #~# ORIGINAL @@ -133,4 +133,4 @@ #~# EXPECTED -{1 => 2} +{1 => 2} diff --git a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec index 94ec81da..0cd1a09f 100644 --- a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec @@ -162,7 +162,7 @@ foo 1, bar: 2 , baz: 3 #~# EXPECTED -foo 1, bar: 2, baz: 3 +foo 1, bar: 2, baz: 3 #~# ORIGINAL @@ -172,7 +172,7 @@ foo 1, #~# EXPECTED foo 1, - bar: 2, baz: 3 + bar: 2, baz: 3 #~# ORIGINAL @@ -547,7 +547,7 @@ foo x: 1 #~# EXPECTED -foo x: 1 +foo x: 1 #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec index f3951ee3..9a77c129 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_after_comma.rb.spec @@ -20,7 +20,7 @@ foo(1,2,3,x:1,y:2) #~# EXPECTED -foo(1, 2, 3, x:1, y:2) +foo(1, 2, 3, x: 1, y: 2) #~# ORIGINAL From 2965748983425359e1e0bf61d9d2560d841f5c2d Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:19:44 +0200 Subject: [PATCH 14/29] Remove spaces_around_hash_arrow config --- lib/rufo/formatter.rb | 4 +- lib/rufo/formatter/settings.rb | 5 --- .../spaces_around_hash_arrow.rb.spec | 41 ------------------- 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index a0e2b83a..26d4abbd 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -2243,7 +2243,7 @@ def visit_hash_key_value(node) arrow = symbol || !(key[0] == :@label || key[0] == :dyna_symbol) visit key - consume_one_dynamic_space @spaces_around_hash_arrow + consume_one_dynamic_space :one track_hash_key @@ -2251,7 +2251,7 @@ def visit_hash_key_value(node) # or `"label": value` if arrow consume_op "=>" - consume_one_dynamic_space @spaces_around_hash_arrow + consume_one_dynamic_space :one end visit value diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index d411cc9c..2c08ac0c 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -6,7 +6,6 @@ def init_settings(options) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_hash_arrow options.fetch(:spaces_around_hash_arrow, :one) spaces_around_when options.fetch(:spaces_around_when, :dynamic) spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) @@ -43,10 +42,6 @@ def spaces_in_commands(value) @spaces_in_commands = one_dynamic("spaces_in_commands", value) end - def spaces_around_hash_arrow(value) - @spaces_around_hash_arrow = one_dynamic("spaces_around_hash_arrow", value) - end - def spaces_around_when(value) @spaces_around_when = one_dynamic("spaces_around_when", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_around_hash_arrow.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_around_hash_arrow.rb.spec index 2584b654..a32a2b4a 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_around_hash_arrow.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_around_hash_arrow.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_around_hash_arrow: :one {1 => 2} @@ -8,16 +7,6 @@ {1 => 2} #~# ORIGINAL -#~# spaces_around_hash_arrow: :dynamic - -{1 => 2} - -#~# EXPECTED - -{1 => 2} - -#~# ORIGINAL -#~# spaces_around_hash_arrow: :one {1=>2} @@ -26,16 +15,6 @@ {1 => 2} #~# ORIGINAL -#~# spaces_around_hash_arrow: :dynamic - -{1=>2} - -#~# EXPECTED - -{1=>2} - -#~# ORIGINAL -#~# spaces_around_hash_arrow: :one {foo: 2} @@ -44,29 +23,9 @@ {foo: 2} #~# ORIGINAL -#~# spaces_around_hash_arrow: :dynamic - -{foo: 2} - -#~# EXPECTED - -{foo: 2} - -#~# ORIGINAL -#~# spaces_around_hash_arrow: :one {foo:2} #~# EXPECTED {foo: 2} - -#~# ORIGINAL -#~# spaces_around_hash_arrow: :dynamic - -{foo:2} - -#~# EXPECTED - -{foo:2} - From 25b267b8b01b49276b1a78a98676ea7dd2c21c26 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:25:29 +0200 Subject: [PATCH 15/29] Change spaces_around_unary config to :no --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../unary_operators.rb.spec | 16 ++++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.rufo b/.rufo index 012ca226..a6462c5b 100644 --- a/.rufo +++ b/.rufo @@ -5,7 +5,6 @@ spaces_in_ternary :one spaces_in_suffix :one spaces_in_commands :dynamic spaces_around_when :one -spaces_around_unary :no spaces_around_binary :one parens_in_def :yes double_newline_inside_type :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 2c08ac0c..4f4c7f0a 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -7,7 +7,7 @@ def init_settings(options) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) - spaces_around_unary options.fetch(:spaces_around_unary, :dynamic) + spaces_around_unary options.fetch(:spaces_around_unary, :no) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/unary_operators.rb.spec b/spec/lib/rufo/formatter_source_specs/unary_operators.rb.spec index 6bcfefd1..1ae1bb65 100644 --- a/spec/lib/rufo/formatter_source_specs/unary_operators.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/unary_operators.rb.spec @@ -1,20 +1,20 @@ -#~# ORIGINAL +#~# ORIGINAL - x #~# EXPECTED -- x +-x -#~# ORIGINAL +#~# ORIGINAL + x #~# EXPECTED -+ x ++x -#~# ORIGINAL +#~# ORIGINAL +x @@ -22,7 +22,7 @@ +x -#~# ORIGINAL +#~# ORIGINAL +(x) @@ -30,10 +30,10 @@ +(x) -#~# ORIGINAL +#~# ORIGINAL + (x) #~# EXPECTED -+ (x) ++(x) From d08be892d3e83b112c4f84415f119118c9b9dc39 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:29:39 +0200 Subject: [PATCH 16/29] Remove spaces_around_unary config --- lib/rufo/formatter.rb | 2 +- lib/rufo/formatter/settings.rb | 5 ----- .../formatter_source_specs/spaces_around_unary.rb.spec | 10 ---------- 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 26d4abbd..bc42c100 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -1751,7 +1751,7 @@ def visit_unary(node) consume_op_or_keyword op - setting = op == :not ? @spaces_in_commands : @spaces_around_unary + setting = op == :not ? @spaces_in_commands : :no first_space = space? consume_space = first_space && setting == :dynamic diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 4f4c7f0a..2afb93b0 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -7,7 +7,6 @@ def init_settings(options) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) spaces_around_when options.fetch(:spaces_around_when, :dynamic) - spaces_around_unary options.fetch(:spaces_around_unary, :no) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) @@ -46,10 +45,6 @@ def spaces_around_when(value) @spaces_around_when = one_dynamic("spaces_around_when", value) end - def spaces_around_unary(value) - @spaces_around_unary = no_dynamic("spaces_around_unary", value) - end - def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_around_unary.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_around_unary.rb.spec index 5d113ef6..0dcc405c 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_around_unary.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_around_unary.rb.spec @@ -1,14 +1,4 @@ #~# ORIGINAL -#~# spaces_around_unary: :dynamic - -- x - -#~# EXPECTED - -- x - -#~# ORIGINAL -#~# spaces_around_unary: :no - x From 08867b5ac8f2fd65c5e77b7f32904be120a4a58d Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:31:46 +0200 Subject: [PATCH 17/29] Change spaces_around_when config to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../rufo/formatter_source_specs/case.rb.spec | 202 +++++++++--------- 3 files changed, 102 insertions(+), 103 deletions(-) diff --git a/.rufo b/.rufo index a6462c5b..cc47b1bc 100644 --- a/.rufo +++ b/.rufo @@ -4,7 +4,6 @@ spaces_inside_array_bracket :never spaces_in_ternary :one spaces_in_suffix :one spaces_in_commands :dynamic -spaces_around_when :one spaces_around_binary :one parens_in_def :yes double_newline_inside_type :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 2afb93b0..a24dd566 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -6,7 +6,7 @@ def init_settings(options) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_when options.fetch(:spaces_around_when, :dynamic) + spaces_around_when options.fetch(:spaces_around_when, :one) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/case.rb.spec b/spec/lib/rufo/formatter_source_specs/case.rb.spec index fd1be49d..b57d73b0 100644 --- a/spec/lib/rufo/formatter_source_specs/case.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/case.rb.spec @@ -1,7 +1,7 @@ -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then 2 +case + when 1 then 2 end #~# EXPECTED @@ -10,11 +10,11 @@ case when 1 then 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then 2 - when 3 then 4 +case + when 1 then 2 + when 3 then 4 end #~# EXPECTED @@ -24,10 +24,10 @@ when 1 then 2 when 3 then 4 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then 2 else 3 +case + when 1 then 2 else 3 end #~# EXPECTED @@ -37,10 +37,10 @@ when 1 then 2 else 3 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 ; 2 +case + when 1 ; 2 end #~# EXPECTED @@ -49,11 +49,11 @@ case when 1; 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 - 2 +case + when 1 + 2 end #~# EXPECTED @@ -63,12 +63,12 @@ when 1 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 - 2 - 3 +case + when 1 + 2 + 3 end #~# EXPECTED @@ -79,14 +79,14 @@ when 1 3 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 - 2 - 3 - when 4 - 5 +case + when 1 + 2 + 3 + when 4 + 5 end #~# EXPECTED @@ -99,11 +99,11 @@ when 4 5 end -#~# ORIGINAL +#~# ORIGINAL -case 123 - when 1 - 2 +case 123 + when 1 + 2 end #~# EXPECTED @@ -113,11 +113,11 @@ when 1 2 end -#~# ORIGINAL +#~# ORIGINAL -case # foo - when 1 - 2 +case # foo + when 1 + 2 end #~# EXPECTED @@ -127,11 +127,11 @@ when 1 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 # comment - 2 +case + when 1 # comment + 2 end #~# EXPECTED @@ -141,11 +141,11 @@ when 1 # comment 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then 2 else - 3 +case + when 1 then 2 else + 3 end #~# EXPECTED @@ -156,11 +156,11 @@ else 3 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then 2 else ; - 3 +case + when 1 then 2 else ; + 3 end #~# EXPECTED @@ -171,11 +171,11 @@ else 3 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then 2 else # comm - 3 +case + when 1 then 2 else # comm + 3 end #~# EXPECTED @@ -186,17 +186,17 @@ else # comm 3 end -#~# ORIGINAL - -begin - case - when 1 - 2 - when 3 - 4 - else - 5 - end +#~# ORIGINAL + +begin + case + when 1 + 2 + when 3 + 4 + else + 5 + end end #~# EXPECTED @@ -212,11 +212,11 @@ begin end end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then - 2 +case + when 1 then + 2 end #~# EXPECTED @@ -226,11 +226,11 @@ when 1 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 then ; - 2 +case + when 1 then ; + 2 end #~# EXPECTED @@ -240,11 +240,11 @@ when 1 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 ; - 2 +case + when 1 ; + 2 end #~# EXPECTED @@ -254,12 +254,12 @@ when 1 2 end -#~# ORIGINAL +#~# ORIGINAL -case - when 1 , - 2 ; - 3 +case + when 1 , + 2 ; + 3 end #~# EXPECTED @@ -270,12 +270,12 @@ when 1, 3 end -#~# ORIGINAL +#~# ORIGINAL -case +case when 1 , 2, # comm - - 3 + + 3 end #~# EXPECTED @@ -285,14 +285,14 @@ when 1, 2, # comm 3 end -#~# ORIGINAL +#~# ORIGINAL -begin - case - when :x - # comment - 2 - end +begin + case + when :x + # comment + 2 + end end #~# EXPECTED @@ -305,11 +305,11 @@ begin end end -#~# ORIGINAL +#~# ORIGINAL case 1 - when *x , *y - 2 + when *x , *y + 2 end #~# EXPECTED @@ -319,7 +319,7 @@ when *x, *y 2 end -#~# ORIGINAL +#~# ORIGINAL case 1 when *x then 2 @@ -331,7 +331,7 @@ case 1 when *x then 2 end -#~# ORIGINAL +#~# ORIGINAL case 1 when 2 then 3 @@ -340,10 +340,10 @@ end #~# EXPECTED case 1 -when 2 then 3 +when 2 then 3 end -#~# ORIGINAL +#~# ORIGINAL case 1 when 2 then # comment @@ -355,11 +355,11 @@ case 1 when 2 then # comment end -#~# ORIGINAL +#~# ORIGINAL case 1 when 2 then 3 - else + else 4 end From 208f96a3f94c3a3cbee9cf4c1c2c80962da6a6da Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:37:16 +0200 Subject: [PATCH 18/29] Remove spaces_around_when config --- lib/rufo/formatter.rb | 20 ++++--------------- lib/rufo/formatter/settings.rb | 5 ----- .../spaces_around_when.rb.spec | 17 ---------------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index bc42c100..ad3df88f 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -2828,16 +2828,13 @@ def visit_when(node) # [:when, conds, body, next_exp] _, conds, body, next_exp = node - preserve_whitespace = @spaces_around_when == :dynamic && !@align_case_when - consume_keyword "when" - consume_space(want_preserve_whitespace: preserve_whitespace) + consume_space space_after_when = nil indent(@column) do visit_comma_separated_list conds - space_after_when = current_token if space? && preserve_whitespace skip_space end @@ -2846,7 +2843,6 @@ def visit_when(node) if then_keyword next_token - space_after_then = current_token if space? && preserve_whitespace skip_space info = track_case_when @@ -2858,11 +2854,7 @@ def visit_when(node) # Cancel tracking of `case when ... then` on a nelwine. @case_when_positions.pop else - if space_after_when - write_space space_after_when[2] - else - write_space - end + write_space write "then" @@ -2883,11 +2875,7 @@ def visit_when(node) info[-1] = offset end - if space_after_then - write_space space_after_then[2] - else - write_space - end + write_space end elsif semicolon? skip_semicolons @@ -2927,7 +2915,7 @@ def visit_when(node) if @align_case_when write_space else - write_space_using_setting(first_space, @spaces_around_when) + write_space_using_setting(first_space, :one) end visit_exps next_exp[1] end diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index a24dd566..88eb9f27 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -6,7 +6,6 @@ def init_settings(options) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_when options.fetch(:spaces_around_when, :one) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) @@ -41,10 +40,6 @@ def spaces_in_commands(value) @spaces_in_commands = one_dynamic("spaces_in_commands", value) end - def spaces_around_when(value) - @spaces_around_when = one_dynamic("spaces_around_when", value) - end - def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_around_when.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_around_when.rb.spec index eafa0a63..1dd20bd4 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_around_when.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_around_when.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_around_when: :one case 1 when 2 then 3 @@ -12,19 +11,3 @@ case 1 when 2 then 3 else 4 end - -#~# ORIGINAL -#~# spaces_around_when: :dynamic - -case 1 -when 2 then 3 -else 4 -end - -#~# EXPECTED - -case 1 -when 2 then 3 -else 4 -end - From 6be9b213c8ddd3d7a6661bf3ba7187e02e79cc65 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:42:53 +0200 Subject: [PATCH 19/29] Change spaces_in_commands config to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 26 +++++++++---------- .../formatter_source_specs/and_or_not.rb.spec | 20 +++++++------- .../calls_with_receiver.rb.spec | 2 +- .../formatter_source_specs/defined?.rb.spec | 10 +++---- .../method_calls.rb.spec | 12 ++++----- 6 files changed, 35 insertions(+), 36 deletions(-) diff --git a/.rufo b/.rufo index cc47b1bc..e518cbc1 100644 --- a/.rufo +++ b/.rufo @@ -3,7 +3,6 @@ spaces_inside_hash_brace :never spaces_inside_array_bracket :never spaces_in_ternary :one spaces_in_suffix :one -spaces_in_commands :dynamic spaces_around_binary :one parens_in_def :yes double_newline_inside_type :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 88eb9f27..11017a79 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -1,19 +1,19 @@ class Rufo::Formatter def init_settings(options) - indent_size options.fetch(:indent_size, 2) - spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) - spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) - spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) - spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) - spaces_in_commands options.fetch(:spaces_in_commands, :dynamic) - spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) + indent_size options.fetch(:indent_size, 2) + spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) + spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) + spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) + spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) + spaces_in_commands options.fetch(:spaces_in_commands, :one) + spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) - parens_in_def options.fetch(:parens_in_def, :dynamic) - double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic) - visibility_indent options.fetch(:visibility_indent, :dynamic) - align_case_when options.fetch(:align_case_when, false) - align_chained_calls options.fetch(:align_chained_calls, false) - trailing_commas options.fetch(:trailing_commas, :dynamic) + parens_in_def options.fetch(:parens_in_def, :dynamic) + double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic) + visibility_indent options.fetch(:visibility_indent, :dynamic) + align_case_when options.fetch(:align_case_when, false) + align_chained_calls options.fetch(:align_chained_calls, false) + trailing_commas options.fetch(:trailing_commas, :dynamic) end def indent_size(value) diff --git a/spec/lib/rufo/formatter_source_specs/and_or_not.rb.spec b/spec/lib/rufo/formatter_source_specs/and_or_not.rb.spec index 98435e1a..eab7c4b7 100644 --- a/spec/lib/rufo/formatter_source_specs/and_or_not.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/and_or_not.rb.spec @@ -1,28 +1,28 @@ -#~# ORIGINAL +#~# ORIGINAL - foo and bar + foo and bar #~# EXPECTED foo and bar -#~# ORIGINAL +#~# ORIGINAL - foo or bar + foo or bar #~# EXPECTED foo or bar -#~# ORIGINAL +#~# ORIGINAL not foo #~# EXPECTED -not foo +not foo -#~# ORIGINAL +#~# ORIGINAL not(x) @@ -30,15 +30,15 @@ not(x) not(x) -#~# ORIGINAL +#~# ORIGINAL not (x) #~# EXPECTED -not (x) +not(x) -#~# ORIGINAL +#~# ORIGINAL not((a, b = 1, 2)) diff --git a/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec b/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec index ced593d5..c8bfaba7 100644 --- a/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/calls_with_receiver.rb.spec @@ -310,7 +310,7 @@ x.y 1, 2 #~# EXPECTED -x.y 1, 2 +x.y 1, 2 #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/defined?.rb.spec b/spec/lib/rufo/formatter_source_specs/defined?.rb.spec index 003a3ea5..278e2d0d 100644 --- a/spec/lib/rufo/formatter_source_specs/defined?.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/defined?.rb.spec @@ -1,12 +1,12 @@ -#~# ORIGINAL +#~# ORIGINAL defined? 1 #~# EXPECTED -defined? 1 +defined? 1 -#~# ORIGINAL +#~# ORIGINAL defined? ( 1 ) @@ -14,7 +14,7 @@ defined? ( 1 ) defined? (1) -#~# ORIGINAL +#~# ORIGINAL defined?(1) @@ -22,7 +22,7 @@ defined?(1) defined?(1) -#~# ORIGINAL +#~# ORIGINAL defined?((a, b = 1, 2)) diff --git a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec index 0cd1a09f..db625a21 100644 --- a/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/method_calls.rb.spec @@ -62,7 +62,7 @@ foo 1 #~# EXPECTED -foo 1 +foo 1 #~# ORIGINAL @@ -70,7 +70,7 @@ foo 1, 2 #~# EXPECTED -foo 1, 2 +foo 1, 2 #~# ORIGINAL @@ -78,7 +78,7 @@ foo 1, *x #~# EXPECTED -foo 1, *x +foo 1, *x #~# ORIGINAL @@ -86,7 +86,7 @@ foo 1, *x , 2 #~# EXPECTED -foo 1, *x, 2 +foo 1, *x, 2 #~# ORIGINAL @@ -94,7 +94,7 @@ foo 1, *x , 2 , 3 #~# EXPECTED -foo 1, *x, 2, 3 +foo 1, *x, 2, 3 #~# ORIGINAL @@ -102,7 +102,7 @@ foo 1, *x , 2 , 3 , *z , *w , 4 #~# EXPECTED -foo 1, *x, 2, 3, *z, *w, 4 +foo 1, *x, 2, 3, *z, *w, 4 #~# ORIGINAL From 120b4d02e41ea32adaf9b7fd43732eff6ed318a8 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:48:56 +0200 Subject: [PATCH 20/29] Remove spaces_in_commands config --- lib/rufo/formatter.rb | 13 ++---- lib/rufo/formatter/settings.rb | 5 --- .../spaces_in_commands.rb.spec | 41 ------------------- 3 files changed, 4 insertions(+), 55 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index ad3df88f..525f00e6 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -1167,7 +1167,7 @@ def consume_space_after_command_name write_line write_indent(next_indent) else - write_space_using_setting(first_space, @spaces_in_commands) + write_space_using_setting(first_space, :one) end end @@ -1751,15 +1751,10 @@ def visit_unary(node) consume_op_or_keyword op - setting = op == :not ? @spaces_in_commands : :no + setting = op == :not ? :one : :no first_space = space? - consume_space = first_space && setting == :dynamic - if consume_space - consume_space(want_preserve_whitespace: true) - else - skip_space_or_newline - end + skip_space_or_newline if op == :not has_paren = current_token_kind == :on_lparen @@ -2525,7 +2520,7 @@ def visit_defined(node) has_space = space? if has_space - consume_space(want_preserve_whitespace: @spaces_in_commands == :dynamic) + consume_space else skip_space_or_newline end diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 11017a79..01f6b290 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -5,7 +5,6 @@ def init_settings(options) spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) - spaces_in_commands options.fetch(:spaces_in_commands, :one) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) @@ -36,10 +35,6 @@ def spaces_in_suffix(value) @spaces_in_suffix = one_dynamic("spaces_in_suffix", value) end - def spaces_in_commands(value) - @spaces_in_commands = one_dynamic("spaces_in_commands", value) - end - def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_in_commands.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_in_commands.rb.spec index e7ba2684..292c4ff9 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_in_commands.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_in_commands.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_in_commands: :one foo 1 @@ -8,7 +7,6 @@ foo 1 foo 1 #~# ORIGINAL -#~# spaces_in_commands: :one foo.bar 1 @@ -17,7 +15,6 @@ foo.bar 1 foo.bar 1 #~# ORIGINAL -#~# spaces_in_commands: :dynamic not x @@ -26,25 +23,6 @@ not x not x #~# ORIGINAL -#~# spaces_in_commands: :dynamic - -not x - -#~# EXPECTED - -not x - -#~# ORIGINAL -#~# spaces_in_commands: :one - -not x - -#~# EXPECTED - -not x - -#~# ORIGINAL -#~# spaces_in_commands: :one not x @@ -53,25 +31,6 @@ not x not x #~# ORIGINAL -#~# spaces_in_commands: :dynamic - -defined? 1 - -#~# EXPECTED - -defined? 1 - -#~# ORIGINAL -#~# spaces_in_commands: :dynamic - -defined? 1 - -#~# EXPECTED - -defined? 1 - -#~# ORIGINAL -#~# spaces_in_commands: :one defined? 1 From 0c073b58ce12e80703efab48ce6333ba991f16a5 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:51:11 +0200 Subject: [PATCH 21/29] Change spaces_in_suffix config to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../formatter_source_specs/suffix_if.rb.spec | 20 +++++++++---------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.rufo b/.rufo index e518cbc1..47675691 100644 --- a/.rufo +++ b/.rufo @@ -2,7 +2,6 @@ indent_size 2 spaces_inside_hash_brace :never spaces_inside_array_bracket :never spaces_in_ternary :one -spaces_in_suffix :one spaces_around_binary :one parens_in_def :yes double_newline_inside_type :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 01f6b290..edabe2c2 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -4,7 +4,7 @@ def init_settings(options) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) - spaces_in_suffix options.fetch(:spaces_in_suffix, :dynamic) + spaces_in_suffix options.fetch(:spaces_in_suffix, :one) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/suffix_if.rb.spec b/spec/lib/rufo/formatter_source_specs/suffix_if.rb.spec index 65eea673..97ede793 100644 --- a/spec/lib/rufo/formatter_source_specs/suffix_if.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/suffix_if.rb.spec @@ -1,4 +1,4 @@ -#~# ORIGINAL +#~# ORIGINAL 1 if 2 @@ -6,7 +6,7 @@ 1 if 2 -#~# ORIGINAL +#~# ORIGINAL 1 unless 2 @@ -14,7 +14,7 @@ 1 unless 2 -#~# ORIGINAL +#~# ORIGINAL 1 rescue 2 @@ -22,7 +22,7 @@ 1 rescue 2 -#~# ORIGINAL +#~# ORIGINAL 1 while 2 @@ -30,7 +30,7 @@ 1 while 2 -#~# ORIGINAL +#~# ORIGINAL 1 until 2 @@ -38,7 +38,7 @@ 1 until 2 -#~# ORIGINAL +#~# ORIGINAL x.y rescue z @@ -46,18 +46,18 @@ x.y rescue z x.y rescue z -#~# ORIGINAL +#~# ORIGINAL 1 if 2 #~# EXPECTED -1 if 2 +1 if 2 -#~# ORIGINAL +#~# ORIGINAL foo bar(1) if 2 #~# EXPECTED -foo bar(1) if 2 +foo bar(1) if 2 From 4cb297709f897dcecd21d78d6eb656a9a7bd9990 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:52:22 +0200 Subject: [PATCH 22/29] Remove spaces_in_suffix config --- lib/rufo/formatter.rb | 4 ++-- lib/rufo/formatter/settings.rb | 5 ----- .../lib/rufo/formatter_source_specs/spaces_in_suffix.rb.spec | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 525f00e6..81d64f46 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -894,9 +894,9 @@ def visit_suffix(node, suffix) end visit body - consume_one_dynamic_space @spaces_in_suffix + consume_one_dynamic_space :one consume_keyword(suffix) - consume_one_dynamic_space_or_newline @spaces_in_suffix + consume_one_dynamic_space_or_newline :one visit cond end diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index edabe2c2..67f93802 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -4,7 +4,6 @@ def init_settings(options) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) - spaces_in_suffix options.fetch(:spaces_in_suffix, :one) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) @@ -31,10 +30,6 @@ def spaces_in_ternary(value) @spaces_in_ternary = one_dynamic("spaces_in_ternary", value) end - def spaces_in_suffix(value) - @spaces_in_suffix = one_dynamic("spaces_in_suffix", value) - end - def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_in_suffix.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_in_suffix.rb.spec index 70b262d5..3d4af8e8 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_in_suffix.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_in_suffix.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_in_suffix: :one 1 if 2 From f581ac024c742c1e7d4f49512806488bf0c2dd51 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:54:33 +0200 Subject: [PATCH 23/29] Change spaces_in_ternary config to :one --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../formatter_source_specs/ternaries.rb.spec | 16 ++++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.rufo b/.rufo index 47675691..68c9d8ce 100644 --- a/.rufo +++ b/.rufo @@ -1,7 +1,6 @@ indent_size 2 spaces_inside_hash_brace :never spaces_inside_array_bracket :never -spaces_in_ternary :one spaces_around_binary :one parens_in_def :yes double_newline_inside_type :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 67f93802..f2da35a3 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -3,7 +3,7 @@ def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) - spaces_in_ternary options.fetch(:spaces_in_ternary, :dynamic) + spaces_in_ternary options.fetch(:spaces_in_ternary, :one) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/ternaries.rb.spec b/spec/lib/rufo/formatter_source_specs/ternaries.rb.spec index f2870c0e..57008dc3 100644 --- a/spec/lib/rufo/formatter_source_specs/ternaries.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/ternaries.rb.spec @@ -1,14 +1,14 @@ -#~# ORIGINAL +#~# ORIGINAL 1 ? 2 : 3 #~# EXPECTED -1 ? 2 : 3 +1 ? 2 : 3 -#~# ORIGINAL +#~# ORIGINAL -1 ? +1 ? 2 : 3 #~# EXPECTED @@ -16,9 +16,9 @@ 1 ? 2 : 3 -#~# ORIGINAL +#~# ORIGINAL -1 ? 2 : +1 ? 2 : 3 #~# EXPECTED @@ -26,10 +26,10 @@ 1 ? 2 : 3 -#~# ORIGINAL +#~# ORIGINAL 1?2:3 #~# EXPECTED -1?2:3 +1 ? 2 : 3 From 386429b1bb173db2b2e03a37b9a3f874bc066de7 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Mon, 2 Oct 2017 23:56:45 +0200 Subject: [PATCH 24/29] Remove spaces_in_ternary config option --- lib/rufo/formatter.rb | 8 ++++---- lib/rufo/formatter/settings.rb | 5 ----- .../rufo/formatter_source_specs/spaces_in_ternary.rb.spec | 4 +--- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 81d64f46..4d413b2d 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -871,13 +871,13 @@ def visit_ternary_if(node) _, cond, then_body, else_body = node visit cond - consume_one_dynamic_space @spaces_in_ternary + consume_one_dynamic_space :one consume_op "?" - consume_one_dynamic_space_or_newline @spaces_in_ternary + consume_one_dynamic_space_or_newline :one visit then_body - consume_one_dynamic_space @spaces_in_ternary + consume_one_dynamic_space :one consume_op ":" - consume_one_dynamic_space_or_newline @spaces_in_ternary + consume_one_dynamic_space_or_newline :one visit else_body end diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index f2da35a3..c2b0d065 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -3,7 +3,6 @@ def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) - spaces_in_ternary options.fetch(:spaces_in_ternary, :one) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) @@ -26,10 +25,6 @@ def spaces_inside_array_bracket(value) @spaces_inside_array_bracket = dynamic_always_never_match("spaces_inside_array_bracket", value) end - def spaces_in_ternary(value) - @spaces_in_ternary = one_dynamic("spaces_in_ternary", value) - end - def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_in_ternary.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_in_ternary.rb.spec index b0f1770a..21cfd3bc 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_in_ternary.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_in_ternary.rb.spec @@ -1,5 +1,4 @@ #~# ORIGINAL -#~# spaces_in_ternary: :one 1?2:3 @@ -8,11 +7,10 @@ 1 ? 2 : 3 #~# ORIGINAL -#~# spaces_in_ternary: :dynamic 1 ? 2 : 3 #~# EXPECTED -1 ? 2 : 3 +1 ? 2 : 3 From eeb526c7fab2203a060123ebc73791c332955afb Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Tue, 3 Oct 2017 00:05:41 +0200 Subject: [PATCH 25/29] Change spaces_inside_array_bracket config to :never --- .rufo | 1 - lib/rufo/formatter/settings.rb | 2 +- .../array_access.rb.spec | 54 +++++------ .../array_literal.rb.spec | 36 ++++---- .../array_setter.rb.spec | 4 +- .../trailing_commas.rb.spec | 90 +++++++++---------- 6 files changed, 93 insertions(+), 94 deletions(-) diff --git a/.rufo b/.rufo index 68c9d8ce..5faeea24 100644 --- a/.rufo +++ b/.rufo @@ -1,6 +1,5 @@ indent_size 2 spaces_inside_hash_brace :never -spaces_inside_array_bracket :never spaces_around_binary :one parens_in_def :yes double_newline_inside_type :no diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index c2b0d065..b07dc80d 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -2,7 +2,7 @@ class Rufo::Formatter def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) - spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :dynamic) + spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :never) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/array_access.rb.spec b/spec/lib/rufo/formatter_source_specs/array_access.rb.spec index 85ceff65..26cc0dd9 100644 --- a/spec/lib/rufo/formatter_source_specs/array_access.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/array_access.rb.spec @@ -1,53 +1,53 @@ -#~# ORIGINAL +#~# ORIGINAL foo[ ] #~# EXPECTED -foo[ ] +foo[] -#~# ORIGINAL +#~# ORIGINAL -foo[ +foo[ ] #~# EXPECTED foo[] -#~# ORIGINAL +#~# ORIGINAL foo[ 1 ] #~# EXPECTED -foo[ 1 ] +foo[1] -#~# ORIGINAL +#~# ORIGINAL foo[ 1 , 2 , 3 ] #~# EXPECTED -foo[ 1, 2, 3 ] +foo[1, 2, 3] -#~# ORIGINAL +#~# ORIGINAL -foo[ 1 , - 2 , +foo[ 1 , + 2 , 3 ] #~# EXPECTED -foo[ 1, - 2, - 3 ] +foo[1, + 2, + 3] -#~# ORIGINAL +#~# ORIGINAL -foo[ - 1 , - 2 , +foo[ + 1 , + 2 , 3 ] #~# EXPECTED @@ -55,20 +55,20 @@ foo[ foo[ 1, 2, - 3 ] + 3] -#~# ORIGINAL +#~# ORIGINAL foo[ *x ] #~# EXPECTED -foo[ *x ] +foo[*x] -#~# ORIGINAL +#~# ORIGINAL foo[ - 1, + 1, ] #~# EXPECTED @@ -77,12 +77,12 @@ foo[ 1, ] -#~# ORIGINAL +#~# ORIGINAL foo[ - 1, - 2 , 3, - 4, + 1, + 2 , 3, + 4, ] #~# EXPECTED diff --git a/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec b/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec index 15d2557a..10096ac8 100644 --- a/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/array_literal.rb.spec @@ -12,7 +12,7 @@ #~# EXPECTED -[ 1 ] +[1] #~# ORIGINAL @@ -20,7 +20,7 @@ #~# EXPECTED -[ 1, 2 ] +[1, 2] #~# ORIGINAL @@ -28,7 +28,7 @@ #~# EXPECTED -[ 1, 2 ] +[1, 2] #~# ORIGINAL @@ -112,9 +112,9 @@ #~# EXPECTED -[ 1, - 2, 3, - 4 ] +[1, + 2, 3, + 4] #~# ORIGINAL @@ -124,9 +124,9 @@ #~# EXPECTED -[ 1, - 2, 3, - 4 ] +[1, + 2, 3, + 4] #~# ORIGINAL @@ -137,9 +137,9 @@ #~# EXPECTED -[ 1, - 2, 3, - 4 ] +[1, + 2, 3, + 4] #~# ORIGINAL @@ -150,9 +150,9 @@ #~# EXPECTED -[ 1, - 2, 3, - 4 # foo +[1, + 2, 3, + 4 # foo ] #~# ORIGINAL @@ -188,7 +188,7 @@ end #~# EXPECTED -[ *x ] +[*x] #~# ORIGINAL @@ -196,7 +196,7 @@ end #~# EXPECTED -[ *x, 1 ] +[*x, 1] #~# ORIGINAL @@ -204,7 +204,7 @@ end #~# EXPECTED -[ 1, *x ] +[1, *x] #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec b/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec index 65207f38..45c58902 100644 --- a/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/array_setter.rb.spec @@ -4,7 +4,7 @@ foo[ ] = 1 #~# EXPECTED -foo[ ] = 1 +foo[] = 1 #~# ORIGINAL @@ -12,4 +12,4 @@ foo[ 1 , 2 ] = 3 #~# EXPECTED -foo[ 1, 2 ] = 3 +foo[1, 2] = 3 diff --git a/spec/lib/rufo/formatter_source_specs/trailing_commas.rb.spec b/spec/lib/rufo/formatter_source_specs/trailing_commas.rb.spec index d82cfd5d..6200a0ad 100644 --- a/spec/lib/rufo/formatter_source_specs/trailing_commas.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/trailing_commas.rb.spec @@ -355,8 +355,8 @@ foo( #~# ORIGINAL #~# trailing_commas: :always - [ - 1 , 2 ] + [ + 1 , 2 ] #~# EXPECTED @@ -367,8 +367,8 @@ foo( #~# ORIGINAL #~# trailing_commas: :always - [ - 1 , 2, ] + [ + 1 , 2, ] #~# EXPECTED @@ -379,9 +379,9 @@ foo( #~# ORIGINAL #~# trailing_commas: :always - [ - 1 , 2 , - 3 , 4 ] + [ + 1 , 2 , + 3 , 4 ] #~# EXPECTED @@ -393,9 +393,9 @@ foo( #~# ORIGINAL #~# trailing_commas: :always - [ - 1 , - 2] + [ + 1 , + 2] #~# EXPECTED @@ -407,9 +407,9 @@ foo( #~# ORIGINAL #~# trailing_commas: :always - [ # comment - 1 , - 2] + [ # comment + 1 , + 2] #~# EXPECTED @@ -421,9 +421,9 @@ foo( #~# ORIGINAL #~# trailing_commas: :always - [ - 1 , # comment - 2] + [ + 1 , # comment + 2] #~# EXPECTED @@ -435,65 +435,65 @@ foo( #~# ORIGINAL #~# trailing_commas: :always - [ 1 , - 2, 3, - 4 ] + [ 1 , + 2, 3, + 4 ] #~# EXPECTED -[ 1, - 2, 3, - 4 ] +[1, + 2, 3, + 4] #~# ORIGINAL #~# trailing_commas: :always - [ 1 , - 2, 3, - 4, ] + [ 1 , + 2, 3, + 4, ] #~# EXPECTED -[ 1, - 2, 3, - 4 ] +[1, + 2, 3, + 4] #~# ORIGINAL #~# trailing_commas: :always - [ 1 , - 2, 3, + [ 1 , + 2, 3, 4, - ] + ] #~# EXPECTED -[ 1, - 2, 3, - 4 ] +[1, + 2, 3, + 4] #~# ORIGINAL #~# trailing_commas: :always - [ 1 , - 2, 3, - 4, # foo - ] + [ 1 , + 2, 3, + 4, # foo + ] #~# EXPECTED -[ 1, - 2, 3, - 4 # foo +[1, + 2, 3, + 4 # foo ] #~# ORIGINAL #~# trailing_commas: :always begin - [ - 1 , 2 ] - end + [ + 1 , 2 ] + end #~# EXPECTED @@ -506,7 +506,7 @@ end #~# ORIGINAL #~# trailing_commas: :always - [ + [ 1 # foo ] From b442e3ba307a8b68f8d0c4af79d1a760f47b0365 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Tue, 3 Oct 2017 00:09:35 +0200 Subject: [PATCH 26/29] Remove spaces_inside_array_bracket config --- lib/rufo/formatter.rb | 16 ++--- lib/rufo/formatter/settings.rb | 5 -- .../spaces_inside_array_bracket.rb.spec | 65 ------------------- 3 files changed, 4 insertions(+), 82 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 4d413b2d..400dde9a 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -2332,7 +2332,7 @@ def visit_array_getter_or_setter(name, args) skip_space_or_newline end else - write_space_using_setting(first_space, @spaces_inside_array_bracket) + write_space_using_setting(first_space, :never) needed_indent = column end @@ -2343,7 +2343,7 @@ def visit_array_getter_or_setter(name, args) end end - skip_space_or_newline_using_setting(@spaces_inside_array_bracket) + skip_space_or_newline_using_setting(:never) check :on_rbracket write "]" @@ -2579,12 +2579,7 @@ def visit_literal_elements(elements, inside_hash: false, inside_array: false, to end if inside_array - case @spaces_inside_array_bracket - when :never - needs_final_space = false - when :always - needs_final_space = true - end + needs_final_space = false end if newline? || comment? @@ -2592,8 +2587,6 @@ def visit_literal_elements(elements, inside_hash: false, inside_array: false, to elsif needs_final_space if inside_hash && first_space && @spaces_inside_hash_brace == :dynamic write first_space[2] - elsif inside_array && first_space && @spaces_inside_array_bracket == :dynamic - write first_space[2] else consume_space end @@ -2637,8 +2630,7 @@ def visit_literal_elements(elements, inside_hash: false, inside_array: false, to wrote_comma = check_heredocs_in_literal_elements(is_last, needs_trailing_comma, wrote_comma) if is_last && !comma? && !wrote_comma && !needs_trailing_comma && !comment? - if (inside_hash && @spaces_inside_hash_brace == :dynamic) || - (inside_array && @spaces_inside_array_bracket == :dynamic) + if (inside_hash && @spaces_inside_hash_brace == :dynamic) if first_space write first_space[2] else diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index b07dc80d..252bc907 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -2,7 +2,6 @@ class Rufo::Formatter def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) - spaces_inside_array_bracket options.fetch(:spaces_inside_array_bracket, :never) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) parens_in_def options.fetch(:parens_in_def, :dynamic) @@ -21,10 +20,6 @@ def spaces_inside_hash_brace(value) @spaces_inside_hash_brace = dynamic_always_never_match("spaces_inside_hash_brace", value) end - def spaces_inside_array_bracket(value) - @spaces_inside_array_bracket = dynamic_always_never_match("spaces_inside_array_bracket", value) - end - def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_inside_array_bracket.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_inside_array_bracket.rb.spec index 75f04389..9abf80e0 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_inside_array_bracket.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_inside_array_bracket.rb.spec @@ -1,72 +1,7 @@ #~# ORIGINAL -#~# spaces_inside_array_bracket: :never [ 1 ] #~# EXPECTED [1] - -#~# ORIGINAL -#~# spaces_inside_array_bracket: :always - -[1] - -#~# EXPECTED - -[ 1 ] - -#~# ORIGINAL -#~# spaces_inside_array_bracket: :dynamic - -[1] - -#~# EXPECTED - -[1] - -#~# ORIGINAL -#~# spaces_inside_array_bracket: :dynamic - -[ 1] - -#~# EXPECTED - -[ 1] - -#~# ORIGINAL -#~# spaces_inside_array_bracket: :dynamic - -[ 1, 2 ] - -#~# EXPECTED - -[ 1, 2 ] - -#~# ORIGINAL -#~# spaces_inside_array_bracket: :match - -[ 1, 2] - -#~# EXPECTED - -[ 1, 2 ] - -#~# ORIGINAL -#~# spaces_inside_array_bracket: :match - -[1, 2 ] - -#~# EXPECTED - -[1, 2] - -#~# ORIGINAL -#~# spaces_inside_array_bracket: :dynamic - -a[ 1 ] - -#~# EXPECTED - -a[ 1 ] - From 8d7d450c99a2eba90fb49e8ed91ae1788b279d0d Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Tue, 3 Oct 2017 00:12:58 +0200 Subject: [PATCH 27/29] Change spaces_in_inline_expressions config to :one --- lib/rufo/formatter/settings.rb | 2 +- .../formatter_source_specs/blocks.rb.spec | 4 +- .../rufo/formatter_source_specs/while.rb.spec | 40 +++++++++---------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 252bc907..4898d73f 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -3,7 +3,7 @@ def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) - spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :dynamic) + spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :one) parens_in_def options.fetch(:parens_in_def, :dynamic) double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic) visibility_indent options.fetch(:visibility_indent, :dynamic) diff --git a/spec/lib/rufo/formatter_source_specs/blocks.rb.spec b/spec/lib/rufo/formatter_source_specs/blocks.rb.spec index 89fcb051..4cfd7f81 100644 --- a/spec/lib/rufo/formatter_source_specs/blocks.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/blocks.rb.spec @@ -199,7 +199,7 @@ foo do end #~# EXPECTED -foo do end +foo do end #~# ORIGINAL @@ -207,7 +207,7 @@ foo do 1 end #~# EXPECTED -foo do 1 end +foo do 1 end #~# ORIGINAL diff --git a/spec/lib/rufo/formatter_source_specs/while.rb.spec b/spec/lib/rufo/formatter_source_specs/while.rb.spec index 288454be..6af1f9a1 100644 --- a/spec/lib/rufo/formatter_source_specs/while.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/while.rb.spec @@ -1,4 +1,4 @@ -#~# ORIGINAL +#~# ORIGINAL while 1 ; end @@ -6,7 +6,7 @@ while 1 ; end while 1; end -#~# ORIGINAL +#~# ORIGINAL while 1 ; 2 ; end @@ -14,9 +14,9 @@ while 1 ; 2 ; end while 1; 2; end -#~# ORIGINAL +#~# ORIGINAL -while 1 +while 1 end #~# EXPECTED @@ -24,11 +24,11 @@ while 1 while 1 end -#~# ORIGINAL +#~# ORIGINAL -while 1 - 2 - 3 +while 1 + 2 + 3 end #~# EXPECTED @@ -38,11 +38,11 @@ while 1 3 end -#~# ORIGINAL +#~# ORIGINAL -while 1 # foo - 2 - 3 +while 1 # foo + 2 + 3 end #~# EXPECTED @@ -52,30 +52,30 @@ while 1 # foo 3 end -#~# ORIGINAL +#~# ORIGINAL while 1 do end #~# EXPECTED -while 1 do end +while 1 do end -#~# ORIGINAL +#~# ORIGINAL while 1 do 2 end #~# EXPECTED -while 1 do 2 end +while 1 do 2 end -#~# ORIGINAL +#~# ORIGINAL -begin - while 1 do 2 end +begin + while 1 do 2 end end #~# EXPECTED begin - while 1 do 2 end + while 1 do 2 end end From da931dd56ada23ac9bca71915e764312793b8461 Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Tue, 3 Oct 2017 00:15:43 +0200 Subject: [PATCH 28/29] Remove spaces_in_inline_expressions config --- lib/rufo/formatter.rb | 17 +++----- lib/rufo/formatter/settings.rb | 5 --- .../spaces_in_inline_expressions.rb.spec | 40 ------------------- 3 files changed, 6 insertions(+), 56 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 400dde9a..72e2ec5f 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -3315,7 +3315,7 @@ def indent_body(exps, force_multiline: false, want_multiline: false) if has_semicolon write "; " else - write_space_using_setting(first_space, @spaces_in_inline_expressions) + write_space_using_setting(first_space, :one) end return end @@ -3340,23 +3340,18 @@ def indent_body(exps, force_multiline: false, want_multiline: false) if has_then write " then " elsif has_do - write_space_using_setting(first_space, @spaces_in_inline_expressions, at_least_one: true) + write_space_using_setting(first_space, :one, at_least_one: true) write "do" - write_space_using_setting(second_space, @spaces_in_inline_expressions, at_least_one: true) + write_space_using_setting(second_space, :one, at_least_one: true) elsif has_semicolon write "; " else - write_space_using_setting(first_space, @spaces_in_inline_expressions, at_least_one: true) + write_space_using_setting(first_space, :one, at_least_one: true) end visit_exps exps, with_indent: false, with_lines: false - first_space = skip_space - if first_space && @spaces_in_inline_expressions == :dynamic && - !(semicolon? || newline? || comment?) - write_space first_space[2] - else - consume_space - end + consume_space + return end diff --git a/lib/rufo/formatter/settings.rb b/lib/rufo/formatter/settings.rb index 4898d73f..6103bc3f 100644 --- a/lib/rufo/formatter/settings.rb +++ b/lib/rufo/formatter/settings.rb @@ -3,7 +3,6 @@ def init_settings(options) indent_size options.fetch(:indent_size, 2) spaces_inside_hash_brace options.fetch(:spaces_inside_hash_brace, :dynamic) spaces_around_binary options.fetch(:spaces_around_binary, :dynamic) - spaces_in_inline_expressions options.fetch(:spaces_in_inline_expressions, :one) parens_in_def options.fetch(:parens_in_def, :dynamic) double_newline_inside_type options.fetch(:double_newline_inside_type, :dynamic) visibility_indent options.fetch(:visibility_indent, :dynamic) @@ -24,10 +23,6 @@ def spaces_around_binary(value) @spaces_around_binary = one_dynamic("spaces_around_binary", value) end - def spaces_in_inline_expressions(value) - @spaces_in_inline_expressions = one_dynamic("spaces_in_inline_expressions", value) - end - def parens_in_def(value) @parens_in_def = yes_dynamic("parens_in_def", value) end diff --git a/spec/lib/rufo/formatter_source_specs/spaces_in_inline_expressions.rb.spec b/spec/lib/rufo/formatter_source_specs/spaces_in_inline_expressions.rb.spec index 200e29da..3f097c19 100644 --- a/spec/lib/rufo/formatter_source_specs/spaces_in_inline_expressions.rb.spec +++ b/spec/lib/rufo/formatter_source_specs/spaces_in_inline_expressions.rb.spec @@ -1,14 +1,4 @@ #~# ORIGINAL -#~# spaces_in_inline_expressions: :dynamic - -begin end - -#~# EXPECTED - -begin end - -#~# ORIGINAL -#~# spaces_in_inline_expressions: :one begin end @@ -17,16 +7,6 @@ begin end begin end #~# ORIGINAL -#~# spaces_in_inline_expressions: :dynamic - -begin 1 end - -#~# EXPECTED - -begin 1 end - -#~# ORIGINAL -#~# spaces_in_inline_expressions: :one begin 1 end @@ -35,16 +15,6 @@ begin 1 end begin 1 end #~# ORIGINAL -#~# spaces_in_inline_expressions: :dynamic - -def foo() 1 end - -#~# EXPECTED - -def foo() 1 end - -#~# ORIGINAL -#~# spaces_in_inline_expressions: :one def foo() 1 end @@ -53,16 +23,6 @@ def foo() 1 end def foo() 1 end #~# ORIGINAL -#~# spaces_in_inline_expressions: :dynamic - -def foo(x) 1 end - -#~# EXPECTED - -def foo(x) 1 end - -#~# ORIGINAL -#~# spaces_in_inline_expressions: :one def foo(x) 1 end From b6ea4b68f900c38989412cd1830aa4983a48c4ab Mon Sep 17 00:00:00 2001 From: Max Brosnahan Date: Thu, 12 Oct 2017 12:32:10 +0200 Subject: [PATCH 29/29] Remove unneeded code --- lib/rufo/formatter.rb | 58 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 39 deletions(-) diff --git a/lib/rufo/formatter.rb b/lib/rufo/formatter.rb index 96d990ab..08a6ac4a 100644 --- a/lib/rufo/formatter.rb +++ b/lib/rufo/formatter.rb @@ -718,7 +718,7 @@ def visit_assign(node) line = @line visit target - consume_one_dynamic_space :one + consume_space track_assignment consume_op "=" @@ -736,7 +736,7 @@ def visit_op_assign(node) line = @line visit target - consume_one_dynamic_space :one + consume_space # [:@op, "+=", [1, 2]], check :on_op @@ -861,13 +861,13 @@ def visit_ternary_if(node) _, cond, then_body, else_body = node visit cond - consume_one_dynamic_space :one + consume_space consume_op "?" - consume_one_dynamic_space_or_newline :one + consume_space_or_newline visit then_body - consume_one_dynamic_space :one + consume_space consume_op ":" - consume_one_dynamic_space_or_newline :one + consume_space_or_newline visit else_body end @@ -884,9 +884,9 @@ def visit_suffix(node, suffix) end visit body - consume_one_dynamic_space :one + consume_space consume_keyword(suffix) - consume_one_dynamic_space_or_newline :one + consume_space_or_newline visit cond end @@ -1240,7 +1240,7 @@ def visit_call_with_block(node) visit call if block[0] == :brace_block - consume_one_dynamic_space :one + consume_space else consume_space end @@ -1262,7 +1262,7 @@ def visit_brace_block(node) if void_exps?(body) consume_token :on_lbrace consume_block_args args - consume_one_dynamic_space :one + consume_space consume_token :on_rbrace return end @@ -1273,14 +1273,14 @@ def visit_brace_block(node) if current_token_line == closing_brace_token[0][0] consume_token :on_lbrace consume_block_args args - consume_one_dynamic_space :one + consume_space visit_exps body, with_lines: false while semicolon? next_token end - consume_one_dynamic_space :one + consume_space consume_token :on_rbrace return @@ -1327,7 +1327,7 @@ def visit_do_block(node) def consume_block_args(args) if args - consume_one_dynamic_space_or_newline :one + consume_space_or_newline # + 1 because of |...| # ^ indent(@column + 1) do @@ -2012,9 +2012,9 @@ def visit_params(node) write_params_comma if needs_comma visit_comma_separated_list(args_with_default) do |arg, default| visit arg - consume_one_dynamic_space :one + consume_space consume_op "=" - consume_one_dynamic_space :one + consume_space visit default end needs_comma = true @@ -2227,13 +2227,13 @@ def visit_hash_key_value(node) arrow = symbol || !(key[0] == :@label || key[0] == :dyna_symbol) visit key - consume_one_dynamic_space :one + consume_space # Don't output `=>` for keys that are `label: value` # or `"label": value` if arrow consume_op "=>" - consume_one_dynamic_space :one + consume_space end visit value @@ -2910,33 +2910,13 @@ def consume_space(want_preserve_whitespace: false) end end - def consume_one_dynamic_space(setting) - if setting == :one - consume_space - else - if space? - consume_space(want_preserve_whitespace: true) - elsif newline? - next_token - if space? - write_space current_token[2] - end - skip_space_or_newline - else - skip_space_or_newline - end - end - end - - def consume_one_dynamic_space_or_newline(setting) + def consume_space_or_newline first_space = skip_space if newline? || comment? consume_end_of_line write_indent(next_indent) - elsif first_space && setting == :dynamic - write_space first_space[2] else - consume_space if setting == :one + consume_space end end