Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perl-Critic is a Perl source code analyzer. The command contained in this commit checks the current file with this tool. It opens a new HTML output window containing clickable references to the problems found by `perlcritic`.
- Loading branch information
1 parent
86743ff
commit 5c1901e
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>beforeRunningCommand</key> | ||
<string>saveActiveFile</string> | ||
<key>command</key> | ||
<string>#!/usr/bin/ruby | ||
# -- Imports ------------------------------------------------------------------- | ||
require ENV['TM_BUNDLE_SUPPORT'] + '/perlcritic.rb' | ||
# -- Main ---------------------------------------------------------------------- | ||
perl_critic</string> | ||
<key>input</key> | ||
<string>none</string> | ||
<key>inputFormat</key> | ||
<string>text</string> | ||
<key>keyEquivalent</key> | ||
<string>~@c</string> | ||
<key>name</key> | ||
<string>Check With Perl-Critic</string> | ||
<key>outputCaret</key> | ||
<string>afterOutput</string> | ||
<key>outputFormat</key> | ||
<string>html</string> | ||
<key>outputLocation</key> | ||
<string>newWindow</string> | ||
<key>requiredCommands</key> | ||
<array> | ||
<dict> | ||
<key>command</key> | ||
<string>perlcritic</string> | ||
<key>locations</key> | ||
<array> | ||
<string>/usr/local/bin/perlcritic</string> | ||
</array> | ||
<key>variable</key> | ||
<string>TM_PERLCRITIC</string> | ||
</dict> | ||
</array> | ||
<key>scope</key> | ||
<string>source.perl</string> | ||
<key>uuid</key> | ||
<string>3F862332-074A-447B-AF5B-00D54FAA50F7</string> | ||
<key>version</key> | ||
<integer>2</integer> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# rubocop:disable Style/AsciiComments, Style/HashSyntax | ||
|
||
# Analyze the current file with Perl-Critic. | ||
# | ||
# Authors:: Guillaume Carbonneau | ||
# Matt Foster | ||
# René Schwaiger (sanssecours@f-m.fm) | ||
|
||
# -- Imports ------------------------------------------------------------------- | ||
|
||
require ENV['TM_SUPPORT_PATH'] + '/lib/escape' | ||
require ENV['TM_SUPPORT_PATH'] + '/lib/tm/executor' | ||
|
||
# -- Functions ----------------------------------------------------------------- | ||
|
||
# Format a single line of output from +perlcritic+. | ||
# | ||
# = Arguments | ||
# | ||
# [line] A single line of output produced by +perlcritic+ | ||
# [show_reference] A boolean value that specifies if the output should include | ||
# references to the matching section of the book “Perl Best | ||
# Practices” (PBP). | ||
# | ||
# = Output | ||
# | ||
# The function returns a string containing HTML code. | ||
def format_critic_output(line, show_reference) | ||
return 'No problems found — Yay!' if line.chomp.end_with?('source OK') | ||
styles = { 5 => 'Red', 4 => 'GoldenRod', 3 => 'DodgerBlue' } | ||
styles.default = '' | ||
file, line_number, column, message, reference, severity = line.split(':') | ||
link = "txmt://open?url=file://#{e_url file}&line=#{line_number}" \ | ||
"&column=#{column}" | ||
"<span class='out' style='color:#{styles[severity.to_i]};'> | ||
(Severity: #{severity.to_i})</span> #{message} | ||
<a href='#{link}'>at line #{line_number}, column #{column}</a>. | ||
#{reference + '.' if show_reference}<br />" | ||
end | ||
|
||
# Output an HMTL formatted analysis of the current Perl file by +perlcritic+. | ||
def perl_critic | ||
show_reference = ENV['TM_PERLCRITIC_REFERENCE'] ? true : false | ||
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 => 'Criticizing') do |line, type| | ||
case type | ||
when :err then "<span class='err'>#{htmlize(line)}</span>" | ||
when :out then format_critic_output(line, show_reference) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters