yalphabetize 0.8.0 → 0.10.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: a68ee1b7cf8a1023f292bcc19606f1f1289bc582137c15e43cb3ad56174f96f1
4
- data.tar.gz: 1246d3f96f00238273ef6251ccf9bbeda7316a861ff711f3be476fc94478e449
3
+ metadata.gz: b2b58ea00743bea3a0a4ca4ef92caa428ced099cdf28bf4caa37bf7214333ade
4
+ data.tar.gz: b8c5d394eaf0aef402e4cab38dd1018560950e36488fb60537f9fa48c201985b
5
5
  SHA512:
6
- metadata.gz: '096bd5b4e436edccbf2fa86c48e1bc1551d0b516ca9fadda7ea8df14ac8db167b985762052701d3a12bcc03c72eb92badd1a6ed3c0d1b4baf5a3c3d0accdcf13'
7
- data.tar.gz: 72b0be00b049d29fb7c322c421ed96f804f7db4f69090711d2fee32af5c0ca32ffeb8173ced531a6e9bcdd0a6b8409f9a0e47c15d15bcdf5ce04bfb1a4effbbd
6
+ metadata.gz: 54d23c05ae16c9eaa72b1f14a817618dbee8e116a0b24d46f08bbfc7ea009ad449e784f8ad07d24f159446deed6382bb7f403393ca45287d16ce740f3ec157b4
7
+ data.tar.gz: 731ca71c870831cd1d5b848f46a7d9e93c924d4e76304624762f7ff28c03e1d4eb4144e647ce059d3ce3315c3a48b29553d6e349f150be9777e6f2e4d41471af
@@ -33,11 +33,11 @@ module Yalphabetize
33
33
  end
34
34
 
35
35
  def offences?
36
- offence_detector_class.new(stream_node, order_checker_class: order_checker_class).offences?
36
+ offence_detector_class.new(stream_node, order_checker_class:).offences?
37
37
  end
38
38
 
39
39
  def alphabetize
40
- alphabetizer_class.new(stream_node, order_checker_class: order_checker_class).call
40
+ alphabetizer_class.new(stream_node, order_checker_class:).call
41
41
  end
42
42
 
43
43
  def handle_aliases
@@ -30,13 +30,13 @@ module Yalphabetize
30
30
  output.puts send(list_offences_color, "Offences: #{offences.size}")
31
31
 
32
32
  offences.each { |file_path, status| puts_offence(file_path, status) }
33
- return unless offences?
33
+ return unless uncorrected_offences?
34
34
 
35
35
  output.puts 'Offences can be automatically fixed with `-a` or `--autocorrect`'
36
36
  end
37
37
 
38
- def offences?
39
- @offences.any?
38
+ def uncorrected_offences?
39
+ offences.value?(:detected)
40
40
  end
41
41
 
42
42
  def log_correction(file_path)
@@ -58,7 +58,7 @@ module Yalphabetize
58
58
  end
59
59
 
60
60
  def list_offences_color
61
- offences? ? :red : :green
61
+ offences.any? ? :red : :green
62
62
  end
63
63
 
64
64
  def red(string)
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'psych'
4
+ require 'psych/comments'
4
5
 
5
6
  module Yalphabetize
6
7
  class Reader
@@ -21,7 +22,7 @@ module Yalphabetize
21
22
  end
22
23
 
23
24
  def stream_node
24
- @_stream_node ||= Psych.parse_stream file
25
+ @_stream_node ||= parser_class.parse_stream file
25
26
  rescue Psych::SyntaxError => e
26
27
  raise Yalphabetize::ParsingError.new(
27
28
  path,
@@ -32,5 +33,13 @@ module Yalphabetize
32
33
  e.context
33
34
  )
34
35
  end
36
+
37
+ def parser_class
38
+ if Yalphabetize.config['preserve_comments']
39
+ Psych::Comments
40
+ else
41
+ Psych
42
+ end
43
+ end
35
44
  end
36
45
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Yalphabetize
4
4
  class Version
5
- STRING = '0.8.0'
5
+ STRING = '0.10.0'
6
6
  end
7
7
  end
@@ -20,7 +20,11 @@ module Yalphabetize
20
20
  attr_reader :stream_node, :path
21
21
 
22
22
  def new_file_content
23
- @_new_file_content ||= stream_node.to_yaml(nil, line_width: MAX_LINE_WIDTH)
23
+ @_new_file_content ||= if Yalphabetize.config['preserve_comments']
24
+ Psych::Comments.emit_yaml stream_node
25
+ else
26
+ stream_node.to_yaml(nil, line_width: MAX_LINE_WIDTH)
27
+ end
24
28
  end
25
29
 
26
30
  def indent_sequences
@@ -32,13 +32,13 @@ module Yalphabetize
32
32
  def process_file(file_path)
33
33
  file_yalphabetizer_class.new(
34
34
  file_path,
35
- reader_class: reader_class,
36
- offence_detector_class: offence_detector_class,
37
- logger: logger,
35
+ reader_class:,
36
+ offence_detector_class:,
37
+ logger:,
38
38
  autocorrect: options[:autocorrect],
39
- alphabetizer_class: alphabetizer_class,
40
- writer_class: writer_class,
41
- order_checker_class: order_checker_class
39
+ alphabetizer_class:,
40
+ writer_class:,
41
+ order_checker_class:
42
42
  ).call
43
43
  end
44
44
 
@@ -56,7 +56,7 @@ module Yalphabetize
56
56
 
57
57
  def final_log
58
58
  logger.final_summary
59
- logger.offences? ? 1 : 0
59
+ logger.uncorrected_offences? ? 1 : 0
60
60
  end
61
61
 
62
62
  def reader_class
data/lib/yalphabetize.rb CHANGED
@@ -28,7 +28,8 @@ module Yalphabetize
28
28
  'indent_sequences' => true,
29
29
  'exclude' => [],
30
30
  'only' => [],
31
- 'sort_by' => 'ABab'
31
+ 'sort_by' => 'ABab',
32
+ 'preserve_comments' => true
32
33
  }.freeze
33
34
 
34
35
  def config
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yalphabetize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Jenkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-29 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: psych-comments
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description:
14
28
  email:
15
29
  executables:
@@ -44,7 +58,9 @@ homepage:
44
58
  licenses: []
45
59
  metadata:
46
60
  rubygems_mfa_required: 'true'
47
- post_install_message:
61
+ post_install_message: |
62
+ yalphabetize 0.10.0 now supports YAML comments!
63
+ For more info: https://github.com/samrjenkins/yalphabetize?tab=readme-ov-file#preserve_comments
48
64
  rdoc_options: []
49
65
  require_paths:
50
66
  - lib
@@ -59,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
75
  - !ruby/object:Gem::Version
60
76
  version: '0'
61
77
  requirements: []
62
- rubygems_version: 3.5.3
78
+ rubygems_version: 3.3.27
63
79
  signing_key:
64
80
  specification_version: 4
65
81
  summary: Alphabetize your YAML files