yaml-sort 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a923ba44e82aa9eba2dbaa2ba2c4c30a6c775a5a6d0e2f447ec6e0682dc119df
4
- data.tar.gz: 637f1efc9b2104818816ce37a62385a149c657d079ad50a6cb8337a9c56a7eee
3
+ metadata.gz: bbee3a96fd3ecb9c7610a0621d80d796bb656a338512655175f213727af356c6
4
+ data.tar.gz: 1b1609202ae8cd7cc002c6a868d836ddfb89681d75efc4c5b996264d85d3392d
5
5
  SHA512:
6
- metadata.gz: 04c75095cfe4fe25a42fdf0d0a4184a0324b1c64244ff3930d082e23f0efd393dbea5f4ea3f00f2364d48307ff37677b17348afa5f57ea367c525248ea3c4ecd
7
- data.tar.gz: b6f2583c7170070daa6bd3dbc1067e280fc26c4bc88895158039a6e2ce5dc67177ef2210978bfbb332496a207070a61c4d2c56a5a4a2913ff6d9bf83f5d89293
6
+ metadata.gz: adbbda3bc7d506f276266b8d3f8bdf88c2032f2b80f64061fb965b25368e735996e7c164737ebebeed0c73fc5757669c7b099b362126f4a05dd37c33b7606d95
7
+ data.tar.gz: affae50f2aeff9ec3e96709f162a06a8cc1b7d2cbeb8ab1f1c8e98a10be3efe36642c9b69d57a1fd07a6c2b17ed09e74d5695f89b488fffca905b4bddfaebaf1
data/CHANGELOG.md CHANGED
@@ -3,9 +3,34 @@ All notable changes to this project will be documented in this file.
3
3
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
4
4
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
- ## [2.0.0](https://github.com/smortex/yaml-sort/tree/2.0.0) (2022-04-25)
6
+ ## [v2.1.0](https://github.com/smortex/yaml-sort/tree/v2.1.0) (2022-07-03)
7
7
 
