[libcode-tidyall-perl] 206/374: add podchecker, jsbeautify, jshint

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:21 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcode-tidyall-perl.

commit 1809594dc5d0ce27b3597eba4f0ad8a852109f08
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Mon Sep 10 04:50:37 2012 -0700

    add podchecker, jsbeautify, jshint
---
 bin/tidyall                           |   31 +++++++++++-----
 lib/Code/TidyAll.pm                   |    6 ++--
 lib/Code/TidyAll/Plugin/JSBeautify.pm |   23 ++++++++----
 lib/Code/TidyAll/Plugin/JSHint.pm     |   63 ++++++++++++++++++++++++++++++---
 lib/Code/TidyAll/Plugin/PerlCritic.pm |   31 +++++++++++++---
 lib/Code/TidyAll/Plugin/PerlTidy.pm   |   29 ++++++++++++---
 lib/Code/TidyAll/Plugin/PodTidy.pm    |   16 +++++++--
 lib/Code/TidyAll/t/Plugin.pm          |   21 +++++------
 lib/Code/TidyAll/t/Plugin/JSHint.pm   |   32 +++++++++++++++--
 lib/Code/TidyAll/t/Plugin/PodTidy.pm  |    7 ++--
 10 files changed, 211 insertions(+), 48 deletions(-)

diff --git a/bin/tidyall b/bin/tidyall
index 1cc1bcd..ec7db3e 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -164,23 +164,36 @@ changed since they were last processed.
 
 A I<tidier> transforms a file so as to improve its appearance without changing
 its semantics. Examples include L<perltidy>, L<podtidy> and
-L<htmltidy|HTML::Tidy>.
+L<js-beautify|https://npmjs.org/package/js-beautify>.
 
 A I<validator> analyzes a file for some definition of correctness. Examples
-include L<perlcritic>, L<podchecker> and
-L<xmllint|http://xmlsoft.org/xmllint.html>.
+include L<perlcritic>, L<podchecker> and L<jshint|http://www.jshint.com/>.
 
 Many tidiers are also validators, e.g. C<perltidy> will throw an error on badly
 formed Perl.
 
 To use a tidier or validator with C<tidyall> it must have a corresponding
 plugin class, usually under the prefix C<Code::TidyAll::Plugin::>.  This
-distribution comes with plugins for
-L<perltidy|Code::TidyAll::Plugin::PerlTidy>,
-L<perlcritic|Code::TidyAll::Plugin::PerlCritic> and
-L<podtidy|Code::TidyAll::Plugin::PodTidy>. See
-L<Code::TidyAll::Plugin|Code::TidyAll::Plugin> for information about creating
-your own plugin.
+distribution comes with plugins for:
+
+=over
+
+=item L<perlcritic|Code::TidyAll::Plugin::PerlCritic>
+
+=item L<perltidy|Code::TidyAll::Plugin::PerlTidy>
+
+=item L<podchecker|Code::TidyAll::Plugin::PodChecker>
+
+=item L<podtidy|Code::TidyAll::Plugin::PodTidy>
+
+=item L<jsbeautify|Code::TidyAll::Plugin::JSBeautify>
+
+=item L<jshint|Code::TidyAll::Plugin::JSHint>
+
+=back
+
+See L<Code::TidyAll::Plugin|Code::TidyAll::Plugin> for information about
+creating your own plugin.
 
 =head1 USING TIDYALL
 
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index dca1594..b637ef4 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -9,7 +9,6 @@ use Date::Format;
 use Digest::SHA1 qw(sha1_hex);
 use File::Find qw(find);
 use File::Zglob;
-use List::Pairwise qw(grepp mapp);
 use List::MoreUtils qw(uniq);
 use Moo;
 use Time::Duration::Parse qw(parse_duration);
@@ -71,7 +70,10 @@ sub _build_plugins_for_mode {
     my $self    = shift;
     my $plugins = $self->plugins;
     if ( my $mode = $self->mode ) {
-        $plugins = { grepp { $self->_plugin_conf_matches_mode( $b, $mode ) } %{ $self->plugins } };
+        $plugins = {
+            map { ( $_, $plugins->{$_} ) }
+            grep { $self->_plugin_conf_matches_mode( $plugins->{$_}, $mode ) } keys(%$plugins)
+        };
     }
     return $plugins;
 }
