[libcode-tidyall-perl] 263/374: Allow .tidyallrc as alternative to tidyall.ini

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:32 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 e3c7510cc70c22b197623f1c2ccee9be417a28c5
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Tue Sep 25 16:11:41 2012 -0700

    Allow .tidyallrc as alternative to tidyall.ini
---
 .ispell_english             |   12 +++++++
 Changes                     |   13 ++++++--
 bin/tidyall                 |   46 ++++++++++++++------------
 lib/Code/TidyAll.pm         |   37 ++++++++++++---------
 lib/Code/TidyAll/t/Basic.pm |   75 ++++++++++++++++++++++---------------------
 5 files changed, 108 insertions(+), 75 deletions(-)

diff --git a/.ispell_english b/.ispell_english
index 72fa784..3049691 100644
--- a/.ispell_english
+++ b/.ispell_english
@@ -1,19 +1,30 @@
 API
+CPAN
+JavaScript
 STDERR
 STDIN
 STDOUT
+Simakov
 TIDYALL
 Thalhammer
 argv
+cmd
 conf
+config
 dir
+iff
 js
 jsbeautify
 jshint
 jslint
 lib
+listref
 masontidy
 noll
+npm
+ok
+ops
+params
 perlcritic
 perlcriticrc
 perltidy
@@ -21,6 +32,7 @@ plugins
 podspell
 podtidy
 pre
+repo
 repos
 svn
 tidiers
diff --git a/Changes b/Changes
index 26b46b9..89d92ce 100644
--- a/Changes
+++ b/Changes
@@ -4,6 +4,13 @@ Revision history for Code-TidyAll
 
 0.12  Sep 21, 2012
 
+* Plugins
+  - Add podspell plugin (POD spell checker)
+
+* Improvements
+  - Allow .tidyallrc as alternative to tidyall.ini
+  - Add handcrafted usage w/summary of options, instead of Pod::Usage
+
 0.11  Sep 21, 2012
 
 * Improvements
@@ -20,7 +27,7 @@ Revision history for Code-TidyAll
 
 0.10  Sep 12, 2012
 
-* Improvements
+* Plugins
   - Add masontidy plugin (Mason component tidier)
   - Add jslint plugin (javascript validator)
 
@@ -32,9 +39,11 @@ Revision history for Code-TidyAll
 
 0.08  Sep 10, 2012
 
-* Improvements
+* Plugins
   - Add js-beautify plugin (javascript tidier)
   - Add jshint plugin (javascript validator)
+
+* Improvements
   - Add podchecker plugin
   - Add -p/--pipe flag to read from STDIN and write to STDOUT
   - Allow tidyall.el to work in narrowed regions
diff --git a/bin/tidyall b/bin/tidyall
index daac238..65c0407 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -38,8 +38,11 @@ sub usage {
     exit;
 }
 
