diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2007-04-25 15:16:22 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2007-04-25 15:16:22 +0000 |
commit | f37d7371879e2b1e2d923ec12762430b3d1937fc (patch) | |
tree | 28155bfc9dca9815ac7e8c7599130a15b1d2cb1b /src/perl_checker.html.pl | |
parent | be4fff49f0164e606d4b2f76f64d4d108895f236 (diff) | |
download | perl_checker-f37d7371879e2b1e2d923ec12762430b3d1937fc.tar perl_checker-f37d7371879e2b1e2d923ec12762430b3d1937fc.tar.gz perl_checker-f37d7371879e2b1e2d923ec12762430b3d1937fc.tar.bz2 perl_checker-f37d7371879e2b1e2d923ec12762430b3d1937fc.tar.xz perl_checker-f37d7371879e2b1e2d923ec12762430b3d1937fc.zip |
Diffstat (limited to 'src/perl_checker.html.pl')
-rw-r--r-- | src/perl_checker.html.pl | 112 |
1 files changed, 87 insertions, 25 deletions
diff --git a/src/perl_checker.html.pl b/src/perl_checker.html.pl index e90d2eb..38ec959 100644 --- a/src/perl_checker.html.pl +++ b/src/perl_checker.html.pl @@ -1,5 +1,42 @@ $s = <<'EOF'; -<head><title>perl_checker</title></head> +<head> + <title>perl_checker</title> + <style> body { max-width: 900; } </style> +</head> + + +<h1>Quick Start</h1> + +To use perl_checker, simply use "perl_checker a_file.pl" +<p> +To use under emacs, simply add the following line to your .emacs, +then when you visit a perl file, you can use Ctrl-Return to run perl_checker +on this file + +<pre> + (global-set-key [(control return)] (lambda () (interactive) (save-some-buffers 1) (compile (concat "perl_checker --restrict-to-files " (buffer-file-name (current-buffer)))))) +</pre> + +<p> +To use with vim, use something like: +<pre> + perl_checker --restrict-to-files scanner.pm > errors.err ; vim -c ':copen 4' -c ':so /usr/share/vim/ftplugin/perl_checker.vim' -q +</pre> +where /usr/share/vim/ftplugin/perl_checker.vim is + +<pre> +" Error formats +setlocal efm= + \%EFile\ \"%f\"\\,\ line\ %l\\,\ characters\ %c-%*\\d:, + \%EFile\ \"%f\"\\,\ line\ %l\\,\ character\ %c:%m, + \%+EReference\ to\ unbound\ regexp\ name\ %m, + \%Eocamlyacc:\ e\ -\ line\ %l\ of\ \"%f\"\\,\ %m, + \%Wocamlyacc:\ w\ -\ %m, + \%-Zmake%.%#, + \%C%m +</pre> + + <h1>Goals of perl_checker</h1> <ul> @@ -23,12 +60,21 @@ $s = <<'EOF'; (NB: the subset is chosen to keep a good expressivity) </ul> -<h1>Compared to <a href="http://perlcritic.tigris.org/">Perl-Critic</a> +<h1>Compared to <a href="http://www.perl.com/pub/a/2005/06/09/ppi.html">PPI</a> and <a href="http://perlcritic.tigris.org/">Perl-Critic</a></h1> <ul> -<li>perl_checker use its own OCaml-written perl parser, which is in no way as robust as <a href="http://www.perl.com/pub/a/2005/06/09/ppi.html">PPI</a>. - A PPI require is to be able to parse non finished perl documents. - perl_checker is a checker, and it is not a big deal to die horribly on a weird perl expression, telling the programmer what to write instead. +<li>perl_checker use its own OCaml-written parser. + This parser only handle a subset of perl, + whereas one of PPI's goal is to be able to parse non finished perl documents. + <p>perl_checker is a checker: it is not a big deal to die horribly on a weird perl expression, it tells the programmer what to write instead. + The issue is that perl_checker includes inter-modules analysis, and it implies being able to parse non-perl_checker compliant modules. + A solution for this is perl_checker <i>fake</i> modules. No perfect solution though. + +<li>PPI doesn't handle operator priorities: <tt>1 + 2 << 3</tt> is parsed as + <ul><li>PPI: a list [ Number(<tt>1</tt>), Operator(<tt>+</tt>), Number(<tt>2</tt>), Operator(<tt><<</tt>), Number(<tt>3</tt>) ] + <li>perl_checker: a tree Operator(<tt><<</tt>, [ Operator(<tt>+</tt>, [ Number(<tt>1</tt>), Number(<tt>2</tt>) ]), Number(<tt>3</tt>) ]) + </ul> + This limits perlcritic checks to a syntax level. <li>perl_checker is <b>much</b> faster (more than 100 times) (ML pattern matching rulez) @@ -39,24 +85,33 @@ $s = <<'EOF'; <h1>Get it</h1> -<a href="http://cvs.mandriva.com/cgi-bin/cvsweb.cgi/soft/perl-MDK-Common/perl_checker.src/">CVS source</a> +<a href="http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages/cooker/perl_checker/current/SOURCES/">tarball</a> +<br> +<a href="http://svn.mandriva.com/cgi-bin/viewvc.cgi/soft/perl_checker/">SVN source</a> +<br> +<a href="http://svn.mandriva.com/cgi-bin/viewvc.cgi/packages/cooker/perl-MDK-Common/current/SOURCES/">MDK::Common tarball</a> <h1>Implemented features</h1> <dl> - <dt>white space normalization - <dd>enforce a similar coding style. In many languages you can find a coding - style document (eg: <a href="http://www.gnu.org/prep/standards_23.html">the GNU one</a>). - TESTS=force_layout.t + <dt>detect some Perl traps + <dd>some Perl expressions are stupid, and one gets a warning when running + them with <tt>perl -w</tt>. The drawback of <tt>perl -w</tt> is the lack of + code coverage, it only detects expressions which are evaluated. + + TESTS=various_errors.t </dd> - <dt>disallow <i>complex</i> expressions - <dd>perl_checker try to ban some weird-not-used-a-lot features. - TESTS=syntax_restrictions.t + <dt>context checks + <dd>Perl has types associated with variables names, the so-called "context". + Some expressions mixing contexts are stupid, perl_checker detects them. + + TESTS=context.t </dd> + <dt>suggest simpler expressions <dd>when there is a simpler way to write an expression, suggest it. It can also help detecting errors. @@ -64,13 +119,7 @@ $s = <<'EOF'; TESTS=suggest_better.t </dd> - <dt>context checks - <dd>Perl has types associated with variables names, the so-called "context". - Some expressions mixing contexts are stupid, perl_checker detects them. - TESTS=context.t - - </dd> <dt>function call check <dd>detection of unknown functions or mismatching prototypes (warning: since perl is a dynamic language, some spurious warnings may occur when a function @@ -79,6 +128,7 @@ $s = <<'EOF'; TESTS=prototype.t </dd> + <dt>method call check <dd>detection of unknown methods or mismatching prototypes. perl_checker doesn't have any idea what the object type is, it simply checks if a method @@ -87,19 +137,31 @@ $s = <<'EOF'; TESTS=method.t </dd> + <dt>return value check <dd>dropping the result of a functionnally <i>pure</i> function is stupid. using the result of a function returning void is stupid too. + <br>(nb: perl_checker enforces <tt>&&</tt> and <tt>||</tt> are used as boolean operators + whereas <tt>and</tt> and <tt>or</tt> are used for control flow) TESTS=return_value.t </dd> - <dt>detect some Perl traps - <dd>some Perl expressions are stupid, and one gets a warning when running - them with <tt>perl -w</tt>. The drawback are <tt>perl -w</tt> is the lack of - code coverage, it only detects expressions which are evaluated. - TESTS=various_errors.t + <dt>white space normalization + <dd>enforce a similar coding style. In many languages you can find a coding + style document (eg: <a href="http://www.gnu.org/prep/standards/standards.html#Writing-C">the GNU one</a>). + + TESTS=force_layout.t + + </dd> + + <dt>disallow <i>complex</i> expressions + <dd>perl_checker try to ban some weird-not-used-a-lot features. + + TESTS=syntax_restrictions.t + + </dd> </dl> @@ -136,7 +198,7 @@ sub get_example { join('', map { my $lines = join("<br>", map { "<tt>" . html_quote($_) . "</tt>" } @{$_->{lines}}); my $logs = join("<br>", map { html_quote($_) } @{$_->{logs}}); - " <tr><td>\n", $lines, "</td><td>", $logs, "</td></tr>\n"; + $logs ? " <tr><td>\n" . $lines . "</td><td>" . $logs . "</td></tr>\n" : ''; } @tests) . "</table></a>\n"; } |