diff --git a/lib/Code/TidyAll/Plugin/JSBeautify.pm b/lib/Code/TidyAll/Plugin/JSBeautify.pm
index 01c82e9..6bc16aa 100644
--- a/lib/Code/TidyAll/Plugin/JSBeautify.pm
+++ b/lib/Code/TidyAll/Plugin/JSBeautify.pm
@@ -19,23 +19,34 @@ __END__
 
 =head1 NAME
 
-Code::TidyAll::Plugin::JSBeautify - use jsbeautify with tidyall
+Code::TidyAll::Plugin::JSBeautify - use js-beautify with tidyall
 
 =head1 SYNOPSIS
 
-   # In tidyall.ini:
+   In tidyall.ini:
 
    [JSBeautify]
    select = static/**/*.js
    argv = --indent-size 2 --brace-style expand
 
+=head1 DESCRIPTION
+
+Runs L<js-beautify|https://npmjs.org/package/js-beautify>, a Javascript tidier.
+
 =head1 INSTALLATION
 
-This plugin requires you to install the
-L<js-beautify|https://npmjs.org/package/js-beautify> npm package. Install
-L<npm|https://npmjs.org/>, then run
+Install L<npm|https://npmjs.org/>, then run
 
-    npm install js-beautfy -g
+    npm install js-beautify -g
 
 Do not confuse this with the C<jsbeautify> package (without the dash).
 
+=head1 CONFIGURATION
+
+=over
+
+=item argv
+
+Arguments to pass to js-beautfy
+
+=back
diff --git a/lib/Code/TidyAll/Plugin/JSHint.pm b/lib/Code/TidyAll/Plugin/JSHint.pm
index 1555043..5e1c737 100644
--- a/lib/Code/TidyAll/Plugin/JSHint.pm
+++ b/lib/Code/TidyAll/Plugin/JSHint.pm
@@ -1,10 +1,25 @@
 package Code::TidyAll::Plugin::JSHint;
+use Code::TidyAll::Util qw(tempdir_simple write_file);
 use Capture::Tiny qw(capture_merged);
 use Moo;
 extends 'Code::TidyAll::Plugin';
 
 sub _build_cmd { 'jshint' }
 
