Code-TidyAll
view release on metacpan or search on metacpan
0.73 2019-01-20
- Fix test failures on Windows. Based on GH #91 from Shlomi Fish.
0.72 2018-12-20
- Added documentation for the -j/--jobs flag to the tidyall script's help
output and POD docs.
- Make the --iterations flag for bin/tidyall actually work. This had been
documented but it has never actually done anything (though setting this in
your config file does work).
0.71 2018-09-12
- Added two new plugins, GenericValidator and GenericTransformer. These allow
you to execute any command as a validator or transformer respectively. This
should be sufficient to keep us all from having to write new plugins for
every command in the world, as these two plugins should handle most common
* Remove Util.t containing only author-only tests
0.12 2012-09-27
[ENHANCEMENTS]
* Added podspell plugin (POD spell checker)
* Added --iterations flag to run tidier transforms multiple times
* Allow .tidyallrc as alternative to tidyall.ini
* Allow git prereceive hook to be bypassed by pushing an identical set of commits
several consecutive times (allow_repeated_push)
* Added handcrafted usage w/summary of options, instead of Pod::Usage
0.11 2012-09-21
Defaults to false.
- inc
An arrayref of directories to prepend to `@INC`. This can be set via the
command-line as `-I`, but you can also set it in a config file.
This affects both loading and running plugins.
- data\_dir
- iterations
- mode
- no\_backups
- no\_cache
- output\_suffix
- quiet
- root\_dir
- ignore
- verbose
These options are the same as the equivalent `tidyall` command-line options,
bin/tidyall view on Meta::CPAN
-s, --svn Process all added/modified files according to svn
-q, --quiet Suppress output except for errors
-v, --verbose Show extra output
-I I<path1,path2,...> Add one or more paths to @INC
--backup-ttl <duration> Amount of time before backup files can be purged
--check-only Just check each file, don't modify
--plugins <name> Explicitly run only the given plugins
--conf-file <path> Relative or absolute path to conf file
--conf-name <name> Conf file name to search for
--data-dir <path> Contains metadata, defaults to root/.tidyall.d
--iterations <count> Number of times to repeat each transform - default is 1
--no-backups Don't back up files before processing
--no-cache Don't cache last processed times
--no-cleanup Don't clean up the temporary files
--output-suffix <suffix> Suffix to add to tidied file
--refresh-cache Erase any existing cache info before processing each file
--root-dir Specify root directory explicitly
--tidyall-class <class> Subclass to use instead of Code::TidyAll
--version Show version
-h, --help Print help message
EOF
bin/tidyall view on Meta::CPAN
}
my (
%params,
$all_files,
$git_files,
$pipe,
$svn_files,
$conf_file,
$conf_name,
$iterations,
$inc_dirs,
$version,
$help,
);
my @conf_names = Code::TidyAll->default_conf_names;
Getopt::Long::Configure('no_ignore_case');
GetOptions(
'a|all' => \$all_files,
bin/tidyall view on Meta::CPAN
's|svn' => \$svn_files,
'q|quiet' => \$params{quiet},
'v|verbose' => \$params{verbose},
'I=s' => \$inc_dirs,
'backup-ttl=i' => \$params{backup_ttl},
'check-only' => \$params{check_only},
'plugins=s@' => \$params{selected_plugins},
'conf-file=s' => \$conf_file,
'conf-name=s' => \$conf_name,
'data-dir=s' => \$params{data_dir},
'iterations=i' => \$iterations,
'no-backups' => \$params{no_backups},
'no-cache' => \$params{no_cache},
'no-cleanup' => \$params{no_cleanup},
'output-suffix=s' => \$params{output_suffix},
'refresh-cache' => \$params{refresh_cache},
'root-dir=s' => \$params{root_dir},
'tidyall-class=s' => \$params{tidyall_class},
'version' => \$version,
'h|help' => \$help,
) or usage();
version() if $version;
usage() if $help;
@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;
for my $key (qw( data_dir root_dir )) {
$params{$key} = path( $params{$key} ) if exists $params{$key};
}
$params{iterations} = $iterations if $iterations;
($conf_file) = ( grep { $_->is_file } map { $params{root_dir}->child($_) } @conf_names )
if $params{root_dir} && !$conf_file;
my $tidyall_class = $params{tidyall_class} || 'Code::TidyAll';
use_module($tidyall_class);
my ( $ct, @paths );
bin/tidyall view on Meta::CPAN
=item --conf-name I<name>
Specify a conf file name to search for instead of the defaults (C<tidyall.ini>
/ C<.tidyallrc>).
=item --data-dir I<path>
Contains data like backups and cache. Defaults to root_dir/.tidyall.d
=item --iterations I<count>
Run each tidier transform I<count> times. Default is 1.
In some cases (hopefully rare) the output from a tidier can be different if it
is applied multiple times. You may want to perform multiple iterations to make
sure the content "settles" into its final tidied form -- especially if the
tidiness is being enforced with a version-control hook or a test. Of course,
performance will suffer a little. You should rarely need to set this higher
than 2.
This only affects tidiers, not validators; e.g.
L<perlcritic|Code::TidyAll::Plugin::PerlCritic> and
L<jshint|Code::TidyAll::Plugin::JSHint> would still only be run once.
=item --no-backups
bin/tidyall view on Meta::CPAN
Print help message
=back
=head2 Specifying options in configuration
Almost any command-line option can be specified at the top of the config file,
above the plugin sections. Replace dashes with underscores. e.g.
backup_ttl = 4h
iterations = 2
tidyall_class = My::Code::TidyAll
[PerlTidy]
select = **/*.{pl,pm,t}
argv = -noll -it=2
...
If an option is passed in both places, the command-line takes precedence.
lib/Code/TidyAll.pm view on Meta::CPAN
is => 'ro',
isa => t('Bool'),
);
has data_dir => (
is => 'lazy',
isa => t('Path'),
coerce => t('Path')->coercion_sub,
);
has iterations => (
is => 'ro',
isa => t('PositiveInt'),
default => 1,
);
has jobs => (
is => 'ro',
isa => t('Int'),
default => 1,
);
lib/Code/TidyAll.pm view on Meta::CPAN
=item * inc
An arrayref of directories to prepend to C<@INC>. This can be set via the
command-line as C<-I>, but you can also set it in a config file.
This affects both loading and running plugins.
=item * data_dir
=item * iterations
=item * mode
=item * no_backups
=item * no_cache
=item * output_suffix
=item * quiet
lib/Code/TidyAll/Plugin.pm view on Meta::CPAN
sub postprocess_source {
return $_[1];
}
sub process_source_or_file {
my ( $self, $orig_source, $rel_path, $check_only ) = @_;
my $new_source = $orig_source;
if ( $self->can('transform_source') ) {
foreach my $iter ( 1 .. $self->tidyall->iterations ) {
$new_source = $self->transform_source($new_source);
}
}
if ( $self->can('transform_file') ) {
my $tempfile = $self->_write_temp_file( $rel_path, $new_source );
foreach my $iter ( 1 .. $self->tidyall->iterations ) {
$self->transform_file($tempfile);
}
$new_source = $tempfile->slurp_raw;
}
if ( $self->can('validate_source') ) {
$self->validate_source($new_source);
}
if ( $self->can('validate_file') ) {
my $tempfile = $self->_write_temp_file( $rel_path, $new_source );
$self->validate_file($tempfile);
lib/Code/TidyAll/Plugin.pm view on Meta::CPAN
default.
=head2 $plugin->preprocess_source($source)
Receives source code as a string; returns the processed string, or dies with
error. This runs on all plugins I<before> any of the other methods.
=head2 $plugin->transform_source($source)
Receives source code as a string; returns the transformed string, or dies with
error. This is repeated multiple times if --iterations was passed or specified
in the configuration file.
=head2 $plugin->transform_file($file)
Receives filename; transforms the file in place, or dies with error. Note that
the file will be a temporary copy of the user's file with the same basename;
your changes will only propagate back if there was no error reported from any
plugin. This is repeated multiple times if --iterations was passed or specified
in the configuration file.
=head2 $plugin->validate_source($source)
Receives source code as a string; dies with error if invalid. Return value will
be ignored.
=head2 $plugin->validate_file($file)
Receives filename; validates file and dies with error if invalid. Should not
-pt=1
-bt=1
-sbt=1
-bbt=1
-nolq
-npro
-nsfs
--opening-hash-brace-right
--no-outdent-long-comments
-wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="
--iterations=2
t/lib/TestFor/Code/TidyAll/Basic.pm view on Meta::CPAN
like(
$output,
qr/\[tidied\] foo\.txt \(\+TestHelper::Plugin::UpperText\)/s,
"foo.txt ($state)"
) if $state eq 'verbose';
}
}
}
}
sub test_iterations : Tests {
my $self = shift;
my $root_dir = $self->create_dir( { 'foo.txt' => 'abc' } );
my $ct = Code::TidyAll->new(
plugins => { test_plugin('RepeatFoo') => { select => '**/foo*', times => 3 } },
root_dir => $root_dir,
iterations => 2
);
my $file = $root_dir->child('foo.txt');
$ct->process_paths($file);
is( $file->slurp, scalar( 'abc' x 9 ), '3^2 = 9' );
}
sub test_caching_and_backups : Tests {
my $self = shift;
my @chi_or_no_chi = (q{});
( run in 4.347 seconds using v1.01-cache-2.11-cpan-71847e10f99 )