Skip to content

Instantly share code, notes, and snippets.

@mattfoster
Created February 19, 2009 20:16
Show Gist options
  • Save mattfoster/67095 to your computer and use it in GitHub Desktop.
Save mattfoster/67095 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Run Perl::Critic on the current file.
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
def colorize_critic_output(str)
styles = {5 => "Red", 4 => "GoldenRod", 3 => "DodgerBlue" }
styles.default = ""
str.map do |line|
file, line_no, col_no, message, ref, severity = line.split(':')
"&bull; <span class=\"out\" style=\"color:#{styles[severity.to_i]};\";>(Severity: #{severity.to_i})</span> #{message} <a href=\"txmt://open?line=#{line_no}&amp;column=#{col_no}#{file}\">at line #{line_no}, column #{col_no}</a>. #{ref}.<br/>"
end
end
TextMate.save_current_document
TextMate::Executor.run(ENV["TM_PERLCRITIC"] || "perlcritic",
'--verbose', '%f:%l:%c:%m:%e:%s\n',
ENV['TM_PERLCRITIC_LEVEL'] || '--stern',
'--nocolor', ENV["TM_FILEPATH"],
:use_hashbang=>false, :verb => "Criticising") do |str, type|
case type
when :err
# do special transformation of stderr
"<span class=\"err\">#{htmlize(str)}</span>"
when :out
# special transformation of stdout
colorize_critic_output(str)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment