Skip to content

Commit 5ba7817

Browse files
committed
Consider closing ) on keyword break, closes #12206
1 parent de33d57 commit 5ba7817

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
lines changed

lib/elixir/lib/code/formatter.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ defmodule Code.Formatter do
11771177
right_doc
11781178
|> nest(2, :break)
11791179
|> concat(break(""))
1180+
|> concat(")")
11801181
|> group(:inherit)
11811182
|> next_break_fits(:enabled)
11821183

@@ -1208,7 +1209,7 @@ defmodule Code.Formatter do
12081209
if skip_parens? do
12091210
nest(args_doc, :cursor, :break)
12101211
else
1211-
nest(args_doc, 2, :break) |> concat(break(""))
1212+
nest(args_doc, 2, :break) |> concat(break("")) |> concat(")")
12121213
end
12131214

12141215
{args_doc, next_break_fits?, state}
@@ -1234,7 +1235,6 @@ defmodule Code.Formatter do
12341235
|> concat(break(""))
12351236
|> nest(2, :break)
12361237
|> concat(args_doc)
1237-
|> concat(")")
12381238
|> concat(extra)
12391239
|> group()
12401240
end

lib/elixir/test/elixir/calendar_test.exs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,31 +243,49 @@ defmodule CalendarTest do
243243
|> elem(month - 1)
244244
end
245245

246-
assert Calendar.strftime(%{month: 1}, "%b", abbreviated_month_names: abbreviated_month_names) ==
246+
assert Calendar.strftime(%{month: 1}, "%b",
247+
abbreviated_month_names: abbreviated_month_names
248+
) ==
247249
"янв"
248250

249-
assert Calendar.strftime(%{month: 2}, "%b", abbreviated_month_names: abbreviated_month_names) ==
251+
assert Calendar.strftime(%{month: 2}, "%b",
252+
abbreviated_month_names: abbreviated_month_names
253+
) ==
250254
"февр"
251255

252-
assert Calendar.strftime(%{month: 3}, "%b", abbreviated_month_names: abbreviated_month_names) ==
256+
assert Calendar.strftime(%{month: 3}, "%b",
257+
abbreviated_month_names: abbreviated_month_names
258+
) ==
253259
"март"
254260

255-
assert Calendar.strftime(%{month: 4}, "%b", abbreviated_month_names: abbreviated_month_names) ==
261+
assert Calendar.strftime(%{month: 4}, "%b",
262+
abbreviated_month_names: abbreviated_month_names
263+
) ==
256264
"апр"
257265

258-
assert Calendar.strftime(%{month: 5}, "%b", abbreviated_month_names: abbreviated_month_names) ==
266+
assert Calendar.strftime(%{month: 5}, "%b",
267+
abbreviated_month_names: abbreviated_month_names
268+
) ==
259269
"май"
260270

261-
assert Calendar.strftime(%{month: 6}, "%b", abbreviated_month_names: abbreviated_month_names) ==
271+
assert Calendar.strftime(%{month: 6}, "%b",
272+
abbreviated_month_names: abbreviated_month_names
273+
) ==
262274
"июнь"
263275

264-
assert Calendar.strftime(%{month: 7}, "%b", abbreviated_month_names: abbreviated_month_names) ==
276+
assert Calendar.strftime(%{month: 7}, "%b",
277+
abbreviated_month_names: abbreviated_month_names
278+
) ==
265279
"июль"
266280

267-
assert Calendar.strftime(%{month: 8}, "%b", abbreviated_month_names: abbreviated_month_names) ==
281+
assert Calendar.strftime(%{month: 8}, "%b",
282+
abbreviated_month_names: abbreviated_month_names
283+
) ==
268284
"авг"
269285

270-
assert Calendar.strftime(%{month: 9}, "%b", abbreviated_month_names: abbreviated_month_names) ==
286+
assert Calendar.strftime(%{month: 9}, "%b",
287+
abbreviated_month_names: abbreviated_month_names
288+
) ==
271289
"сент"
272290

273291
assert Calendar.strftime(%{month: 10}, "%b",

lib/elixir/test/elixir/code_formatter/integration_test.exs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,26 @@ defmodule Code.Formatter.IntegrationTest do
383383
"""
384384
end
385385

386+
test "keyword list at line limit" do
387+
bad = """
388+
pre()
389+
config(arg, foo: bar)
390+
post()
391+
"""
392+
393+
good = """
394+
pre()
395+
396+
config(arg,
397+
foo: bar
398+
)
399+
400+
post()
401+
"""
402+
403+
assert_format bad, good, line_length: 20
404+
end
405+
386406
test "do at the end of the line with single argument" do
387407
bad = """
388408
defmodule Location do

lib/elixir/test/elixir/config/reader_test.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ defmodule Config.ReaderTest do
5959
assert_raise RuntimeError,
6060
~r"import_config/1 is not enabled for this configuration file",
6161
fn ->
62-
Config.Reader.read!(fixture_path("configs/good_import.exs"), imports: :disabled)
62+
Config.Reader.read!(fixture_path("configs/good_import.exs"),
63+
imports: :disabled
64+
)
6365
end
6466
end
6567

0 commit comments

Comments
 (0)