yaml-sort 2.1.1 → 2.2.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: 813b1d18ae4a2cb6b57ebde8dc720c06ff9125417ab245d6cc15e22467e8f5ef
4
- data.tar.gz: 5d334e4fd7ab15319c225e549a1e7e38319f62a3ecec62a855b40c8e00cba036
3
+ metadata.gz: 6c27eb85cd2257c1d9ae801f0de2bcf360f4980e40479599745ecea41f4aa1f0
4
+ data.tar.gz: 05a1eb6551c2c671ca4e1ff01ce6acd91f3954fd7eeb8b70238bb48df45c1365
5
5
  SHA512:
6
- metadata.gz: 84b534524792c4218449a7724e1673d09058afb2b2c838001e2092e144d8caaeadf51ea5cf415d52a6f5b1ca284ac3977785871344e317d0c61a0414b715d2d8
7
- data.tar.gz: 211409b7ade1b5cace67a86ea71a3fe952398a03165a099a201760ad47e3a01a2da99e7ecd359bc80f63d988396b63afc7a42141899f7ef316ac1dd0aa2c1e5a
6
+ metadata.gz: 28b1e39e69330c1d4f4f68884fb84a8ba8dcc5411315a4b37e51391a4f32b1495fbb2f90eeaa78fea283e1c1ed06f0d030f35c9642de578e4e2665d76546a8ed
7
+ data.tar.gz: '0218e2f44f0a27dc1d5ca720493be401f2e9e55276b4de733ca37f716e9b92cc1c963a0c716c34f219fe3efc6704e21df570564f356394253bc790ecc7c9644f'
data/.simplecov ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # vim:set syntax=ruby:
4
+
5
+ SimpleCov.start do
6
+ add_filter "/spec/"
7
+ end
data/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@ 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
+ ## [v2.2.0](https://github.com/smortex/yaml-sort/tree/v2.2.0) (2022-09-27)
7
+
8
+ [Full Changelog](https://github.com/smortex/yaml-sort/compare/v2.1.1...v2.2.0)
9
+
10
+ **Implemented enhancements:**
11
+
12
+ - Add support for &anchor / \*alias [\#17](https://github.com/smortex/yaml-sort/pull/17) ([smortex](https://github.com/smortex))
13
+
14
+ **Fixed bugs:**
15
+
16
+ - Fix relocation of comments following UNINDENT [\#18](https://github.com/smortex/yaml-sort/pull/18) ([smortex](https://github.com/smortex))
17
+
18
+ **Merged pull requests:**
19
+
20
+ - Add CodeClimate integration [\#15](https://github.com/smortex/yaml-sort/pull/15) ([smortex](https://github.com/smortex))
21
+
6
22
  ## [v2.1.1](https://github.com/smortex/yaml-sort/tree/v2.1.1) (2022-07-03)
7
23
 
8
24
  [Full Changelog](https://github.com/smortex/yaml-sort/compare/v2.1.0...v2.1.1)
data/Gemfile CHANGED
@@ -12,3 +12,4 @@ gem "rspec", "~> 3.0"
12
12
  gem "rubocop", "~> 1.21"
13
13
  gem "rubocop-rake"
14
14
  gem "rubocop-rspec"
15
+ gem "simplecov"
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # yaml-sort
2
2
 
3
+ [![CI](https://github.com/smortex/yaml-sort/actions/workflows/ci.yaml/badge.svg)](https://github.com/smortex/yaml-sort/actions/workflows/ci.yaml)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/4df28a3babe44d1a83c0/maintainability)](https://codeclimate.com/github/smortex/yaml-sort/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/4df28a3babe44d1a83c0/test_coverage)](https://codeclimate.com/github/smortex/yaml-sort/test_coverage)
6
+
3
7
  An utility to manage YAML files and ensure their lines is in a predictable order.
4
8
 
5
9
  This is mainly indended to manage [Hiera files](https://puppet.com/docs/puppet/7/hiera_intro.html) for [Puppet](https://puppet.com/) and translation files in [Ruby on Rails](https://rubyonrails.org/) applications.
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ require "cucumber/rake/task"
13
13
 
14
14
  Cucumber::Rake::Task.new
15
15
 
16
- task default: %i[rubocop spec cucumber]
16
+ task default: %i[spec cucumber]
17
17
 
18
18
  file "lib/yaml/sort/parser.rb": ["lib/yaml/sort/parser.ra"] do
19
19
  sh "racc --output-status --output-file=lib/yaml/sort/parser.rb lib/yaml/sort/parser.ra"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yaml
4
+ module Sort
5
+ class Alias < Value
6
+ attr_reader :name
7
+
8
+ def initialize(anchors, name)
9
+ super()
10
+ @anchors = anchors
11
+ @name = name[:value]
12
+ end
13
+
14
+ def value?
15
+ @anchors[@name]
16
+ end
17
+
18
+ def delete_value
19
+ @anchors.delete(@name)
20
+ end
21
+
22
+ def to_s(*)
23
+ if (s = @anchors.delete(@name))
24
+ separator = case s
25
+ when List, Dictionary then "\n"
26
+ else " "
27
+ end
28
+ "&#{name}#{separator}#{s}"
29
+ else
30
+ "*#{name}"
31
+ end
32
+ end
33
+
34
+ def <=>(_other)
35
+ 0
36
+ end
37
+ end
38
+ end
39
+ end
@@ -25,10 +25,9 @@ module Yaml
25
25
  super + items.map do |k, v|
26
26
  n += 1
27
27
  case v
28
- when List, Dictionary
29
- "#{k.to_s(skip_first_indent: skip_first_indent && n.zero?)}\n#{v}"
30
- when Scalar
31
- "#{k.to_s(skip_first_indent: skip_first_indent && n.zero?)} #{v}"
28
+ when List, Dictionary then "#{k.to_s(skip_first_indent: skip_first_indent && n.zero?)}\n#{v}"
29
+ when Scalar, Alias then "#{k.to_s(skip_first_indent: skip_first_indent && n.zero?)} #{v}"
30
+ else raise "Unexpected type"
32
31
  end
33
32
  end.join("\n")
34
33
  end
@@ -111,7 +111,7 @@ def scan(text)
111
111
  @tokens.each do |token|
112
112
  if token[0] == :COMMENT
113
113
  comment << token[1][:value] + "\n"
114
- elsif comment.any?
114
+ elsif comment.any? && token[0] != :UNINDENT
115
115
  token[1][:comment] = comment
116
116
  comment = []
117
117
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yaml
4
4
  module Sort
5
- VERSION = "2.1.1"
5
+ VERSION = "2.2.0"
6
6
  end
7
7
  end
data/lib/yaml/sort.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "sort/parser"
4
4
  require_relative "sort/value"
5
+ require_relative "sort/alias"
5
6
  require_relative "sort/dictionary"
6
7
  require_relative "sort/item"
7
8
  require_relative "sort/list"
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.1.1
4
+ version: 2.2.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-07-03 00:00:00.000000000 Z
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cri
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".rspec"
78
78
  - ".rubocop.yml"
79
+ - ".simplecov"
79
80
  - CHANGELOG.md
80
81
  - CODE_OF_CONDUCT.md
81
82
  - Gemfile
@@ -84,6 +85,7 @@ files:
84
85
  - Rakefile
85
86
  - exe/yaml-sort
86
87
  - lib/yaml/sort.rb
88
+ - lib/yaml/sort/alias.rb
87
89
  - lib/yaml/sort/cli.rb
88
90
  - lib/yaml/sort/dictionary.rb
89
91
  - lib/yaml/sort/item.rb
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  - !ruby/object:Gem::Version
120
122
  version: '0'
121
123
  requirements: []
122
- rubygems_version: 3.3.16
124
+ rubygems_version: 3.3.22
123
125
  signing_key:
124
126
  specification_version: 4
125
127
  summary: Sort lines in YAML files in a predictable order