-my ( %params, $all_files, $conf_file, $git_files, $help, $inc_dirs, $list, $pipe, $svn_files );
-my $conf_name = 'tidyall.ini';
+my (
+    %params, $all_files, $conf_file, $conf_name, $git_files,
+    $help,   $inc_dirs,  $list,      $pipe,      $svn_files
+);
+my @conf_names = ( 'tidyall.ini', '.tidyallrc' );
 
 GetOptions(
     'backup-ttl=i'    => \$params{backup_ttl},
@@ -64,15 +67,15 @@ GetOptions(
     'v|verbose'       => \$params{verbose},
     'I'               => \$inc_dirs,
 ) or usage();
-
 usage() if $help;
+ at conf_names = ($conf_name) if defined($conf_name);
 
 unshift( @INC, split( /\s*,\s*/, $inc_dirs ) ) if defined($inc_dirs);
 
 %params = map { ( $_, $params{$_} ) } grep { defined( $params{$_} ) } keys(%params);
 
-$conf_file = "$params{root_dir}/tidyall.ini"
-  if $params{root_dir} && !$conf_file && -f "$params{root_dir}/tidyall.ini";
+($conf_file) = ( grep { -f } map { "$params{root_dir}/$_" } @conf_names )
+  if $params{root_dir} && !$conf_file;
 
 my $tidyall_class = $params{tidyall_class} || 'Code::TidyAll';
 
@@ -85,7 +88,7 @@ if ($pipe) {
 elsif ( ( $all_files || $svn_files || $git_files ) ) {
     die "cannot use filename(s) with -a/--all, -s/--svn, or -g/--git"
       if @ARGV;
-    $conf_file ||= $tidyall_class->find_conf_file( $conf_name, cwd() );
+    $conf_file ||= $tidyall_class->find_conf_file( \@conf_names, cwd() );
     $ct = $tidyall_class->new_from_conf_file( $conf_file, %params );
 
     if ($all_files) {
@@ -101,7 +104,7 @@ elsif ( ( $all_files || $svn_files || $git_files ) ) {
     }
 }
 elsif ( @files = @ARGV ) {
-    $conf_file ||= $tidyall_class->find_conf_file( $conf_name, dirname( $files[0] ) );
+    $conf_file ||= $tidyall_class->find_conf_file( \@conf_names, dirname( $files[0] ) );
     $ct = $tidyall_class->new_from_conf_file( $conf_file, %params );
 }
 else {
@@ -124,7 +127,7 @@ sub handle_pipe {
     $params{$_} = 1 for ( 'no_backups', 'no_cache', 'quiet' );
     $params{$_} = 0 for ('verbose');
 
-    $conf_file ||= $tidyall_class->find_conf_file( $conf_name, dirname($pipe_filename) );
+    $conf_file ||= $tidyall_class->find_conf_file( \@conf_names, dirname($pipe_filename) );
     my $ct       = $tidyall_class->new_from_conf_file( $conf_file, %params );
     my $root_dir = $ct->root_dir;
     my $source   = do { local $/; <STDIN> };
@@ -165,7 +168,7 @@ tidyall - Your all-in-one code tidier and validator
 
 =head1 SYNOPSIS
 
-    # Create a tidyall.ini at the top of your project
+    # Create a tidyall.ini or .tidyallrc at the top of your project
     #
     [PerlTidy]
     select = **/*.{pl,pm,t}
@@ -177,7 +180,7 @@ tidyall - Your all-in-one code tidier and validator
     argv = -severity 3
 
     # Process all files in the current project,
-    # look upwards from cwd for tidyall.ini
+    # look upwards from cwd for conf file
     #
     % tidyall -a
 
@@ -186,7 +189,7 @@ tidyall - Your all-in-one code tidier and validator
     % tidyall -a --root-dir /home/joe/project
 
     # Process one or more specific files,
-    # look upwards from the first file for tidyall.ini
+    # look upwards from the first file for conf file
     #
     % tidyall file [file...]
 
@@ -248,8 +251,8 @@ hierarchy of files. svn or git working directories are typical examples of
 projects.
 
 The top of the project is called the I<root directory>. In the root directory
-you'll need a C<tidyall.ini> config file; it defines how various tidiers and
-validators will be applied to the files in your project.
+you'll need a config file named C<tidyall.ini> or C<.tidyallrc>; it defines how
+various tidiers and validators will be applied to the files in your project.
 
 C<tidyall> will find your root directory and config file automatically
 depending on how you call it:
@@ -258,20 +261,20 @@ depending on how you call it:
 
 =item C<< tidyall file [file...] >>
 
-C<tidyall> will search upwards from the first file for C<tidyall.ini>.
+C<tidyall> will search upwards from the first file for the conf file.
 
 =item C<< tidyall -p/--pipe file >>
 
-C<tidyall> will search upwards from the specified file for C<tidyall.ini>.
+C<tidyall> will search upwards from the specified file for the conf file.
 
 =item C<< tidyall -a/--all >> or C<< tidyall -s/--svn >> or C<< tidyall -g/--git >>
 
-C<tidyall> will search upwards from the current working directory for
-C<tidyall.ini>.
+C<tidyall> will search upwards from the current working directory for the conf
+file.
 
 =item C<< tidyall -a --root-dir dir >>
 
-C<tidyall> will expect to find C<tidyall.ini> in the specified root directory.
+C<tidyall> will expect to find the conf file in the specified root directory.
 
 =back
 
@@ -280,8 +283,8 @@ You can also pass --conf-name to change the name that is searched for, or
 
 =head1 CONFIGURATION
 
-The config file (C<tidyall.ini>) is in L<Config::INI|Config::INI> format.
-Here's a sample:
+The config file (C<tidyall.ini> or C<.tidyallrc>) is in
+L<Config::INI|Config::INI> format.  Here's a sample:
 
     [PerlTidy]
     select = **/*.{pl,pm,t}
@@ -490,7 +493,8 @@ the usual way.
 
 =item --conf-name I<name>
 
-Specify a conf file name to search for instead of C<tidyall.ini>.
+Specify a conf file name to search for instead of the defaults (C<tidyall.ini>
+/ C<.tidyallrc>).
 
 =item --data-dir I<path>
 
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index eb4bbf2..81a736c 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -324,31 +324,34 @@ sub _purge_backups {
 }
 
 sub find_conf_file {
-    my ( $class, $conf_name, $start_dir ) = @_;
+    my ( $class, $conf_names, $start_dir ) = @_;
 
     my $path1     = rel2abs($start_dir);
     my $path2     = realpath($start_dir);
-    my $conf_file = $class->_find_conf_file_upward( $conf_name, $path1 )
-      || $class->_find_conf_file_upward( $conf_name, $path2 );
+    my $conf_file = $class->_find_conf_file_upward( $conf_names, $path1 )
+      || $class->_find_conf_file_upward( $conf_names, $path2 );
     unless ( defined $conf_file ) {
-        die sprintf( "could not find $conf_name upwards from %s",
-            ( $path1 eq $path2 ) ? "'$path1'" : "'$path1' or '$path2'" );
+        die sprintf(
+            "could not find %s upwards from %s",
+            join( " or ", @$conf_names ),
+            ( $path1 eq $path2 ) ? "'$path1'" : "'$path1' or '$path2'"
+        );
     }
     return $conf_file;
 }
 
 sub _find_conf_file_upward {
-    my ( $class, $conf_name, $search_dir ) = @_;
+    my ( $class, $conf_names, $search_dir ) = @_;
 
     $search_dir =~ s{/+$}{};
 
     my $cnt = 0;
     while (1) {
-        my $try_path = "$search_dir/$conf_name";
-        if ( -f $try_path ) {
-            return $try_path;
+        foreach my $conf_name (@$conf_names) {
+            my $try_path = "$search_dir/$conf_name";
+            return $try_path if ( -f $try_path );
         }
-        elsif ( $search_dir eq '/' ) {
+        if ( $search_dir eq '/' ) {
             return undef;
         }
         else {
@@ -509,7 +512,8 @@ constructed instead of C<Code::TidyAll>.
 =item plugins
 
 Specify a hash of plugins, each of which is itself a hash of options. This is
-equivalent to what would be parsed out of the sections in C<tidyall.ini>.
+equivalent to what would be parsed out of the sections in the configuration
+file.
 
 =item backup_ttl
 
@@ -578,23 +582,24 @@ Return a L<Code::TidyAll::Result|Code::TidyAll::Result> object
 
 =back
 
-=item process_source (source, path)
+=item process_source (I<source>, I<path>)
 
 Same as L</process_file>, but process the I<source> string instead of a file.
 You must still pass the relative I<path> from the root as the second argument,
 so that we know which plugins to apply. Return a
 L<Code::TidyAll::Result|Code::TidyAll::Result> object.
 
-=item plugins_for_path (path)
+=item plugins_for_path (I<path>)
 
 Given a relative I<path> from the root, return a list of
 L<Code::TidyAll::Plugin|Code::TidyAll::Plugin> objects that apply to it, or an
 empty list if no plugins apply.
 
-=item find_conf_file (start_dir)
+=item find_conf_file (I<conf_names>, I<start_dir>)
 
-Class method. Start in the I<start_dir> and work upwards, looking for a
-C<tidyall.ini>.  Return the pathname if found or throw an error if not found.
+Class method. Start in the I<start_dir> and work upwards, looking for one of
+the I<conf_names>.  Return the pathname if found or throw an error if not
+found.
 
 =back
 
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index a95fb35..a07fb9c 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -259,42 +259,45 @@ sub test_errors : Tests {
 }
 
 sub test_cli : Tests {
-    my $self      = shift;
-    my $root_dir  = $self->create_dir();
-    my $conf_file = "$root_dir/tidyall.ini";
-    write_file( $conf_file, $cli_conf );
-
-    write_file( "$root_dir/foo.txt", "hello" );
-    my $output = capture_stdout {
-        system( "$^X", "bin/tidyall", "$root_dir/foo.txt", "-v" );
-    };
-
-    my ($params_msg) = ( $output =~ /constructing Code::TidyAll with these params:(.*)/ );
-    ok( defined($params_msg), "params msg" );
-    like( $params_msg, qr/backup_ttl => '15m'/,                              'backup_ttl' );
-    like( $params_msg, qr/verbose => '?1'?/,                                 'verbose' );
-    like( $params_msg, qr/\Qroot_dir => '$root_dir'\E/,                      'root_dir' );
-    like( $output,     qr/\[tidied\]  foo.txt \(.*RepeatFoo, .*UpperText\)/, 'foo.txt' );
-    is( read_file("$root_dir/foo.txt"), "HELLOHELLOHELLO", "tidied" );
-
-    mkpath( "$root_dir/subdir", 0, 0775 );
-    write_file( "$root_dir/subdir/foo.txt",  "bye" );
-    write_file( "$root_dir/subdir/foo2.txt", "bye" );
-    my $cwd = realpath();
-    capture_stdout {
-        system("cd $root_dir/subdir; $^X $cwd/bin/tidyall foo.txt");
-    };
-    is( read_file("$root_dir/subdir/foo.txt"),  "BYEBYEBYE", "foo.txt tidied" );
-    is( read_file("$root_dir/subdir/foo2.txt"), "bye",       "foo2.txt not tidied" );
-
-    # Test -p / --pipe
-    #
-    my ( $stdout, $stderr ) = capture {
-        open( my $fh, "|-", "$^X", "bin/tidyall", "-p", "$root_dir/does_not_exist/foo.txt" );
-        print $fh "echo";
-    };
-    is( $stdout, "ECHOECHOECHO", "pipe: stdin tidied" );
-    unlike( $stderr, qr/\S/, "pipe: no stderr" );
+    my $self = shift;
+
+    foreach my $conf_name ( "tidyall.ini", ".tidyallrc" ) {
+        my $root_dir  = $self->create_dir();
+        my $conf_file = "$root_dir/$conf_name";
+        write_file( $conf_file, $cli_conf );
+
+        write_file( "$root_dir/foo.txt", "hello" );
+        my $output = capture_stdout {
+            system( "$^X", "bin/tidyall", "$root_dir/foo.txt", "-v" );
+        };
+
+        my ($params_msg) = ( $output =~ /constructing Code::TidyAll with these params:(.*)/ );
+        ok( defined($params_msg), "params msg" );
+        like( $params_msg, qr/backup_ttl => '15m'/,                              'backup_ttl' );
+        like( $params_msg, qr/verbose => '?1'?/,                                 'verbose' );
+        like( $params_msg, qr/\Qroot_dir => '$root_dir'\E/,                      'root_dir' );
+        like( $output,     qr/\[tidied\]  foo.txt \(.*RepeatFoo, .*UpperText\)/, 'foo.txt' );
+        is( read_file("$root_dir/foo.txt"), "HELLOHELLOHELLO", "tidied" );
+
+        mkpath( "$root_dir/subdir", 0, 0775 );
+        write_file( "$root_dir/subdir/foo.txt",  "bye" );
+        write_file( "$root_dir/subdir/foo2.txt", "bye" );
+        my $cwd = realpath();
+        capture_stdout {
+            system("cd $root_dir/subdir; $^X $cwd/bin/tidyall foo.txt");
+        };
+        is( read_file("$root_dir/subdir/foo.txt"),  "BYEBYEBYE", "foo.txt tidied" );
+        is( read_file("$root_dir/subdir/foo2.txt"), "bye",       "foo2.txt not tidied" );
+
+        # Test -p / --pipe
+        #
+        my ( $stdout, $stderr ) = capture {
+            open( my $fh, "|-", "$^X", "bin/tidyall", "-p", "$root_dir/does_not_exist/foo.txt" );
+            print $fh "echo";
+        };
+        is( $stdout, "ECHOECHOECHO", "pipe: stdin tidied" );
+        unlike( $stderr, qr/\S/, "pipe: no stderr" );
+    }
 }
 
 $cli_conf = '

-- 
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