ruby-progress 1.0.1 → 1.1.2

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.
data/Rakefile CHANGED
@@ -9,6 +9,9 @@ RuboCop::RakeTask.new
9
9
 
10
10
  task default: %i[spec rubocop]
11
11
 
12
+ # Used by markdown tasks
13
+ MARKDOWN_GLOB = ['**/*.md'].freeze
14
+
12
15
  # Version management tasks
13
16
  desc 'Show current version'
14
17
  task :version do
@@ -31,6 +34,7 @@ task :bump_major do
31
34
  bump_version(:major)
32
35
  end
33
36
 
37
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
34
38
  def bump_version(type)
35
39
  require_relative 'lib/ruby-progress/version'
36
40
  version_parts = RubyProgress::VERSION.split('.').map(&:to_i)
@@ -57,6 +61,7 @@ def bump_version(type)
57
61
 
58
62
  puts "Version bumped from #{RubyProgress::VERSION} to #{new_version}"
59
63
  end
64
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
60
65
 
61
66
  # Package management
62
67
  desc 'Clean up generated files'
@@ -82,3 +87,119 @@ task :test_binaries do
82
87
  system('worm --version') || abort('worm binary test failed')
83
88
  puts 'Binary tests passed!'
84
89
  end
90
+
91
+ # Markdown lint/fix tasks (no external deps)
92
+ # rubocop:disable Metrics/BlockLength
93
+ namespace :markdown do
94
+ def markdown_files
95
+ Dir.glob(MARKDOWN_GLOB).reject do |p|
96
+ p.start_with?('pkg/') || p.start_with?('coverage/') || p.start_with?('node_modules/')
97
+ end
98
+ end
99
+
100
+ def list_item?(line)
101
+ !!(line =~ /^\s*([-*+]\s+|\d+\.\s+)/)
102
+ end
103
+
104
+ def fence_delimiter?(line)
105
+ !!(line =~ /^\s*```|^\s*~~~/)
106
+ end
107
+
108
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
109
+ def format_markdown(content)
110
+ lines = content.split("\n", -1)
111
+ out = []
112
+ in_fence = false
113
+ i = 0
114
+ while i < lines.length
115
+ line = lines[i]
116
+
117
+ if fence_delimiter?(line)
118
+ in_fence = !in_fence
119
+ out << line
120
+ i += 1
121
+ next
122
+ end
123
+
124
+ if in_fence
125
+ out << line
126
+ i += 1
127
+ next
128
+ end
129
+
130
+ # Collapse multiple blank lines
131
+ if line.strip.empty?
132
+ prev = out.last
133
+ out << '' if prev && !prev.strip.empty?
134
+ i += 1
135
+ next
136
+ end
137
+
138
+ # Ensure blank line after headings
139
+ if line =~ /^\s*#+\s+/
140
+ out << line
141
+ nxt = lines[i + 1]
142
+ out << '' if nxt && !nxt.strip.empty? && !fence_delimiter?(nxt)
143
+ i += 1
144
+ next
145
+ end
146
+
147
+ # Ensure blank line before and after list blocks
148
+ if list_item?(line)
149
+ prev = out.last
150
+ out << '' unless prev.nil? || prev.strip.empty? || list_item?(prev)
151
+ while i < lines.length && list_item?(lines[i])
152
+ out << lines[i]
153
+ i += 1
154
+ end
155
+ after = lines[i]
156
+ out << '' if after && !after.strip.empty? && !fence_delimiter?(after)
157
+ next
158
+ end
159
+
160
+ out << line
161
+ i += 1
162
+ end
163
+
164
+ out << '' if (last = out.last) && !last.empty?
165
+ out.join("\n")
166
+ end
167
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
168
+
169
+ desc 'Lint markdown (reports files that would be changed)'
170
+ task :lint do
171
+ changed = []
172
+ markdown_files.each do |path|
173
+ original = File.read(path)
174
+ formatted = format_markdown(original)
175
+ changed << path if formatted != original
176
+ end
177
+ if changed.empty?
178
+ puts 'Markdown: no issues found.'
179
+ else
180
+ puts 'Markdown files needing formatting:'
181
+ changed.each { |p| puts " - #{p}" }
182
+ abort 'Run: rake markdown:fix'
183
+ end
184
+ end
185
+
186
+ desc 'Auto-fix markdown spacing (headings, lists, blank lines)'
187
+ task :fix do
188
+ updated = []
189
+ markdown_files.each do |path|
190
+ original = File.read(path)
191
+ formatted = format_markdown(original)
192
+ next if formatted == original
193
+
194
+ File.write(path, formatted)
195
+ updated << path
196
+ end
197
+ if updated.empty?
198
+ puts 'Markdown: nothing to fix.'
199
+ else
200
+ puts 'Markdown updated:'
201
+ updated.each { |p| puts " - #{p}" }
202
+ end
203
+ end
204
+ end
205
+ # rubocop:enable Metrics/BlockLength