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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3ce2fde0ad82db9c01bd5ba06cfd1b12123819422a8384783678fe02bc083453
4
- data.tar.gz: b188d825c3e6cf728b7290fc0a4e7d2ec72d1eb22a3949854b024b47d2c1d04f
3
+ metadata.gz: e59505a1d473ed64e03853dd3465ce958bb81ee2dfcd2ec38b0280a5ee3dd98a
4
+ data.tar.gz: e13a2d15ba45209e81213bd7b5a3f1ea58a26cdcb9446f29f9f6b5906aa7e9fe
5
5
  SHA512:
6
- metadata.gz: 894a43bd0eddb8374bf65e266f08d1a7b99652cdafb48e1cef96e5ed168d006a6dc58b12e7e1cb9f757efad66365e6835f56cc0dedb8d184693d09304a9aafaf
7
- data.tar.gz: 20614c5ac0f308334d20e21e2ee69e6ba283e4cb5e4bf0274f0b375fc397fc4b29569ead66ffbacbc2070cb0af66f05ae7bfc78fa2c64529d6015c09fc7ebaa0
6
+ metadata.gz: 82cf388eb36848ff8f01f122177e436205ccebfd6f4e19488e65e1adecdff267246292da159a99b42cca23f5adefb505483ebe1357b928922ee824ac4c832086
7
+ data.tar.gz: 3069cb6a421189bad2b0aba4eed4a3d50d5e24128f1fcd6fa6ee12db5110b5a53babf2b310175ba4701b59a5bb3447bb4fd1505282c5f3de44c5e2c3a530fc6d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (3.0.9)
4
+ code-ruby (3.0.10)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.9
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 expression.include?("\n") || candidate.length > MAX_LINE_LENGTH
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.each_with_index.map do |line, index|
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.9
4
+ version: 3.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié