code-ruby 3.0.9 → 3.0.10
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 +11 -2
- data/spec/code/format_spec.rb +4 -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: e59505a1d473ed64e03853dd3465ce958bb81ee2dfcd2ec38b0280a5ee3dd98a
|
|
4
|
+
data.tar.gz: e13a2d15ba45209e81213bd7b5a3f1ea58a26cdcb9446f29f9f6b5906aa7e9fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 82cf388eb36848ff8f01f122177e436205ccebfd6f4e19488e65e1adecdff267246292da159a99b42cca23f5adefb505483ebe1357b928922ee824ac4c832086
|
|
7
|
+
data.tar.gz: 3069cb6a421189bad2b0aba4eed4a3d50d5e24128f1fcd6fa6ee12db5110b5a53babf2b310175ba4701b59a5bb3447bb4fd1505282c5f3de44c5e2c3a530fc6d
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.0.
|
|
1
|
+
3.0.10
|
data/lib/code/format.rb
CHANGED
|
@@ -434,7 +434,11 @@ class Code
|
|
|
434
434
|
"#{expression}#{operator}#{right}"
|
|
435
435
|
else
|
|
436
436
|
candidate = "#{expression} #{operator} #{right}"
|
|
437
|
-
if
|
|
437
|
+
if multiline_collection_statement?(other[:statement]) &&
|
|
438
|
+
right.include?("\n")
|
|
439
|
+
first_line, *rest = right.lines(chomp: true)
|
|
440
|
+
[ "#{expression} #{operator} #{first_line}", *rest ].join("\n")
|
|
441
|
+
elsif expression.include?("\n") || candidate.length > MAX_LINE_LENGTH
|
|
438
442
|
right_lines =
|
|
439
443
|
if right.include?("\n")
|
|
440
444
|
right.lines(chomp: true).map(&:lstrip)
|
|
@@ -442,7 +446,7 @@ class Code
|
|
|
442
446
|
right.split(" #{operator} ")
|
|
443
447
|
end
|
|
444
448
|
continuation_lines =
|
|
445
|
-
right_lines.
|
|
449
|
+
right_lines.map do |line|
|
|
446
450
|
content = line.lstrip
|
|
447
451
|
prefix =
|
|
448
452
|
(content.start_with?("#{operator} ") ? "" : "#{operator} ")
|
|
@@ -594,6 +598,11 @@ class Code
|
|
|
594
598
|
values.join(", ").length > MAX_INLINE_COLLECTION_LENGTH
|
|
595
599
|
end
|
|
596
600
|
|
|
601
|
+
def multiline_collection_statement?(statement)
|
|
602
|
+
statement.is_a?(Hash) &&
|
|
603
|
+
(statement.key?(:dictionnary) || statement.key?(:list))
|
|
604
|
+
end
|
|
605
|
+
|
|
597
606
|
def multiline_call_arguments?(raw_arguments, arguments)
|
|
598
607
|
return true if arguments.any? { |argument| argument.include?("\n") }
|
|
599
608
|
return true if arguments.size > MAX_INLINE_COLLECTION_ITEMS
|
data/spec/code/format_spec.rb
CHANGED
|
@@ -47,6 +47,10 @@ RSpec.describe Code::Format do
|
|
|
47
47
|
[
|
|
48
48
|
"x = { content: \"you select the funniest tweets for a french \" + \"audience from the provided candidates. pick up to \" + \"{max_selected}. prioritize genuinely funny content\" + \" (jokes, memes, punchlines, absurd). avoid \" + \"politics/news/serious content. output only json.\" }",
|
|
49
49
|
"x = {\n content: \"you select the funniest tweets for a french \"\n + \"audience from the provided candidates. pick up to \"\n + \"{max_selected}. prioritize genuinely funny content\"\n + \" (jokes, memes, punchlines, absurd). avoid \"\n + \"politics/news/serious content. output only json.\"\n}"
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
"blocks << { title: \"hello world\", description: \"lorem ipsum dolor es sit\", position: 1 }",
|
|
53
|
+
"blocks << {\n title: \"hello world\",\n description: \"lorem ipsum dolor es sit\",\n position: 1\n}"
|
|
50
54
|
]
|
|
51
55
|
].each do |input, expected|
|
|
52
56
|
it "formats #{input.inspect}" do
|