yaml-janitor 20251114 → 20251115

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: cfafb9059761011d0d8dfc568f4cc5b8b5820b3370389e5d5985a8b7ff6f0d93
4
- data.tar.gz: ffa37dd472c6594455eae81f98559e154308844e3fd3d12fb6ba0ef530ef09b4
3
+ metadata.gz: 9836d954e6602561f6197a639b73183bc96409e93d477191590192d689c669ae
4
+ data.tar.gz: f1f96ba5f15ec13038060a9ebdf6775a939e46d8b5fddaa190c8664e50925cc8
5
5
  SHA512:
6
- metadata.gz: b2906bd8a997aa239635c800fae76d3e255b20d452bcc11350918c1890194280194653a9caf25212f66505c68859162ffc9bfc3940f540b381f81e16a289dc03
7
- data.tar.gz: fe01011a9494bccf085dfdc44f7b0b10c62d2dcfd545287d5382c9aceca7e6af535f6097fea6831cef1d097ba394da6d783acd64aaf5ce9a733c47696a291a11
6
+ metadata.gz: 1a02c1e0afd72eb574dff29f779bd9de9a58a4455fee1be3ceb9e598e958608c3302da92784a1730f08927ef0f1a221f52a72b556d2d8d7e4de970252f9bfbe7
7
+ data.tar.gz: bded6694abd1eb893bcde70ac3144315ececc62a92eb20f7730ec85075b2bb14dd3ad696a32dd431644cb7f0b2fb559dad9e53a21094629352013bc296f029ea
data/README.md CHANGED
@@ -45,6 +45,11 @@ Format with custom indentation:
45
45
  yaml-janitor --fix --indentation 4 config.yml
46
46
  ```
47
47
 
48
+ Show diff of formatting changes:
49
+ ```bash
50
+ yaml-janitor --diff config.yml
51
+ ```
52
+
48
53
  ### Ruby API
49
54
 
50
55
  ```ruby
data/bin/yaml-janitor CHANGED
@@ -11,6 +11,7 @@ def print_usage
11
11
 
12
12
  Options:
13
13
  --fix Format files in-place (without this, just check)
14
+ --diff Show diff of formatting changes
14
15
  --config PATH Path to config file (default: .yaml-janitor.yml)
15
16
  --indentation N Number of spaces for indentation (default: 2)
16
17
  --line-width N Maximum line width (default: 80)
@@ -24,12 +25,16 @@ def print_usage
24
25
  # Format files in-place
25
26
  yaml-janitor --fix config.yml
26
27
  yaml-janitor --fix --indentation 4 containers/
28
+
29
+ # Show diff of formatting changes
30
+ yaml-janitor --diff config.yml
27
31
  USAGE
28
32
  exit 0
29
33
  end
30
34
 
31
35
  # Parse args
32
36
  fix = false
37
+ diff = false
33
38
  config_path = nil
34
39
  config_overrides = {}
35
40
  paths = []
@@ -39,6 +44,8 @@ while i < ARGV.length
39
44
  case ARGV[i]
40
45
  when "--fix"
41
46
  fix = true
47
+ when "--diff"
48
+ diff = true
42
49
  when "--config"
43
50
  i += 1
44
51
  config_path = ARGV[i]
@@ -90,10 +97,14 @@ paths.each do |path|
90
97
  if fix
91
98
  formatted_files << file
92
99
  puts "✓ #{file} (formatted)"
100
+ elsif diff
101
+ puts "✗ #{file}: needs formatting"
102
+ puts linter.generate_diff(result[:original], result[:formatted], file)
103
+ puts ""
93
104
  else
94
105
  puts "✗ #{file}: needs formatting"
95
106
  end
96
- elsif !fix
107
+ elsif !fix && !diff
97
108
  puts "✓ #{file}"
98
109
  end
99
110
  end
@@ -110,10 +121,14 @@ paths.each do |path|
110
121
  if fix
111
122
  formatted_files << path
112
123
  puts "✓ #{path} (formatted)"
124
+ elsif diff
125
+ puts "✗ #{path}: needs formatting"
126
+ puts linter.generate_diff(result[:original], result[:formatted], path)
127
+ puts ""
113
128
  else
114
129
  puts "✗ #{path}: needs formatting"
115
130
  end
116
- elsif !fix
131
+ elsif !fix && !diff
117
132
  puts "✓ #{path}"
118
133
  end
119
134
  else
@@ -52,7 +52,9 @@ module YamlJanitor
52
52
  {
53
53
  violations: violations,
54
54
  fixed: fixed,
55
- output: output
55
+ output: output,
56
+ original: yaml_content,
57
+ formatted: formatted
56
58
  }
57
59
  rescue => e
58
60
  {
@@ -67,6 +69,45 @@ module YamlJanitor
67
69
  }
68
70
  end
69
71
 
72
+ # Generate unified diff between original and formatted content
73
+ def generate_diff(original, formatted, path)
74
+ require 'tempfile'
75
+
76
+ # Write to temp files and use system diff
77
+ Tempfile.create(['original', '.yml']) do |orig_file|
78
+ Tempfile.create(['formatted', '.yml']) do |fmt_file|
79
+ orig_file.write(original)
80
+ orig_file.flush
81
+ fmt_file.write(formatted)
82
+ fmt_file.flush
83
+
84
+ # Use git diff if available (better formatting), fall back to diff
85
+ diff_cmd = if system('which git > /dev/null 2>&1')
86
+ "git diff --no-index --color=always #{orig_file.path} #{fmt_file.path}"
87
+ else
88
+ "diff -u #{orig_file.path} #{fmt_file.path}"
89
+ end
90
+
91
+ diff_output = `#{diff_cmd}`
92
+
93
+ # Replace temp file paths with actual path
94
+ # Git adds a/ and b/ prefixes (or just a/b for temp files)
95
+ orig_path_pattern = Regexp.escape(orig_file.path)
96
+ fmt_path_pattern = Regexp.escape(fmt_file.path)
97
+
98
+ # Handle various git diff formats
99
+ diff_output.gsub(/a\/#{orig_path_pattern}/, path)
100
+ .gsub(/b\/#{fmt_path_pattern}/, "#{path} (formatted)")
101
+ .gsub(/a#{orig_path_pattern}/, path)
102
+ .gsub(/b#{fmt_path_pattern}/, "#{path} (formatted)")
103
+ .gsub(/#{orig_path_pattern}/, path)
104
+ .gsub(/#{fmt_path_pattern}/, "#{path} (formatted)")
105
+ end
106
+ end
107
+ rescue => e
108
+ "Error generating diff: #{e.message}"
109
+ end
110
+
70
111
  private
71
112
 
72
113
  def verify_semantics!(original, fixed)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YamlJanitor
4
- VERSION = "20251114"
4
+ VERSION = "20251115"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-janitor
3
3
  version: !ruby/object:Gem::Version
4
- version: '20251114'
4
+ version: '20251115'
5
5
  platform: ruby
6
6
  authors:
7
7
  - ducks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-11-14 00:00:00.000000000 Z
11
+ date: 2025-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: psych-pure