8
- [Full Changelog](https://github.com/smortex/yaml-sort/compare/v1.0.1...2.0.0)
8
+ [Full Changelog](https://github.com/smortex/yaml-sort/compare/v2.0.2...v2.1.0)
9
+
10
+ **Implemented enhancements:**
11
+
12
+ - Make the Rake tasks silent [\#11](https://github.com/smortex/yaml-sort/pull/11) ([smortex](https://github.com/smortex))
13
+ - Improve --lint by showing a diff on error [\#10](https://github.com/smortex/yaml-sort/pull/10) ([smortex](https://github.com/smortex))
14
+
15
+ ## [v2.0.2](https://github.com/smortex/yaml-sort/tree/v2.0.2) (2022-06-10)
16
+
17
+ [Full Changelog](https://github.com/smortex/yaml-sort/compare/v2.0.1...v2.0.2)
18
+
19
+ **Fixed bugs:**
20
+
21
+ - Fix infinite loops when processing files with trailing whitespace [\#9](https://github.com/smortex/yaml-sort/pull/9) ([smortex](https://github.com/smortex))
22
+
23
+ ## [v2.0.1](https://github.com/smortex/yaml-sort/tree/v2.0.1) (2022-06-01)
24
+
25
+ [Full Changelog](https://github.com/smortex/yaml-sort/compare/v2.0.0...v2.0.1)
26
+
27
+ **Fixed bugs:**
28
+
29
+ - Fix parsing of keys with spaces [\#8](https://github.com/smortex/yaml-sort/pull/8) ([smortex](https://github.com/smortex))
30
+
31
+ ## [v2.0.0](https://github.com/smortex/yaml-sort/tree/v2.0.0) (2022-04-25)
32
+
33
+ [Full Changelog](https://github.com/smortex/yaml-sort/compare/v1.0.1...v2.0.0)
9
34
 
10
35
  **Merged pull requests:**
11
36
 
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ task cucumber: ["lib/yaml/sort/parser.rb"]
24
24
 
25
25
  require "github_changelog_generator/task"
26
26
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
27
- config.future_release = Yaml::Sort::VERSION
27
+ config.future_release = "v#{Yaml::Sort::VERSION}"
28
28
  config.header = <<~HEADER.chomp
29
29
  # Changelog
30
30
  All notable changes to this project will be documented in this file.
data/lib/yaml/sort/cli.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require "optparse"
4
4
 
5
5
  require "cri"
6
+ require "tempfile"
6
7
 
7
8
  module Yaml
8
9
  module Sort
@@ -25,7 +26,7 @@ module Yaml
25
26
  opts.on("-l", "--lint", "Ensure files content is sorted as expected") do
26
27
  options[:lint] = true
27
28
  end
28
- end.parse!
29
+ end.parse!(argv)
29
30
 
30
31
  if !options[:in_place] && !options[:lint] && argv.count > 1
31
32
  warn "Sorting multiple YAML document to stdout does not make sense"
@@ -47,7 +48,7 @@ module Yaml
47
48
  end
48
49
  end
49
50
 
50
- @exit_code
51
+ $kernel.exit(@exit_code) # rubocop:disable Style/GlobalVars
51
52
  end
52
53
 
53
54
  def process_document(filename, options)
@@ -78,13 +79,28 @@ module Yaml
78
79
  File.write(filename, sorted_yaml)
79
80
  elsif options[:lint]
80
81
  if yaml != sorted_yaml
81
- warn "#{filename || "<stdin>"} is not sorted as expected"
82
+ show_diff(filename, yaml, sorted_yaml)
82
83
  @exit_code = 1
83
84
  end
84
85
  else
85
86
  puts sorted_yaml
86
87
  end
87
88
  end
89
+
90
+ def show_diff(filename, actual, expected)
91
+ filename ||= "<stdin>"
92
+
93
+ a = Tempfile.new
94
+ a.write(actual)
95
+ a.close
96
+
97
+ b = Tempfile.new
98
+ b.write(expected)
99
+ b.close
100
+
101
+ warn "diff #{File.join("a", filename)} #{File.join("b", filename)}"
102
+ warn `diff -u --label "#{File.join("a", filename)}" #{a.path} --label "#{File.join("b", filename)}" #{b.path}`
103
+ end
88
104
  end
89
105
  end
90
106
  end
@@ -30,43 +30,42 @@ def scan(text)
30
30
 
31
31
  until s.eos?
32
32
  if scan_value
33
- unless s.match?(/[[:space:]]*\n/)
34
- @position += s.matched_size if s.scan(/[[:blank:]]*/)
35
- case
36
- when s.scan(/[|>][-+]?(?=\n)/)
37
- match = s.matched
38
-
39
- while s.match?("\n" + last_indent_value + " ")
40
- match += s.scan(/\n[^\n]+(?=\n)/)
41
- end
42
- emit(:VALUE, match)
43
- when s.scan(/"/)
44
- match = s.matched
45
- loop do
46
- match += s.scan_until(/"|\\/)
47
- if match[-1] == "\\"
48
- match += s.scan(/.|\n/)
49
- else
50
- break
51
- end
52
- end
53
- emit(:VALUE, match)
54
- when s.scan(/'/)
55
- match = s.matched
56
- loop do
57
- match += s.scan_until(/'/)
58
- break unless s.match?(/'/)
59
- match += s.scan(/'/)
60
- end
61
- emit(:VALUE, match)
62
- when s.scan(/\S+/)
63
- match = s.matched
64
- until s.match?(/[\n]/) || s.eos?
65
- match += s.scan(/[^\n]+/)
33
+ @position += s.matched_size if s.scan(/[[:blank:]]*/)
34
+ case
35
+ when s.scan(/[|>][-+]?(?=\n)/)
36
+ match = s.matched
37
+
38
+ while s.match?("\n" + last_indent_value + " ")
39
+ match += s.scan(/\n[^\n]+(?=\n)/)
40
+ end
41
+ emit(:VALUE, match)
42
+ when s.scan(/"/)
43
+ match = s.matched
44
+ loop do
45
+ match += s.scan_until(/"|\\/)
46
+ if match[-1] == "\\"
47
+ match += s.scan(/.|\n/)
48
+ else
49
+ break
66
50
  end
67
- emit(:VALUE, match)
68
51
  end
52
+ emit(:VALUE, match)
53
+ when s.scan(/'/)
54
+ match = s.matched
55
+ loop do
56
+ match += s.scan_until(/'/)
57
+ break unless s.match?(/'/)
58
+ match += s.scan(/'/)
59
+ end
60
+ emit(:VALUE, match)
61
+ when s.scan(/\S+/)
62
+ match = s.matched
63
+ until s.match?(/[\n]/) || s.eos?
64
+ match += s.scan(/[^\n]+/)
65
+ end
66
+ emit(:VALUE, match)
69
67
  end
68
+ s.scan(/[[:blank:]]*/)
70
69
  scan_value = false
71
70
  else
72
71
  case
@@ -78,7 +77,7 @@ def scan(text)
78
77
  when s.scan(/\n[[:blank:]]*#.*/) then emit(:COMMENT, s.matched)
79
78
  when s.scan(/\n([[:blank:]]*-) */) then emit(:ITEM, s.matched, indent: s.captures[0])
80
79
  when s.scan(/\n[[:blank:]]*\.\.\./) then emit(:END_OF_DOCUMENT, s.matched)
81
- when s.scan(/\n?([[:blank:]]*)([^[[:space:]]\n]+:)(?=[ \n])/)
80
+ when s.scan(/\n?([[:blank:]]*)(.+:)(?=[ \n])/)
82
81
  indent = s.captures[0]
83
82
  indent = last_indent_value + indent + " " unless s.matched.start_with?("\n")
84
83
  emit(:KEY, s.matched, indent: indent, value: s.captures[1])
@@ -88,7 +87,20 @@ def scan(text)
88
87
  when s.match?(/./)
89
88
  scan_value = true
90
89
  else
91
- raise "LoST: #{s.rest.inspect} #{s.eos?}"
90
+ message = if @lines[@lineno - 1][@position] == "\n"
91
+ <<~MESSAGE
92
+ #{@filename}:#{@lineno + 1}: unexpected content
93
+ #{@lines[@lineno].chomp}
94
+ ^#{"~" * (@lines[@lineno].chomp.length - 1)}
95
+ MESSAGE
96
+ else
97
+ <<~MESSAGE
98
+ #{@filename}:#{@lineno}: unexpected content
99
+ #{@lines[@lineno - 1].chomp}
100
+ #{" " * @position}^
101
+ MESSAGE
102
+ end
103
+ raise(Racc::ParseError, message)
92
104
  end
93
105
  end
94
106
  end
@@ -3,11 +3,11 @@
3
3
  namespace :lint do
4
4
  desc "Check Hiera data content ordering"
5
5
  task :hiera_data_ordering do
6
- sh "yaml-sort", "--lint", *Dir.glob("data/**/*.yaml")
6
+ sh "yaml-sort", "--lint", *Dir.glob("data/**/*.yaml"), verbose: false
7
7
  end
8
8
  end
9
9
 
10
10
  desc "Reorder Hiera data in-place"
11
11
  task :reorder_hiera_data do
12
- sh "yaml-sort", "--in-place", *Dir.glob("data/**/*.yaml")
12
+ sh "yaml-sort", "--in-place", *Dir.glob("data/**/*.yaml"), verbose: false
13
13
  end
@@ -3,11 +3,11 @@
3
3
  namespace :test do
4
4
  desc "Check translations content ordering"
5
5
  task :translations_ordering do
6
- sh "yaml-sort", "--lint", *Dir.glob("config/locales/**/*.yml")
6
+ sh "yaml-sort", "--lint", *Dir.glob("config/locales/**/*.yml"), verbose: false
7
7
  end
8
8
  end
9
9
 
10
10
  desc "Reorder translations in-place"
11
11
  task :reorder_translations do
12
- sh "yaml-sort", "--in-place", *Dir.glob("config/locales/**/*.yml")
12
+ sh "yaml-sort", "--in-place", *Dir.glob("config/locales/**/*.yml"), verbose: false
13
13
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yaml
4
4
  module Sort
5
- VERSION = "2.0.0"
5
+ VERSION = "2.1.0"
6
6
  end
7
7
  end
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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Romain Tartière
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-25 00:00:00.000000000 Z
11
+ date: 2022-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cri
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
- rubygems_version: 3.3.10
122
+ rubygems_version: 3.3.16
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Sort lines in YAML files in a predictable order