[libcode-tidyall-perl] 334/374: add SortLines

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:46 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 a54014a83f1a42b44f0ca59c7465f2e13119162e
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Mon Oct 22 07:12:32 2012 -0700

    add SortLines
---
 .ispell_english                        |    3 ++-
 bin/tidyall                            |    4 ++++
 lib/Code/TidyAll/Plugin/SortLines.pm   |   33 ++++++++++++++++++++++++++++++++
 lib/Code/TidyAll/t/Plugin.pm           |    1 +
 lib/Code/TidyAll/t/Plugin/SortLines.pm |   11 +++++++++++
 xt/author/Plugin-SortLines.t           |    3 +++
 6 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/.ispell_english b/.ispell_english
index 6c23fd2..9e986cb 100644
--- a/.ispell_english
+++ b/.ispell_english
@@ -1,6 +1,7 @@
 API
 CPAN
 JavaScript
+Misc
 PHP
 Raggett
 STDERR
@@ -15,6 +16,7 @@ atomicity
 cmd
 conf
 config
+cssunminifier
 ctrl
 dir
 iff
@@ -45,6 +47,5 @@ svn
 tidiers
 tidyall
 txn
-cssunminifier
 validator
 validators
diff --git a/bin/tidyall b/bin/tidyall
index 5d095f5..0c42c32 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -267,6 +267,10 @@ CSS: L<cssunminifier|Code::TidyAll::Plugin::CSUnminifier>
 
 PHP: L<phpcs|Code::TidyAll::Plugin::CSUnminifier>
 
+=item *
+
+Misc: L<Code::TidyAll::Plugin::SortLines|Code::TidyAll::Plugin::SortLines>
+
 =back
 
 See L<Code::TidyAll::Plugin|Code::TidyAll::Plugin> for information about
diff --git a/lib/Code/TidyAll/Plugin/SortLines.pm b/lib/Code/TidyAll/Plugin/SortLines.pm
new file mode 100644
index 0000000..9c52317
--- /dev/null
+++ b/lib/Code/TidyAll/Plugin/SortLines.pm
@@ -0,0 +1,33 @@
+package Code::TidyAll::Plugin::SortLines;
+use Moo;
+extends 'Code::TidyAll::Plugin';
+
+sub transform_source {
+    my ( $self, $source ) = @_;
+
+    return join( "\n", sort( grep { /\S/ } split( /\n/, $source ) ) ) . "\n";
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Code::TidyAll::Plugin::SortLines - sort lines of a file
+
+=head1 SYNOPSIS
+
+   # In configuration:
+
+   [SortLines]
+   select = .ispell* **/.gitignore
+
+=head1 DESCRIPTION
+
+Sorts the lines of a file; whitespace lines are discarded. Useful for files
+containing one entry per line, such as C<.svnignore>, C<.gitignore>, and
+C<.ispell*>.
+
diff --git a/lib/Code/TidyAll/t/Plugin.pm b/lib/Code/TidyAll/t/Plugin.pm
index 195009c..a84856c 100644
--- a/lib/Code/TidyAll/t/Plugin.pm
+++ b/lib/Code/TidyAll/t/Plugin.pm
@@ -26,6 +26,7 @@ sub tidyall {
 
     my $source = $p{source} || die "source required";
     my $desc   = $p{desc}   || $source;
+    $desc =~ s/\n/\\n/g;
     my $plugin_class = $self->plugin_class;
     my %plugin_conf = ( $plugin_class => { select => '*', %{ $p{conf} || {} } } );
     my $ct =
diff --git a/lib/Code/TidyAll/t/Plugin/SortLines.pm b/lib/Code/TidyAll/t/Plugin/SortLines.pm
new file mode 100644
index 0000000..3990008
--- /dev/null
+++ b/lib/Code/TidyAll/t/Plugin/SortLines.pm
@@ -0,0 +1,11 @@
+package Code::TidyAll::t::Plugin::SortLines;
+use Test::Class::Most parent => 'Code::TidyAll::t::Plugin';
+
+sub test_main : Tests {
+    my $self = shift;
+
+    $self->tidyall( source => "c\nb\na\n",   expect_tidy => "a\nb\nc\n" );
+    $self->tidyall( source => "\n\na\n\n\n", expect_tidy => "a\n" );
+}
+
+1;
diff --git a/xt/author/Plugin-SortLines.t b/xt/author/Plugin-SortLines.t
new file mode 100644
index 0000000..8c18580
--- /dev/null
+++ b/xt/author/Plugin-SortLines.t
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+use Code::TidyAll::t::Plugin::SortLines;
+Code::TidyAll::t::Plugin::SortLines->runtests;

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