+sub BUILDARGS {
+    my ( $class, %params ) = @_;
+
+    if ( my $options_string = $params{options} ) {
+        my @options   = split( /\s+/, $options_string );
+        my $conf_dir  = tempdir_simple();
+        my $conf_file = "$conf_dir/jshint.json";
+        write_file( $conf_file, '{ ' . join( ",\n", map { "\"$_\": true" } @options ) . ' }' );
+        $params{argv} ||= "";
+        $params{argv} .= " --config $conf_file";
+    }
+    return \%params;
+}
+
 sub validate_file {
     my ( $self, $file ) = @_;
 
@@ -25,16 +40,56 @@ Code::TidyAll::Plugin::JSHint - use jshint with tidyall
 
 =head1 SYNOPSIS
 
-   # In tidyall.ini:
+   In tidyall.ini:
+
+   ; With default settings
+   ;
+   [JSHint]
+   select = static/**/*.js
+
+   ; Specify options inline
+   ;
+   [JSHint]
+   select = static/**/*.js
+   options = bitwise camelcase latedef
 
+   ; or refer to a jshint.json config file in the same directory
+   ;
    [JSHint]
    select = static/**/*.js
    argv = --config $ROOT/jshint.json
 
+   where jshint.json looks like
+
+   {
+      "bitwise": true,
+      "camelcase": true,
+      "latedef": true
+   }
+
 =head1 DESCRIPTION
 
-This plugin requires you to install L<jshint|http://www.jshint.com/platforms/>.
-The easiest way to do that at present time is to install
-L<npm|https://npmjs.org/>, then run
+Runs L<jshint|http://www.jshint.com/>, a Javascript validator, and dies if any
+problems were found.
+
+=head1 INSTALLATION
+
+See installation options at L<jshint|http://www.jshint.com/platforms/>. One
+easy method is to install L<npm|https://npmjs.org/>, then run
 
     npm install jshint -g
+
+=head1 CONFIGURATION
+
+=over
+
+=item argv
+
+Arguments to pass to jshint
+
+=item options
+
+A whitespace separated string of options, as documented
+L<here|http://www.jshint.com/docs/>
+
+=back
diff --git a/lib/Code/TidyAll/Plugin/PerlCritic.pm b/lib/Code/TidyAll/Plugin/PerlCritic.pm
index 0e83a0a..9cbb2db 100644
--- a/lib/Code/TidyAll/Plugin/PerlCritic.pm
+++ b/lib/Code/TidyAll/Plugin/PerlCritic.pm
@@ -25,16 +25,37 @@ Code::TidyAll::Plugin::PerlCritic - use perlcritic with tidyall
 
 =head1 SYNOPSIS
 
-   # In tidyall.ini:
+   In tidyall.ini:
 
-   # Configure in-line
-   #
+   ; Configure in-line
+   ;
    [PerlCritic]
    argv = --severity 5 --exclude=nowarnings
    select = lib/**/*.pm
 
-   # or refer to a .perlcriticrc in the same directory
-   #
+   ; or refer to a .perlcriticrc in the same directory
+   ;
    [PerlCritic]
    argv = --profile $ROOT/.perlcriticrc
    select = lib/**/*.pm
+
+=head1 DESCRIPTION
+
+Runs L<perlcritic|perlcritic>, a Perl validator, and dies if any problems were
+found.
+
+=head1 INSTALLATION
+
+Install perlcritic from CPAN.
+
+    cpanm perlcritic
+
+=head1 CONFIGURATION
+
+=over
+
+=item argv
+
+Arguments to pass to perlcritic
+
+=back
diff --git a/lib/Code/TidyAll/Plugin/PerlTidy.pm b/lib/Code/TidyAll/Plugin/PerlTidy.pm
index 668bce6..9334c2c 100644
--- a/lib/Code/TidyAll/Plugin/PerlTidy.pm
+++ b/lib/Code/TidyAll/Plugin/PerlTidy.pm
@@ -32,14 +32,35 @@ Code::TidyAll::Plugin::PerlTidy - use perltidy with tidyall
 
    # In tidyall.ini:
 
-   # Configure in-line
-   #
+   ; Configure in-line
+   ;
    [PerlTidy]
    argv = --noll
    select = lib/**/*.pm
 
-   # or refer to a .perltidyrc in the same directory
-   #
+   ; or refer to a .perltidyrc in the same directory
+   ;
    [PerlTidy]
    argv = --profile=$ROOT/.perltidyrc
    select = lib/**/*.pm
+
+=head1 DESCRIPTION
+
+Runs L<perltidy|perltidy>, a Perl tidier.
+
+=head1 INSTALLATION
+
+Install perltidy from CPAN.
+
+    cpanm perltidy
+
+=head1 CONFIGURATION
+
+=over
+
+=item argv
+
+Arguments to pass to perltidy
+
+=back
+
diff --git a/lib/Code/TidyAll/Plugin/PodTidy.pm b/lib/Code/TidyAll/Plugin/PodTidy.pm
index 23cdc66..a6a0cdf 100644
--- a/lib/Code/TidyAll/Plugin/PodTidy.pm
+++ b/lib/Code/TidyAll/Plugin/PodTidy.pm
@@ -33,18 +33,28 @@ Code::TidyAll::Plugin::PodTidy - use podtidy with tidyall
 
 =head1 SYNOPSIS
 
-   # In tidyall.ini:
+   In tidyall.ini:
 
    [PodTidy]
    select = lib/**/*.{pm,pod}
    columns = 90
 
-=head1 OPTIONS
+=head1 DESCRIPTION
+
+Runs L<podtidy|podtidy>, which will tidy the POD in your Perl or POD-only file.
+
+=head1 INSTALLATION
+
+Install podtidy from CPAN.
+
+    cpanm podtidy
+
+=head1 CONFIGURATION
 
 =over
 
 =item columns
 
-Number of columns to fill
+Number of columns per line
 
 =back
diff --git a/lib/Code/TidyAll/t/Plugin.pm b/lib/Code/TidyAll/t/Plugin.pm
index b6ff5b4..19e1286 100644
--- a/lib/Code/TidyAll/t/Plugin.pm
+++ b/lib/Code/TidyAll/t/Plugin.pm
@@ -24,9 +24,10 @@ sub test_filename { 'foo.txt' }
 sub tidyall {
     my ( $self, %p ) = @_;
 
-    my $source       = $p{source} || die "source required";
+    my $source = $p{source} || die "source required";
+    my $desc   = $p{desc}   || $source;
     my $plugin_class = $self->plugin_class;
-    my %plugin_conf  = ( $plugin_class => { select => '*', %{ $p{conf} || {} } } );
+    my %plugin_conf = ( $plugin_class => { select => '*', %{ $p{conf} || {} } } );
     my $ct =
       Code::TidyAll->new( quiet => 1, root_dir => $self->{root_dir}, plugins => \%plugin_conf );
 
@@ -37,20 +38,20 @@ sub tidyall {
 
     if ( my $expect_tidy = $p{expect_tidy} ) {
         $expect_tidy =~ s/\\n/\n/g;
-        is( $result->state,        'tidied',     'state=tidied' );
-        is( $result->new_contents, $expect_tidy, 'new contents' );
-        is( $result->error,        undef,        'no error' );
+        is( $result->state,        'tidied',     "state=tidied [$desc]" );
+        is( $result->new_contents, $expect_tidy, "new contents [$desc]" );
+        is( $result->error,        undef,        "no error [$desc]" );
     }
     elsif ( my $expect_ok = $p{expect_ok} ) {
-        is( $result->state, 'checked', 'state=checked' );
-        is( $result->error, undef,     'no error' );
+        is( $result->state, 'checked', "state=checked [$desc]" );
+        is( $result->error, undef,     "no error [$desc]" );
         if ( $result->new_contents ) {
-            is( $result->new_contents, $source, 'same contents' );
+            is( $result->new_contents, $source, "same contents [$desc]" );
         }
     }
     elsif ( my $expect_error = $p{expect_error} ) {
-        is( $result->state, 'error', 'state=error' );
-        like( $result->error, $expect_error, 'error message' );
+        is( $result->state, 'error', "state=error [$desc]" );
+        like( $result->error, $expect_error, "error message [$desc]" );
     }
 }
 
diff --git a/lib/Code/TidyAll/t/Plugin/JSHint.pm b/lib/Code/TidyAll/t/Plugin/JSHint.pm
index 4cb614f..7e8819b 100644
--- a/lib/Code/TidyAll/t/Plugin/JSHint.pm
+++ b/lib/Code/TidyAll/t/Plugin/JSHint.pm
@@ -11,17 +11,43 @@ sub test_main : Tests {
 
     $self->tidyall(
         source    => 'var my_object = {};',
-        expect_ok => 1
+        expect_ok => 1,
+        desc      => 'ok - camelcase',
+    );
+    $self->tidyall(
+        source    => 'while (day)\n  shuffle();',
+        expect_ok => 1,
+        desc      => 'ok no brace',
     );
     $self->tidyall(
         source       => 'var my_object = new Object();',
-        expect_error => qr/object literal notation/
+        expect_error => qr/object literal notation/,
+        desc         => 'error - object literal',
+    );
+    $self->tidyall(
+        source       => 'var my_object = {};',
+        conf         => { options => 'camelcase' },
+        expect_error => qr/not in camel case/,
+        desc         => 'error - camel case - options=camelcase',
+    );
+    $self->tidyall(
+        source       => 'var my_object = {};',
+        conf         => { options => 'camelcase curly' },
+        expect_error => qr/not in camel case/,
+        desc         => 'error - camel case - options=camelcase,curly',
+    );
+    $self->tidyall(
+        source       => 'while (day)\n  shuffle();',
+        conf         => { options => 'camelcase curly' },
+        expect_error => qr/Expected \'{/,
+        desc         => 'error - curly - options=camelcase,curly',
     );
     write_file( $rc_file, '{"camelcase": true}' );
     $self->tidyall(
         source       => 'var my_object = {};',
         conf         => { argv => "--config $rc_file" },
-        expect_error => qr/not in camel case/
+        expect_error => qr/not in camel case/,
+        desc         => 'error - camelcase - conf file',
     );
 }
 
diff --git a/lib/Code/TidyAll/t/Plugin/PodTidy.pm b/lib/Code/TidyAll/t/Plugin/PodTidy.pm
index 32ca4d1..cf93958 100644
--- a/lib/Code/TidyAll/t/Plugin/PodTidy.pm
+++ b/lib/Code/TidyAll/t/Plugin/PodTidy.pm
@@ -23,7 +23,8 @@ configure which tidiers/validators are applied to which files. C<tidyall> will
 back up files beforehand, and for efficiency will only consider files that have
 changed since they were last processed.
 
-'
+',
+        desc => 'tidy - defaults',
     );
 
     $self->tidyall(
@@ -39,6 +40,7 @@ changed since they were last processed.
 
 ',
         expect_ok => 1,
+        desc      => 'ok - defaults',
     );
 
     $self->tidyall(
@@ -64,7 +66,8 @@ efficiency will only consider
 files that have changed since
 they were last processed.
 
-'
+',
+        desc => 'tidy - columns = 30',
     );
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git



More information about the Pkg-perl-cvs-commits mailing list