syntax_tree-array_brackets 0.1.0 → 0.1.2

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: 310c9fa6ba5f710b1cfd410e930e2c55c67a89c02310099b542f1970c11f47ca
4
- data.tar.gz: 18d763015004da43943e609760b85e0d8c4265a974662e3743c7f40ffd21ba21
3
+ metadata.gz: 49b660457db14aff9dcbd80f2c32d80f90572e5eb29926649c5a917da00c283d
4
+ data.tar.gz: fdc99b74a18cd62d1b7f1aa447abdee845e7ffc64ffbd530cded7f0a34f0af37
5
5
  SHA512:
6
- metadata.gz: 2b5e483494a5df437e5dfb3c919224b662d128d0a46fb00448b029e02dc8646cb8ce1191fe00381e8636e96733960d94ac02b1a1b33838da015f4bffad44be3b
7
- data.tar.gz: 13ec518da27b95ac23f5d1c9ffef9c2d0a08379451d447145689518d21cbce9e813a3d506cbefde8bc05c294a203691303c6477d264a6c6ed0e482adb97df865
6
+ metadata.gz: 299e44a474ec394a6acb7387c4bad12b299b3d8b9a43cc67327424cca01ae5d6686252771086e6b86cdfc2740cf298b73e58f785b23be0675ef4c4eb81da375d
7
+ data.tar.gz: 90f32e7ddb3d3902c574e9d0e0896e255239d1bc6e3d6609c07b8808b07bf42261263fc7bb7a7752efab5016ad1bdbc6cf2f618d4ea193c4a3e71865cf64bf39
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- syntax_tree-array_brackets (0.1.0)
4
+ syntax_tree-array_brackets (0.1.2)
5
5
  syntax_tree (>= 2.0.1)
6
6
 
7
7
  GEM
@@ -50,6 +50,7 @@ GEM
50
50
 
51
51
  PLATFORMS
52
52
  arm64-darwin-21
53
+ x86_64-linux
53
54
 
54
55
  DEPENDENCIES
55
56
  rake (~> 13.0)
data/Rakefile CHANGED
@@ -7,6 +7,6 @@ require "syntax_tree/rake_tasks"
7
7
 
8
8
  RSpec::Core::RakeTask.new(:spec)
9
9
  RuboCop::RakeTask.new
10
- SyntaxTree::Rake::CheckTask.new()
10
+ SyntaxTree::Rake::CheckTask.new
11
11
 
12
12
  task default: [:spec, :rubocop, :"stree:check"]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SyntaxTree
4
4
  module ArrayBrackets
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -37,17 +37,19 @@ module SyntaxTree
37
37
  q.group do
38
38
  q.text(opening)
39
39
 
40
- loc = elements.first.location.to(elements.last.location)
41
- str_contents =
42
- elements.map do |element|
43
- StringContent.new(parts: [element], location: nil)
44
- end
45
- contents = Args.new(parts: str_contents, location: loc)
40
+ unless elements.empty?
41
+ loc = elements.first.location.to(elements.last.location)
42
+ str_contents =
43
+ elements.map do |element|
44
+ StringContent.new(parts: [element], location: nil)
45
+ end
46
+ contents = Args.new(parts: str_contents, location: loc)
46
47
 
47
- q.indent do
48
- q.breakable_empty
49
- q.format(contents)
50
- q.if_break { q.text(",") } if q.trailing_comma?
48
+ q.indent do
49
+ q.breakable_empty
50
+ q.format(contents)
51
+ q.if_break { q.text(",") } if q.trailing_comma?
52
+ end
51
53
  end
52
54
 
53
55
  q.breakable_empty
@@ -63,22 +65,46 @@ module SyntaxTree
63
65
  q.group do
64
66
  q.text(opening)
65
67
 
66
- loc = elements.first.location.to(elements.last.location)
67
- str_contents =
68
- elements.map do |element|
69
- SymbolLiteral.new(value: element, location: nil)
70
- end
71
- contents = Args.new(parts: str_contents, location: loc)
68
+ unless elements.empty?
69
+ loc = elements.first.location.to(elements.last.location)
70
+ literals = convert_to_literals(q, elements)
71
+ contents = Args.new(parts: literals, location: loc)
72
72
 
73
- q.indent do
74
- q.breakable_empty
75
- q.format(contents)
76
- q.if_break { q.text(",") } if q.trailing_comma?
73
+ q.indent do
74
+ q.breakable_empty
75
+ q.format(contents)
76
+ q.if_break { q.text(",") } if q.trailing_comma?
77
+ end
77
78
  end
78
79
 
79
80
  q.breakable_empty
80
81
  q.text(closing)
81
82
  end
82
83
  end
84
+
85
+ private
86
+
87
+ def convert_to_literals(q, elements)
88
+ elements.map do |element|
89
+ value =
90
+ if element.value.intern.inspect.include?("\"") # consider symbols like :"foo:bar", :"?"
91
+ value = get_intern_representation(q, element.value)
92
+ element.copy(value: value, location: element.location)
93
+ else
94
+ element
95
+ end
96
+
97
+ SymbolLiteral.new(value: value, location: nil)
98
+ end
99
+ end
100
+
101
+ def get_intern_representation(q, value)
102
+ if value == q.quote
103
+ return "\"\\\"\"" if q.quote == "\""
104
+ return "\'\\\'\'" if q.quote == "'" # rubocop:disable Style/RedundantStringEscape
105
+ end
106
+
107
+ "#{q.quote}#{value}#{q.quote}"
108
+ end
83
109
  end
84
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: syntax_tree-array_brackets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nobuo Takizawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-21 00:00:00.000000000 Z
11
+ date: 2023-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: syntax_tree