code-ruby 3.0.4 → 3.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/format.rb +15 -3
- data/lib/code/parser.rb +11 -6
- data/spec/code/format_spec.rb +8 -0
- data/spec/code_spec.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 71c8d3a9deab8aee738543c6fb7a3b06732c5ecd0fbd042ec41c7e3d3a351bf1
|
|
4
|
+
data.tar.gz: e828824ea1a50b4fa0cdb071aeee9b0042933dfad6b80c90ee91df7010946fd1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75f6791a43a543361becdde69f55c47134dc2386ef6e018df1fed31b261f748afb1a16233cccc1d1512f95858866654954250b2d48570510e3910e71efdc38f7
|
|
7
|
+
data.tar.gz: '041049251701b05e2ea7f3c95ed48173b4cdc1fc76dfef311e5109f6c3c25de51fe9c0a604261915759617dc1684a59d01defffc5578e9eb57d65bb9c1658201'
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.0.
|
|
1
|
+
3.0.5
|
data/lib/code/format.rb
CHANGED
|
@@ -413,10 +413,22 @@ class Code
|
|
|
413
413
|
else
|
|
414
414
|
candidate = "#{expression} #{operator} #{right}"
|
|
415
415
|
if expression.include?("\n") || candidate.length > MAX_LINE_LENGTH
|
|
416
|
-
|
|
416
|
+
right_lines =
|
|
417
|
+
if right.include?("\n")
|
|
418
|
+
right.lines(chomp: true).map(&:lstrip)
|
|
419
|
+
else
|
|
420
|
+
right.split(" #{operator} ")
|
|
421
|
+
end
|
|
417
422
|
continuation_lines =
|
|
418
|
-
|
|
419
|
-
|
|
423
|
+
right_lines.each_with_index.map do |line, index|
|
|
424
|
+
content = line.lstrip
|
|
425
|
+
prefix =
|
|
426
|
+
if content.start_with?("#{operator} ")
|
|
427
|
+
""
|
|
428
|
+
else
|
|
429
|
+
"#{operator} "
|
|
430
|
+
end
|
|
431
|
+
"#{INDENT * (indent + 1)}#{prefix}#{content}"
|
|
420
432
|
end
|
|
421
433
|
"#{expression}\n#{continuation_lines.join("\n")}"
|
|
422
434
|
else
|
data/lib/code/parser.rb
CHANGED
|
@@ -350,11 +350,10 @@ class Code
|
|
|
350
350
|
skip_newlines
|
|
351
351
|
|
|
352
352
|
if match?(:keyword, "if") || match?(:keyword, "unless")
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
elses << { operator: else_operator, statement: else_statement, body: else_body }
|
|
353
|
+
elses << {
|
|
354
|
+
operator: "else",
|
|
355
|
+
body: [parse_if_expression(advance.value)]
|
|
356
|
+
}
|
|
358
357
|
else
|
|
359
358
|
elses << { operator: "else", body: parse_body(%w[end]) }
|
|
360
359
|
end
|
|
@@ -365,6 +364,7 @@ class Code
|
|
|
365
364
|
break
|
|
366
365
|
end
|
|
367
366
|
|
|
367
|
+
skip_newlines
|
|
368
368
|
advance if match?(:keyword, "end")
|
|
369
369
|
|
|
370
370
|
{
|
|
@@ -382,6 +382,7 @@ class Code
|
|
|
382
382
|
|
|
383
383
|
statement = parse_expression unless operator == "loop"
|
|
384
384
|
body = parse_body(%w[end])
|
|
385
|
+
skip_newlines
|
|
385
386
|
advance if match?(:keyword, "end")
|
|
386
387
|
|
|
387
388
|
{
|
|
@@ -414,7 +415,10 @@ class Code
|
|
|
414
415
|
parse_delimited_code("{", "}")
|
|
415
416
|
elsif match?(:keyword, "do") || match?(:keyword, "begin")
|
|
416
417
|
advance
|
|
417
|
-
parse_code(stop_keywords: ["end"]).tap
|
|
418
|
+
parse_code(stop_keywords: ["end"]).tap do
|
|
419
|
+
skip_newlines
|
|
420
|
+
advance if match?(:keyword, "end")
|
|
421
|
+
end
|
|
418
422
|
else
|
|
419
423
|
[parse_expression]
|
|
420
424
|
end
|
|
@@ -548,6 +552,7 @@ class Code
|
|
|
548
552
|
expect(:keyword, "do")
|
|
549
553
|
parameters = parse_pipe_parameters
|
|
550
554
|
body = parse_code(stop_keywords: ["end"])
|
|
555
|
+
skip_newlines
|
|
551
556
|
expect(:keyword, "end")
|
|
552
557
|
end
|
|
553
558
|
|
data/spec/code/format_spec.rb
CHANGED
|
@@ -23,6 +23,14 @@ RSpec.describe Code::Format do
|
|
|
23
23
|
"if true 1 elsif false 2 else 3 end",
|
|
24
24
|
"if true\n 1\nelsif false\n 2\nelse\n 3\nend"
|
|
25
25
|
],
|
|
26
|
+
[
|
|
27
|
+
"if false 1 else if true 2 else 3 end",
|
|
28
|
+
"if false\n 1\nelse\n if true\n 2\n else\n 3\n end\nend"
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
"event[:uid].present? and event[:summary].present? and event[:starts_at].present? and event[:ends_at].present?",
|
|
32
|
+
"event[:uid].present?\n and event[:summary].present?\n and event[:starts_at].present?\n and event[:ends_at].present?"
|
|
33
|
+
],
|
|
26
34
|
[
|
|
27
35
|
"sum = (a, b: 2) => { a + b } sum(1)",
|
|
28
36
|
"sum = (a, b: 2) => {\n a + b\n}\n\nsum(1)"
|
data/spec/code_spec.rb
CHANGED
|
@@ -366,7 +366,10 @@ RSpec.describe Code do
|
|
|
366
366
|
["if false 1 else 2", "2"],
|
|
367
367
|
["if false 1 else if false 2", "nothing"],
|
|
368
368
|
["if false 1 else if true 2", "2"],
|
|
369
|
+
["if false 1 else if false 2 else 3 end", "3"],
|
|
370
|
+
["if false 1 else if true 2 else 3 end", "2"],
|
|
369
371
|
["if false 1 else unless false 2", "2"],
|
|
372
|
+
["if false 1 else unless true 2 else 3 end", "3"],
|
|
370
373
|
["if false 1 else unless true 2", "nothing"],
|
|
371
374
|
["if false 1 elsif false 2", "nothing"],
|
|
372
375
|
["if false 1 elsif true 2", "2"],
|