vinter 0.6.2 → 0.6.3

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: e47fb1e67cb9cf9a42ef421129fc7002bcc1471c39e4e62ff3ff78a480498fe6
4
- data.tar.gz: d6b42a562879298291c5e613ef76a6af680f9aaf794152c4ced90aebe37f51a4
3
+ metadata.gz: 24da5c73f3d23b6cf4102c37632877a090534aa5343e99b73aab613aa6e5a860
4
+ data.tar.gz: 7250550dedf15c7fe332ab7a048b833ff93c09bbc48433f50b0845aff7448db1
5
5
  SHA512:
6
- metadata.gz: 62cb9236451e5a58a36115d307b5a98bbd8e0759cb0212b97a53908168b74d4ee04a375798f6b34e3e79625aa1bf22be7cfb3b4c66b9b10fe41cc9bf969d0cea
7
- data.tar.gz: ed8cf7eaccb6e1fc46080b41f66502c375cca18762ea8c38369f71ede1a850c2b843cc9afa1ff32575ec056c2fa38397adee0a6c8f473727fe1a3ec266221e48
6
+ metadata.gz: 26d2eb57e3ee43e442e786e76da8c06729c0f9253deca4ac991582a7595bdfe08580d4d9ac784eefa55d7619392725c5f818612744088fe49a2d87019261f29f
7
+ data.tar.gz: 380639a4f1fff2b3010317d8f1fa392ac6911a5fd3beb827590ce6220320d5c5a77209edce450032751e00030391a35743a6787fc51cb5a21ea1c5f7a70db0db
data/lib/vinter/cli.rb CHANGED
@@ -6,36 +6,116 @@ module Vinter
6
6
 
7
7
  def run(args)
8
8
  if args.empty?
9
- puts "Usage: vinter [file.vim|directory] [--exclude=dir1,dir2]"
9
+ puts "Usage: vinter [file.vim|directory] [--exclude=dir1,dir2] [--stdio]"
10
10
  return 1
11
11
  end
12
12
 
13
13
  # Parse args: first non-option argument is the target path.
14
14
  exclude_value = nil
15
15
  target_path = nil
16
+ stdio = false
17
+ format_value = nil
16
18
 
17
19
  args.each_with_index do |a, i|
18
20
  if a.start_with?("--exclude=")
19
21
  exclude_value = a.split("=", 2)[1]
20
22
  elsif a == "--exclude"
21
23
  exclude_value = args[i + 1]
24
+ elsif a == "--stdio" || a.start_with?("--stdio=")
25
+ stdio = true
26
+ elsif a.start_with?("--format=")
27
+ format_value = a.split("=", 2)[1]
28
+ elsif a == "--format"
29
+ format_value = args[i + 1]
22
30
  elsif !a.start_with?('-') && target_path.nil?
23
31
  target_path = a
24
32
  end
25
33
  end
26
34
 
27
- if target_path.nil?
28
- puts "Usage: vinter [file.vim|directory] [--exclude=dir1,dir2]"
35
+ if target_path.nil? && !stdio
36
+ puts "Usage: vinter [file.vim|directory] [--exclude=dir1,dir2] [--stdio]"
29
37
  return 1
30
38
  end
31
39
 
32
- unless File.exist?(target_path)
33
- puts "Error: File or directory not found: #{target_path}"
34
- return 1
40
+ unless stdio
41
+ unless File.exist?(target_path)
42
+ puts "Error: File or directory not found: #{target_path}"
43
+ return 1
44
+ end
35
45
  end
36
46
 
37
47
  excludes = Array(exclude_value).flat_map { |v| v.to_s.split(',') }.map(&:strip).reject(&:empty?)
38
48
 
49
+ # normalize format value
50
+ format_value = format_value.to_s.downcase if format_value
51
+
52
+ # Handle STDIN input mode
53
+ if stdio
54
+ content = STDIN.read
55
+
56
+ if content.nil? || content.empty?
57
+ puts "No input received on stdin"
58
+ return 0
59
+ end
60
+
61
+ issues = @linter.lint(content)
62
+ total_issues = issues.length
63
+
64
+ if format_value == 'json'
65
+ require 'json'
66
+
67
+ files = [
68
+ {
69
+ path: 'stdin',
70
+ offenses: issues.map do |issue|
71
+ {
72
+ severity: (issue[:type] == :error ? 'fatal' : (issue[:type] == :warning ? 'warning' : 'convention')),
73
+ message: issue[:message],
74
+ cop_name: issue[:rule],
75
+ corrected: false,
76
+ correctable: false,
77
+ location: {
78
+ start_line: issue[:line] || 1,
79
+ start_column: issue[:column] || 1,
80
+ last_line: issue[:line] || 1,
81
+ last_column: issue[:column] || 1,
82
+ length: 0,
83
+ line: issue[:line] || 1,
84
+ column: issue[:column] || 1
85
+ }
86
+ }
87
+ end
88
+ }
89
+ ]
90
+
91
+ metadata = {
92
+ 'rubocop_version' => defined?(Vinter::VERSION) ? Vinter::VERSION : nil,
93
+ 'ruby_engine' => defined?(RUBY_ENGINE) ? RUBY_ENGINE : RUBY_PLATFORM,
94
+ 'ruby_version' => RUBY_VERSION,
95
+ 'ruby_patchlevel' => RUBY_PATCHLEVEL.to_s,
96
+ 'ruby_platform' => RUBY_PLATFORM
97
+ }
98
+
99
+ summary = {
100
+ 'offense_count' => total_issues,
101
+ 'target_file_count' => files.length,
102
+ 'inspected_file_count' => files.length
103
+ }
104
+
105
+ output = { metadata: metadata, files: files, summary: summary }
106
+ options = {
107
+ indent: '',
108
+ space: '',
109
+ space_before: '',
110
+ object_nl: '',
111
+ array_nl: ''
112
+ }
113
+ puts JSON.pretty_generate(output, options)
114
+
115
+ return total_issues > 0 ? 1 : 0
116
+ end
117
+ end
118
+
39
119
  vim_files = if File.directory?(target_path)
40
120
  find_vim_files(target_path, excludes)
41
121
  else
@@ -54,40 +134,95 @@ module Vinter
54
134
 
55
135
  total_issues = 0
56
136
  error_count = 0
137
+ json_files = []
57
138
 
58
139
  vim_files.each do |file_path|
59
140
  content = File.read(file_path)
60
141
  issues = @linter.lint(content)
61
142
  total_issues += issues.length
62
143
 
63
- if issues.empty?
64
- puts "No issues found in #{file_path}" if vim_files.length == 1
144
+ if format_value == 'json'
145
+ json_files << {
146
+ path: file_path,
147
+ offenses: issues.map do |issue|
148
+ {
149
+ severity: (issue[:type] == :error ? 'fatal' : (issue[:type] == :warning ? 'warning' : 'convention')),
150
+ message: issue[:message],
151
+ cop_name: issue[:rule],
152
+ corrected: false,
153
+ correctable: false,
154
+ location: {
155
+ start_line: issue[:line] || 1,
156
+ start_column: issue[:column] || 1,
157
+ last_line: issue[:line] || 1,
158
+ last_column: issue[:column] || 1,
159
+ length: 0,
160
+ line: issue[:line] || 1,
161
+ column: issue[:column] || 1
162
+ }
163
+ }
164
+ end
165
+ }
65
166
  else
66
- puts "Found #{issues.length} issues in #{file_path}:" if vim_files.length > 1
167
+ if issues.empty?
168
+ puts "No issues found in #{file_path}" if vim_files.length == 1
169
+ else
170
+ puts "Found #{issues.length} issues in #{file_path}:" if vim_files.length > 1
67
171
 
68
- issues.each do |issue|
69
- type_str = case issue[:type]
70
- when :error then "ERROR"
71
- when :warning then "WARNING"
72
- when :rule then "RULE(#{issue[:rule]})"
73
- else "UNKNOWN"
74
- end
172
+ issues.each do |issue|
173
+ type_str = case issue[:type]
174
+ when :error then "ERROR"
175
+ when :warning then "WARNING"
176
+ when :rule then "RULE(#{issue[:rule]})"
177
+ else "UNKNOWN"
178
+ end
75
179
 
76
- line = issue[:line] || 1
77
- column = issue[:column] || 1
180
+ line = issue[:line] || 1
181
+ column = issue[:column] || 1
78
182
 
79
- puts "#{file_path}:#{line}:#{column}: #{type_str}: #{issue[:message]}"
80
- end
183
+ puts "#{file_path}:#{line}:#{column}: #{type_str}: #{issue[:message]}"
184
+ end
81
185
 
82
- error_count += 1 if issues.any? { |i| i[:type] == :error }
186
+ error_count += 1 if issues.any? { |i| i[:type] == :error }
187
+ end
83
188
  end
84
189
  end
85
190
 
86
- if vim_files.length > 1
87
- puts "\nProcessed #{vim_files.length} files, found #{total_issues} total issues"
191
+ #if vim_files.length > 1
192
+ #puts "\nProcessed #{vim_files.length} files, found #{total_issues} total issues"
193
+ #end
194
+
195
+ if format_value == 'json'
196
+ require 'json'
197
+
198
+ metadata = {
199
+ 'rubocop_version' => defined?(Vinter::VERSION) ? Vinter::VERSION : nil,
200
+ 'ruby_engine' => defined?(RUBY_ENGINE) ? RUBY_ENGINE : RUBY_PLATFORM,
201
+ 'ruby_version' => RUBY_VERSION,
202
+ 'ruby_patchlevel' => RUBY_PATCHLEVEL.to_s,
203
+ 'ruby_platform' => RUBY_PLATFORM
204
+ }
205
+
206
+ summary = {
207
+ 'offense_count' => total_issues,
208
+ 'target_file_count' => vim_files.length,
209
+ 'inspected_file_count' => vim_files.length
210
+ }
211
+
212
+ output = { metadata: metadata, files: json_files, summary: summary }
213
+ options = {
214
+ indent: '',
215
+ space: '',
216
+ space_before: '',
217
+ object_nl: '',
218
+ array_nl: ''
219
+ }
220
+ puts JSON.pretty_generate(output, options)
221
+
222
+ return total_issues > 0 ? 1 : 0
88
223
  end
89
224
 
90
- return error_count > 0 ? 1 : 0
225
+ return total_issues > 0 ? 1 : 0
91
226
  end
92
227
 
93
228
  private
data/lib/vinter/parser.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  module Vinter
3
2
  class Parser
4
3
  def initialize(tokens, source_text = nil)
data/lib/vinter.rb CHANGED
@@ -5,5 +5,5 @@ require "vinter/cli"
5
5
  require "vinter/ast_printer"
6
6
 
7
7
  module Vinter
8
- VERSION = "0.6.2"
8
+ VERSION = "0.6.3"
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vinter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Bradbury
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-11-30 00:00:00.000000000 Z
11
+ date: 2025-12-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A linter for vim9script
14
14
  email: dan.luckydaisy@gmail.com