yaml-sort 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -3
- data/Rakefile +16 -0
- data/lib/yaml/sort/cli.rb +6 -3
- data/lib/yaml/sort/parser.rb +68 -66
- data/lib/yaml/sort/version.rb +1 -1
- data/yaml-sort.gemspec +1 -0
- metadata +21 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 232d936095f9aac0e3f4098fa2cc4f1d608ddc79be9cb4e757fb476fa75999e3
|
4
|
+
data.tar.gz: be5949810ea40472c5d80e7f23d96886e964847b26d9526f67b337a77acfe490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e90a5d3ff86076d86b0629ec1a387aa179588f678d17c5f60fcae2d01ffda38eb28f308d5d3d7df1a29d6b1a194701caab02409d26d364f8c2c8fb7403ca2a0a
|
7
|
+
data.tar.gz: e2fb3054b83242a9fad8c596c6f79ecfce1f66169234c7e1bc8a179214bd41288e08eb608981b08d2312dff721e3bfa18aadaa429dded7bae1eeb702dc06bdd3
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
4
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
2
5
|
|
3
|
-
## [0.1.0
|
6
|
+
## [1.0.1](https://github.com/smortex/yaml-sort/tree/1.0.1) (2022-04-24)
|
4
7
|
|
5
|
-
-
|
8
|
+
[Full Changelog](https://github.com/smortex/yaml-sort/compare/v1.0.0...1.0.1)
|
9
|
+
|
10
|
+
**Fixed bugs:**
|
11
|
+
|
12
|
+
- Fix processing of some YAML files without a `START_OF_DOCUMENT` [\#6](https://github.com/smortex/yaml-sort/pull/6) ([smortex](https://github.com/smortex))
|
13
|
+
- Fix error reporting [\#5](https://github.com/smortex/yaml-sort/pull/5) ([smortex](https://github.com/smortex))
|
14
|
+
- Fix display of filename on parse errors [\#1](https://github.com/smortex/yaml-sort/pull/1) ([smortex](https://github.com/smortex))
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/Rakefile
CHANGED
@@ -21,3 +21,19 @@ end
|
|
21
21
|
|
22
22
|
task spec: ["lib/yaml/sort/parser.rb"]
|
23
23
|
task cucumber: ["lib/yaml/sort/parser.rb"]
|
24
|
+
|
25
|
+
require "github_changelog_generator/task"
|
26
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
27
|
+
config.future_release = Yaml::Sort::VERSION
|
28
|
+
config.header = <<~HEADER.chomp
|
29
|
+
# Changelog
|
30
|
+
All notable changes to this project will be documented in this file.
|
31
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
32
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
33
|
+
HEADER
|
34
|
+
config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog ignore]
|
35
|
+
config.user = "smortex"
|
36
|
+
config.project = "yaml-sort"
|
37
|
+
config.since_tag = "v1.0.0"
|
38
|
+
config.issues = false
|
39
|
+
end
|
data/lib/yaml/sort/cli.rb
CHANGED
@@ -52,8 +52,11 @@ module Yaml
|
|
52
52
|
|
53
53
|
def process_document(filename, options)
|
54
54
|
yaml = read_document(filename)
|
55
|
-
sorted_yaml = sort_yaml(yaml)
|
55
|
+
sorted_yaml = sort_yaml(yaml, filename)
|
56
56
|
write_output(yaml, sorted_yaml, filename, options)
|
57
|
+
rescue Racc::ParseError => e
|
58
|
+
warn(e.message)
|
59
|
+
@exit_code = 1
|
57
60
|
end
|
58
61
|
|
59
62
|
def read_document(filename)
|
@@ -64,8 +67,8 @@ module Yaml
|
|
64
67
|
end
|
65
68
|
end
|
66
69
|
|
67
|
-
def sort_yaml(yaml)
|
68
|
-
document = @parser.parse(yaml)
|
70
|
+
def sort_yaml(yaml, filename)
|
71
|
+
document = @parser.parse(yaml, filename: filename)
|
69
72
|
document = document.sort
|
70
73
|
"---\n#{document}\n"
|
71
74
|
end
|
data/lib/yaml/sort/parser.rb
CHANGED
@@ -13,9 +13,11 @@ module Yaml
|
|
13
13
|
module Sort
|
14
14
|
class Parser < Racc::Parser
|
15
15
|
|
16
|
-
module_eval(<<'...end parser.ra/module_eval...', 'parser.ra',
|
16
|
+
module_eval(<<'...end parser.ra/module_eval...', 'parser.ra', 33)
|
17
17
|
|
18
18
|
def scan(text)
|
19
|
+
text = "---\n#{text}" unless text.start_with?("---\n")
|
20
|
+
|
19
21
|
scan_value = false
|
20
22
|
|
21
23
|
@lines = text.lines
|
@@ -29,7 +31,7 @@ def scan(text)
|
|
29
31
|
until s.eos?
|
30
32
|
if scan_value
|
31
33
|
unless s.match?(/[[:space:]]*\n/)
|
32
|
-
@position += s.matched_size if s.scan(
|
34
|
+
@position += s.matched_size if s.scan(/[[:blank:]]*/)
|
33
35
|
case
|
34
36
|
when s.scan(/[|>][-+]?(?=\n)/)
|
35
37
|
match = s.matched
|
@@ -68,20 +70,23 @@ def scan(text)
|
|
68
70
|
scan_value = false
|
69
71
|
else
|
70
72
|
case
|
71
|
-
when s.scan(/---/)
|
72
|
-
when s.scan(
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
when s.scan(/\n
|
73
|
+
when s.scan(/---/) then emit(:START_OF_DOCUMENT, s.matched)
|
74
|
+
when s.scan(/\n[[:blank:]]*(?=\n)/)
|
75
|
+
# Ignore empty lines
|
76
|
+
@lineno += 1
|
77
|
+
@position = 0
|
78
|
+
when s.scan(/\n[[:blank:]]*#.*/) then emit(:COMMENT, s.matched)
|
79
|
+
when s.scan(/\n([[:blank:]]*-) */) then emit(:ITEM, s.matched, indent: s.captures[0])
|
80
|
+
when s.scan(/\n[[:blank:]]*\.\.\./) then emit(:END_OF_DOCUMENT, s.matched)
|
81
|
+
when s.scan(/\n?([[:blank:]]*)([^[[:space:]]\n]+):(?=[ \n])/)
|
77
82
|
indent = s.captures[0]
|
78
83
|
indent = last_indent_value + indent + " " unless s.matched.start_with?("\n")
|
79
84
|
emit(:KEY, s.matched, indent: indent)
|
80
85
|
|
81
86
|
when s.scan(/\n\z/)
|
82
87
|
# Done
|
83
|
-
|
84
|
-
|
88
|
+
when s.match?(/./)
|
89
|
+
scan_value = true
|
85
90
|
else
|
86
91
|
raise "LoST: #{s.rest.inspect} #{s.eos?}"
|
87
92
|
end
|
@@ -128,7 +133,6 @@ def emit(token, value, length: nil, indent: nil)
|
|
128
133
|
value: value,
|
129
134
|
lineno: @lineno,
|
130
135
|
position: @position,
|
131
|
-
filename: @filename,
|
132
136
|
length: length,
|
133
137
|
indent: indent,
|
134
138
|
}
|
@@ -146,7 +150,7 @@ end
|
|
146
150
|
def unindent(new_indent = nil)
|
147
151
|
while @indent_stack.count > 0 && (new_indent.nil? || @indent_stack.last.length > new_indent.length)
|
148
152
|
value = @indent_stack.pop
|
149
|
-
@tokens << [:UNINDENT, { value: value, lineno: @lineno, position: 0,
|
153
|
+
@tokens << [:UNINDENT, { value: value, lineno: @lineno, position: 0, length: value.length, indent: nil }]
|
150
154
|
end
|
151
155
|
end
|
152
156
|
|
@@ -154,73 +158,73 @@ def next_token
|
|
154
158
|
@current_token = @tokens.shift
|
155
159
|
end
|
156
160
|
|
157
|
-
def parse(text)
|
161
|
+
def parse(text, filename: nil)
|
162
|
+
@filename = filename || "<stdin>"
|
158
163
|
scan(text)
|
159
164
|
do_parse
|
160
165
|
end
|
161
166
|
|
162
167
|
def on_error(error_token_id, error_value, value_stack)
|
163
|
-
|
164
|
-
|
165
|
-
|
168
|
+
message = if @current_token
|
169
|
+
<<~MESSAGE
|
170
|
+
#{@filename}:#{@current_token[1][:lineno]} unexpected #{@current_token[0]}
|
171
|
+
#{@lines[@current_token[1][:lineno] - 1].chomp}
|
172
|
+
#{" " * @current_token[1][:position]}^#{"~" * ([@current_token[1][:length] - 1, 0].max)}
|
173
|
+
MESSAGE
|
174
|
+
else
|
175
|
+
"#{@filename}:#{@lineno} unexpected end-of-file"
|
176
|
+
end
|
166
177
|
|
167
|
-
raise
|
178
|
+
raise(Racc::ParseError, message)
|
168
179
|
end
|
169
180
|
...end parser.ra/module_eval...
|
170
181
|
##### State transition tables begin ###
|
171
182
|
|
172
183
|
racc_action_table = [
|
173
|
-
2, 11,
|
174
|
-
|
175
|
-
15, 10 ]
|
184
|
+
5, 9, 2, 11, 5, 9, 3, 11, 5, 9,
|
185
|
+
12, 11, 9, 14, 16, 11, 13 ]
|
176
186
|
|
177
187
|
racc_action_check = [
|
178
|
-
|
179
|
-
|
180
|
-
6, 6 ]
|
188
|
+
2, 2, 0, 2, 9, 9, 1, 9, 11, 11,
|
189
|
+
3, 11, 6, 6, 7, 7, 4 ]
|
181
190
|
|
182
191
|
racc_action_pointer = [
|
183
|
-
|
184
|
-
|
185
|
-
nil ]
|
192
|
+
0, 6, -4, 10, 13, nil, 7, 8, nil, 0,
|
193
|
+
nil, 4, nil, nil, nil, nil, nil, nil, nil, nil ]
|
186
194
|
|
187
195
|
racc_action_default = [
|
188
|
-
-
|
189
|
-
-
|
190
|
-
-1 ]
|
196
|
+
-12, -12, -12, -12, -2, -3, -12, -12, -7, -12,
|
197
|
+
-10, -12, 20, -1, -4, -6, -5, -9, -8, -11 ]
|
191
198
|
|
192
199
|
racc_goto_table = [
|
193
|
-
|
194
|
-
18 ]
|
200
|
+
4, 1, 15, 17, nil, nil, nil, 18, nil, 19 ]
|
195
201
|
|
196
202
|
racc_goto_check = [
|
197
|
-
2, 1,
|
198
|
-
2 ]
|
203
|
+
2, 1, 5, 6, nil, nil, nil, 2, nil, 2 ]
|
199
204
|
|
200
205
|
racc_goto_pointer = [
|
201
|
-
nil, 1,
|
206
|
+
nil, 1, -2, nil, nil, -4, -4 ]
|
202
207
|
|
203
208
|
racc_goto_default = [
|
204
|
-
nil, nil, nil,
|
209
|
+
nil, nil, nil, 6, 7, 8, 10 ]
|
205
210
|
|
206
211
|
racc_reduce_table = [
|
207
212
|
0, 0, :racc_error,
|
208
213
|
3, 9, :_reduce_1,
|
209
214
|
2, 9, :_reduce_2,
|
210
|
-
1,
|
211
|
-
|
215
|
+
1, 10, :_reduce_3,
|
216
|
+
2, 10, :_reduce_4,
|
212
217
|
2, 10, :_reduce_5,
|
213
|
-
2,
|
214
|
-
|
215
|
-
|
216
|
-
2,
|
217
|
-
|
218
|
-
|
219
|
-
2, 14, :_reduce_12 ]
|
218
|
+
2, 11, :_reduce_6,
|
219
|
+
1, 11, :_reduce_7,
|
220
|
+
2, 13, :_reduce_8,
|
221
|
+
2, 12, :_reduce_9,
|
222
|
+
1, 12, :_reduce_10,
|
223
|
+
2, 14, :_reduce_11 ]
|
220
224
|
|
221
|
-
racc_reduce_n =
|
225
|
+
racc_reduce_n = 12
|
222
226
|
|
223
|
-
racc_shift_n =
|
227
|
+
racc_shift_n = 20
|
224
228
|
|
225
229
|
racc_token_table = {
|
226
230
|
false => 0,
|
@@ -230,7 +234,7 @@ racc_token_table = {
|
|
230
234
|
:VALUE => 4,
|
231
235
|
:KEY => 5,
|
232
236
|
:UNINDENT => 6,
|
233
|
-
|
237
|
+
:ITEM => 7 }
|
234
238
|
|
235
239
|
racc_nt_base = 8
|
236
240
|
|
@@ -260,7 +264,7 @@ Racc_token_to_s_table = [
|
|
260
264
|
"VALUE",
|
261
265
|
"KEY",
|
262
266
|
"UNINDENT",
|
263
|
-
"
|
267
|
+
"ITEM",
|
264
268
|
"$start",
|
265
269
|
"document",
|
266
270
|
"value",
|
@@ -289,11 +293,16 @@ module_eval(<<'.,.,', 'parser.ra', 10)
|
|
289
293
|
end
|
290
294
|
.,.,
|
291
295
|
|
292
|
-
|
296
|
+
module_eval(<<'.,.,', 'parser.ra', 12)
|
297
|
+
def _reduce_3(val, _values, result)
|
298
|
+
result = Scalar.new(val[0])
|
299
|
+
result
|
300
|
+
end
|
301
|
+
.,.,
|
293
302
|
|
294
303
|
module_eval(<<'.,.,', 'parser.ra', 13)
|
295
304
|
def _reduce_4(val, _values, result)
|
296
|
-
result =
|
305
|
+
result = val[0]
|
297
306
|
result
|
298
307
|
end
|
299
308
|
.,.,
|
@@ -305,50 +314,43 @@ module_eval(<<'.,.,', 'parser.ra', 14)
|
|
305
314
|
end
|
306
315
|
.,.,
|
307
316
|
|
308
|
-
module_eval(<<'.,.,', 'parser.ra',
|
317
|
+
module_eval(<<'.,.,', 'parser.ra', 16)
|
309
318
|
def _reduce_6(val, _values, result)
|
310
|
-
result = val[0]
|
319
|
+
val[0].add_item(*val[1]); result = val[0]
|
311
320
|
result
|
312
321
|
end
|
313
322
|
.,.,
|
314
323
|
|
315
324
|
module_eval(<<'.,.,', 'parser.ra', 17)
|
316
325
|
def _reduce_7(val, _values, result)
|
317
|
-
|
326
|
+
result = Dictionary.create(*val[0])
|
318
327
|
result
|
319
328
|
end
|
320
329
|
.,.,
|
321
330
|
|
322
|
-
module_eval(<<'.,.,', 'parser.ra',
|
331
|
+
module_eval(<<'.,.,', 'parser.ra', 19)
|
323
332
|
def _reduce_8(val, _values, result)
|
324
|
-
result =
|
333
|
+
result = [Scalar.new(val[0]), val[1]]
|
325
334
|
result
|
326
335
|
end
|
327
336
|
.,.,
|
328
337
|
|
329
|
-
module_eval(<<'.,.,', 'parser.ra',
|
338
|
+
module_eval(<<'.,.,', 'parser.ra', 21)
|
330
339
|
def _reduce_9(val, _values, result)
|
331
|
-
|
340
|
+
val[0].add_item(*val[1]); result = val[0]
|
332
341
|
result
|
333
342
|
end
|
334
343
|
.,.,
|
335
344
|
|
336
345
|
module_eval(<<'.,.,', 'parser.ra', 22)
|
337
346
|
def _reduce_10(val, _values, result)
|
338
|
-
val[0].add_item(*val[1]); result = val[0]
|
339
|
-
result
|
340
|
-
end
|
341
|
-
.,.,
|
342
|
-
|
343
|
-
module_eval(<<'.,.,', 'parser.ra', 23)
|
344
|
-
def _reduce_11(val, _values, result)
|
345
347
|
result = List.create(*val[0])
|
346
348
|
result
|
347
349
|
end
|
348
350
|
.,.,
|
349
351
|
|
350
|
-
module_eval(<<'.,.,', 'parser.ra',
|
351
|
-
def
|
352
|
+
module_eval(<<'.,.,', 'parser.ra', 24)
|
353
|
+
def _reduce_11(val, _values, result)
|
352
354
|
result = [Scalar.new(val[0]), val[1]]
|
353
355
|
result
|
354
356
|
end
|
data/lib/yaml/sort/version.rb
CHANGED
data/yaml-sort.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml-sort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Romain Tartière
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cri
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: github_changelog_generator
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: racc
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +66,7 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
|
-
description:
|
69
|
+
description:
|
56
70
|
email:
|
57
71
|
- romain@blogreen.org
|
58
72
|
executables:
|
@@ -89,7 +103,7 @@ metadata:
|
|
89
103
|
source_code_uri: https://github.com/smortex/yaml-sort
|
90
104
|
changelog_uri: https://github.com/smortex/yaml-sort/blob/master/CHANGELOG.md
|
91
105
|
rubygems_mfa_required: 'true'
|
92
|
-
post_install_message:
|
106
|
+
post_install_message:
|
93
107
|
rdoc_options: []
|
94
108
|
require_paths:
|
95
109
|
- lib
|
@@ -104,8 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
118
|
- !ruby/object:Gem::Version
|
105
119
|
version: '0'
|
106
120
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
108
|
-
signing_key:
|
121
|
+
rubygems_version: 3.3.10
|
122
|
+
signing_key:
|
109
123
|
specification_version: 4
|
110
124
|
summary: Sort lines in YAML files in a predictable order
|
111
125
|
test_files: []
|