module Golint

Constants

REGEXP
VERSION

Public Class Methods

lint(content) click to toggle source
# File lib/golint.rb, line 13
def lint(content)
  code = Base64.encode64(content).strip[0..16]
  file = Tempfile.new(code)
  file.write(content)
  file.close

  stdin, stdout, stderr, wait_thr = Open3.popen3('golint', file.path)

  out = stdout.read
  err = stderr.read

  if err.size > 0
    parse_matches(file.path, err)
  elsif out.size > 0
    parse_matches(file.path, out)
  else
    []
  end
end
parse_matches(path, body) click to toggle source
# File lib/golint.rb, line 33
def parse_matches(path, body)
  pattern = "#{path}:"
  matches = []
  body.each_line do |line|
    line = line.sub(pattern, "").sub("\n", "")

    res = line.match(REGEXP)
    matches << Match.new(res[1].to_i, res[3].strip)
  end

  matches
end