Skip to content

Commit

Permalink
Change trailing comma config from symbols to booleans
Browse files Browse the repository at this point in the history
Why: The symbols were effectively booleans anyway so this simplifies using and remembering config options.
  • Loading branch information
gingermusketeer authored and splattael committed Nov 8, 2017
1 parent e333d0f commit 1097750
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
1 change: 0 additions & 1 deletion .rufo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
spaces_around_binary :one
double_newline_inside_type :no
trailing_commas :always
align_case_when true
align_chained_calls true
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ The default for the following options has changed:
- parens_in_def: ~~dynamic~~ > yes
- last_has_comma: ~~dynamic~~ > always

Valid options for:
- trailing_commas: `[:always, :never]` > `[true, false]`

### Removed
The following configuration options have been **removed**, and replaced with non-configurable sane defaults, [per discussion](https://github.com/ruby-formatter/rufo/issues/2):
- align_assignments
Expand Down
13 changes: 4 additions & 9 deletions lib/rufo/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ def visit_call_at_paren(node, args)

if found_comma
if needs_trailing_newline
write "," if trailing_commas != :never && !block_arg
write "," if trailing_commas && !block_arg

next_token
indent(next_indent) do
Expand All @@ -1048,7 +1048,7 @@ def visit_call_at_paren(node, args)

if newline? || comment?
if needs_trailing_newline
write "," if trailing_commas == :always && want_trailing_comma
write "," if trailing_commas && want_trailing_comma

indent(next_indent) do
consume_end_of_line
Expand All @@ -1059,7 +1059,7 @@ def visit_call_at_paren(node, args)
end
else
if needs_trailing_newline && !found_comma
write "," if trailing_commas == :always && want_trailing_comma
write "," if trailing_commas && want_trailing_comma
consume_end_of_line
write_indent
end
Expand Down Expand Up @@ -2651,12 +2651,7 @@ def visit_literal_elements(elements, inside_hash: false, inside_array: false, to
end

if needs_trailing_comma
case trailing_commas
when :always
write "," unless wrote_comma
when :never
# Nothing
end
write "," unless wrote_comma || !trailing_commas

consume_end_of_line(first_space: first_space)
write_indent
Expand Down
2 changes: 1 addition & 1 deletion lib/rufo/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Rufo::Settings
double_newline_inside_type: [:dynamic, :no],
align_case_when: [false, true],
align_chained_calls: [false, true],
trailing_commas: [:always, :never],
trailing_commas: [true, false],
}

attr_accessor *OPTIONS.keys
Expand Down
56 changes: 28 additions & 28 deletions spec/lib/rufo/formatter_source_specs/trailing_commas.rb.spec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1,
Expand All @@ -14,7 +14,7 @@
]

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

[
1,
Expand All @@ -29,7 +29,7 @@
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1,
Expand All @@ -44,7 +44,7 @@
]

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

[
1,
Expand All @@ -59,7 +59,7 @@
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

{
foo: 1,
Expand All @@ -74,7 +74,7 @@
}

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

{
foo: 1,
Expand All @@ -89,7 +89,7 @@
}

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

{
foo: 1,
Expand All @@ -104,7 +104,7 @@
}

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

{
foo: 1,
Expand All @@ -119,7 +119,7 @@
}

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

foo(
one: 1,
Expand All @@ -136,7 +136,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

foo(
one: 1,
Expand All @@ -153,7 +153,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

foo(
one: 1,
Expand All @@ -170,7 +170,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

foo(
one: 1,
Expand All @@ -187,7 +187,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

foo(
one: 1)
Expand All @@ -199,7 +199,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

foo(
one: 1)
Expand All @@ -211,7 +211,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

foo(
one: 1,)
Expand All @@ -223,7 +223,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :never
#~# trailing_commas: false

foo(
one: 1,)
Expand All @@ -235,7 +235,7 @@ foo(
)

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1 , 2 ]
Expand All @@ -247,7 +247,7 @@ foo(
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1 , 2, ]
Expand All @@ -259,7 +259,7 @@ foo(
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1 , 2 ,
Expand All @@ -273,7 +273,7 @@ foo(
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1 ,
Expand All @@ -287,7 +287,7 @@ foo(
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[ # comment
1 ,
Expand All @@ -301,7 +301,7 @@ foo(
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1 , # comment
Expand All @@ -315,7 +315,7 @@ foo(
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[ 1 ,
2, 3,
Expand All @@ -328,7 +328,7 @@ foo(
4]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[ 1 ,
2, 3,
Expand All @@ -341,7 +341,7 @@ foo(
4]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[ 1 ,
2, 3,
Expand All @@ -355,7 +355,7 @@ foo(
4]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[ 1 ,
2, 3,
Expand All @@ -370,7 +370,7 @@ foo(
]

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

begin
[
Expand All @@ -386,7 +386,7 @@ begin
end

#~# ORIGINAL
#~# trailing_commas: :always
#~# trailing_commas: true

[
1 # foo
Expand Down

0 comments on commit 1097750

Please sign in to comment.