From 9833b00c609efc926b4e32ca1a97f52baf48e420 Mon Sep 17 00:00:00 2001 From: Eric Harmon Date: Thu, 31 May 2012 04:23:04 -0400 Subject: [PATCH 1/3] Add warnings support to perl checker --- syntax_checkers/efm_perl.pl | 53 +++++++++++++++++++++++++++---------- syntax_checkers/perl.vim | 5 ++-- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/syntax_checkers/efm_perl.pl b/syntax_checkers/efm_perl.pl index 570d6e76..4b7be1c4 100644 --- a/syntax_checkers/efm_perl.pl +++ b/syntax_checkers/efm_perl.pl @@ -4,6 +4,7 @@ # with the quickfix mode of Vim # # Copyright (©) 2001 by Jörg Ziefle +# Copyright (c) 2012 Eric Harmon # You may use and distribute this software under the same terms as Perl itself. # # Usage: put one of the two configurations below in your ~/.vimrc (without the @@ -13,25 +14,27 @@ # Program is run interactively with 'perl -w': # # set makeprg=$HOME/bin/vimparse.pl\ %\ $* -# set errorformat=%f:%l:%m +# set errorformat=%t:%f:%l:%m # # Program is only compiled with 'perl -wc': # # set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $* -# set errorformat=%f:%l:%m +# set errorformat=%t:%f:%l:%m # # Usage: -# vimparse.pl [-c] [-f ] [programargs] +# vimparse.pl [-c] [-w] [-f ] [programargs] # # -c compile only, don't run (perl -wc) +# -w output warnings as warnings instead of errors (slightly slower) # -f write errors to # # Example usages: # * From the command line: # vimparse.pl program.pl # -# vimparse.pl -c -f errorfile program.pl +# vimparse.pl -c -w -f errorfile program.pl # Then run vim -q errorfile to edit the errors with Vim. +# This uses the custom errorformat: %t:%f:%l:%m. # # * From Vim: # Edit in Vim (and save, if you don't have autowrite on), then @@ -39,6 +42,9 @@ # to error check. # # Version history: +# 0.3 (05/31/2012): +# * Added support for the seperate display of warnings +# * Switched output format to %t:%f:%l:%m to support error levels # 0.2 (04/12/2001): # * First public version (sent to Bram) # * -c command line option for compiling only @@ -64,11 +70,11 @@ use strict; use Getopt::Std; -use vars qw/$opt_c $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars' +use vars qw/$opt_c $opt_w $opt_f $opt_h/; # needed for Getopt in combination with use strict 'vars' use constant VERSION => 0.2; -getopts('cf:h'); +getopts('cwf:h'); &usage if $opt_h; # not necessarily needed, but good for further extension @@ -86,20 +92,37 @@ my $handle = (defined $opt_f ? \*FILE : \*STDOUT); (my $file = shift) or &usage; # display usage if no filename is supplied my $args = (@ARGV ? ' ' . join ' ', @ARGV : ''); -my @lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`; +my @error_lines = `perl @{[defined $opt_c ? '-c ' : '' ]} @{[defined $opt_w ? '-X ' : '-w ']} "$file$args" 2>&1`; + +my @lines = map { "E:$_" } @error_lines; + +my @warn_lines; +if(defined($opt_w)) { + @warn_lines = `perl @{[defined $opt_c ? '-c ' : '' ]} -w "$file$args" 2>&1`; +} + +# Any new errors must be warnings +foreach my $line (@warn_lines) { + if(!grep { $_ eq $line } @error_lines) { + push(@lines, "W:$line"); + } +} + +# Clever trick, doesn't work due to scoping of $_ +#@lines = (@lines, map { "W:$_" if !grep( $_, @error_lines) } @warn_lines); my $errors = 0; foreach my $line (@lines) { chomp($line); - my ($file, $lineno, $message, $rest); + my ($file, $lineno, $message, $rest, $severity); - if ($line =~ /^(.*)\sat\s(.*)\sline\s(\d+)(\.|,\snear\s\".*\")$/) { + if ($line =~ /^([EW]):(.*)\sat\s(.*)\sline\s(\d+)(\.|,\snear\s\".*\")$/) { - ($message, $file, $lineno, $rest) = ($1, $2, $3, $4); + ($severity, $message, $file, $lineno, $rest) = ($1, $2, $3, $4, $5); $errors++; $message .= $rest if ($rest =~ s/^,//); - print $handle "$file:$lineno:$message\n"; + print $handle "$severity:$file:$lineno:$message\n"; } else { next }; @@ -129,9 +152,10 @@ sub usage { (local $0 = $0) =~ s/^.*\/([^\/]+)$/$1/; # remove path from name of program print<] [programargs] + $0 [-c] [-w] [-f ] [programargs] - -c compile only, don't run (executes 'perl -wc') + -c compile only, don't run (executes 'perl -c') + -w output warnings as warnings instead of errors (slightly slower) -f write errors to Examples: @@ -139,8 +163,9 @@ Examples: $0 program.pl Displays output on STDOUT. - $0 -c -f errorfile program.pl + $0 -c -w -f errorfile program.pl Then run 'vim -q errorfile' to edit the errors with Vim. + This uses the custom errorformat: %t:%f:%l:%m. * In Vim: Edit in Vim (and save, if you don't have autowrite on), then diff --git a/syntax_checkers/perl.vim b/syntax_checkers/perl.vim index e8aa5777..8927674b 100644 --- a/syntax_checkers/perl.vim +++ b/syntax_checkers/perl.vim @@ -19,11 +19,12 @@ if !executable("perl") finish endif -let s:checker = 'perl ' . shellescape(expand(':p:h') . '/efm_perl.pl') . ' -c' +"remove '-w' switch to change all warnings to errors +let s:checker = 'perl ' . shellescape(expand(':p:h') . '/efm_perl.pl') . ' -c -w' function! SyntaxCheckers_perl_GetLocList() let makeprg = s:checker . ' ' . shellescape(expand('%')) - let errorformat = '%f:%l:%m' + let errorformat = '%t:%f:%l:%m' return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) endfunction From 979258dbbe65c87927a8d0db96ef86f7dc67bc2d Mon Sep 17 00:00:00 2001 From: Eric Harmon Date: Thu, 31 May 2012 04:26:08 -0400 Subject: [PATCH 2/3] Make sure we add some contact info --- syntax_checkers/efm_perl.pl | 2 +- syntax_checkers/perl.vim | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax_checkers/efm_perl.pl b/syntax_checkers/efm_perl.pl index 4b7be1c4..b2cee65e 100644 --- a/syntax_checkers/efm_perl.pl +++ b/syntax_checkers/efm_perl.pl @@ -4,7 +4,7 @@ # with the quickfix mode of Vim # # Copyright (©) 2001 by Jörg Ziefle -# Copyright (c) 2012 Eric Harmon +# Copyright (c) 2012 Eric Harmon # You may use and distribute this software under the same terms as Perl itself. # # Usage: put one of the two configurations below in your ~/.vimrc (without the diff --git a/syntax_checkers/perl.vim b/syntax_checkers/perl.vim index 8927674b..1d48f61c 100644 --- a/syntax_checkers/perl.vim +++ b/syntax_checkers/perl.vim @@ -1,7 +1,8 @@ "============================================================================ "File: perl.vim "Description: Syntax checking plugin for syntastic.vim -"Maintainer: Anthony Carapetis +"Maintainer: Anthony Carapetis , +" Eric Harmon "License: This program is free software. It comes without any warranty, " to the extent permitted by applicable law. You can redistribute " it and/or modify it under the terms of the Do What The Fuck You From 5c4697acdd012a47868a5ff97260dab7e0bed68d Mon Sep 17 00:00:00 2001 From: Eric Harmon Date: Thu, 31 May 2012 04:35:53 -0400 Subject: [PATCH 3/3] Remove some working notes --- syntax_checkers/efm_perl.pl | 3 --- 1 file changed, 3 deletions(-) diff --git a/syntax_checkers/efm_perl.pl b/syntax_checkers/efm_perl.pl index b2cee65e..27b7c296 100644 --- a/syntax_checkers/efm_perl.pl +++ b/syntax_checkers/efm_perl.pl @@ -108,9 +108,6 @@ foreach my $line (@warn_lines) { } } -# Clever trick, doesn't work due to scoping of $_ -#@lines = (@lines, map { "W:$_" if !grep( $_, @error_lines) } @warn_lines); - my $errors = 0; foreach my $line (@lines) {