Class: Vinter::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/vinter/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI



3
4
5
# File 'lib/vinter/cli.rb', line 3

def initialize
  @linter = Linter.new
end

Instance Method Details

#run(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vinter/cli.rb', line 7

def run(args)
  if args.empty?
    puts "Usage: vim9-lint [file.vim]"
    return 1
  end

  file_path = args[0]

  unless File.exist?(file_path)
    puts "Error: File not found: #{file_path}"
    return 1
  end

  content = File.read(file_path)
  issues = @linter.lint(content)

  if issues.empty?
    puts "No issues found in #{file_path}"
    return 0
  else
    puts "Found #{issues.length} issues in #{file_path}:"

    issues.each do |issue|
      type_str = case issue[:type]
                 when :error then "ERROR"
                 when :warning then "WARNING"
                 when :rule then "RULE(#{issue[:rule]})"
                 else "UNKNOWN"
                 end

      line = issue[:line] || 1
      column = issue[:column] || 1

      puts "#{file_path}:#{line}:#{column}: #{type_str}: #{issue[:message]}"
    end

    return issues.any? { |i| i[:type] == :error } ? 1 : 0
  end
end