TIDYALL(1)
π TIDYALL(1) π
okay so bestie, this is the manual for tidyall, straight from the User Contributed Perl Documentation gang, and she is literally your all-in-one code tidier and validator. no cap, sheβs about to make your whole project glow. π«Άβ¨
πΈ NAME πΈ
tidyall β Your all-in-one code tidier and validator π
β¨ SYNOPSIS β¨
first things first: drop a tidyall.ini or .tidyallrc at the top of your project, like this π
# Create a tidyall.ini or .tidyallrc at the top of your project
#
[PerlTidy]
select = **/*.{pl,pm,t}
argv = -noll -it=2
[PerlCritic]
select = lib/**/*.pm
ignore = lib/UtterHack.pm
argv = -severity 3
# Process all files in the current project,
# look upwards from cwd for conf file
#
% tidyall -a
# Process one or more specific files,
# look upwards from the first file for conf file
#
% tidyall file [file...]
# Process a directory recursively
#
% tidyall -r dir
π¦ DESCRIPTION π¦
okay so there are a lot of great code tidiers and validators out there, and tidyall makes them available from a single unified interface. sheβs the group chat that finally gets everyone to cooperate. π
You can run tidyall on a single file or on an entire project hierarchy, and configure which tidiers/validators are applied to which files. tidyall will back up files beforehand, and for efficiency will only consider files that have changed since they were last processed. obsessed with a queen who remembers things. β¨
π§ What's a tidier? What's a validator? π§
A tidier transforms a file so as to improve its appearance without changing its semantics. Examples include perltidy, podtidy and js-beautify (https://npmjs.org/package/js-beautify). itβs giving βsame girl, better outfit.β π
A validator analyzes a file for some definition of correctness. Examples include perlcritic, podchecker and jshint (http://www.jshint.com/). sheβs the friend who checks your homework before you submit it. π
Many tidiers are also validators, e.g. perltidy will throw an error on badly formed Perl. multitasking icon behavior.
To use a tidier or validator with tidyall it must have a corresponding plugin class, usually under the prefix Code::TidyAll::Plugin::. This distribution comes with plugins for:
- Perl:
perlcritic,perltidy,perltidy-sweet - Pod:
podchecker,podspell,podtidy - Mason:
masontidy - JavaScript:
js-beautify,jshint,jslint - JSON:
JSON - CSS:
cssunminifier - PHP:
phpcs - Misc:
Code::TidyAll::Plugin::SortLines
See Code::TidyAll::Plugin for information about creating your own plugin. build your own bestie, iykyk. π οΈπ
π USING TIDYALL π
tidyall works on a project basis, where a project is just a directory hierarchy of files. svn or git working directories are typical examples of projects. very βyour repo is your kingdomβ energy. π
The top of the project is called the root directory. In the root directory you'll need a config file named tidyall.ini or .tidyallrc; it defines how various tidiers and validators will be applied to the files in your project. this is the master plan, the vibe check, the whole blueprint. πΊοΈβ¨
tidyall will find your root directory and config file automatically depending on how you call it:
tidyall file [file...]βtidyallwill search upwards from the first file for the conf file.tidyall -p/--pipe fileβtidyallwill search upwards from the specified file for the conf file.tidyall -a/--allortidyall -s/--svnortidyall -g/--gitβtidyallwill search upwards from the current working directory for the conf file.tidyall -a --root-dir dirβtidyallwill expect to find the conf file in the specified root directory.
You can also pass --conf-name to change the name that is searched for, or --conf-file to specify an explicit path. no more guessing games, bestie. π΅οΈββοΈπ
π CONFIGURATION π
The config file (tidyall.ini or .tidyallrc) is in Config::INI format. Here's a sample:
ignore = **/*.bak
[PerlTidy]
select = **/*.{pl,pm,t}
argv = -noll -it=2
[PerlCritic]
select = lib/**/*.pm
ignore = lib/UtterHack.pm lib/OneTime/*.pm
argv = -severity 3
[PodTidy]
select = lib/**/*.{pm,pod}
In order, the four sections declare:
- Always ignore
*.bakfiles. - Apply
PerlTidywith settings-noll -it=2to all*.pl,*.pm, and*.tfiles. - Apply
PerlCriticwith severity 3 to all Perl modules somewhere underneathlib/, except forlib/UtterHack.pm. - Apply
PodTidywith default settings to all*.pmand*.podfiles underneathlib/.
πΈ Standard configuration elements πΈ
[class]or[class description]β The header of each section refers to atidyallplugin. The name is automatically prefixed withCode::TidyAll::Plugin::unless it begins with a+, e.g.
; Uses plugin Code::TidyAll::Plugin::PerlTidy
;
[PerlTidy]
; Uses plugin My::TidyAll::Plugin
;
[+My::TidyAll::Plugin]
You can also include an optional description after the class. The description will be ignored and only the first word will be used for the plugin. This lets you list a plugin more than once, with different configuration each time. For example, two different PerlCritic configurations:
; Be brutal on libraries
;
[PerlCritic strict]
select = lib/**/*.pm
argv = --brutal
; but gentle on scripts
;
[PerlCritic lenient]
select = bin/**/*.pl
argv = --gentle
Warning: If you simply list the same plugin twice with no description (or the same description), one of them will be silently ignored. she will literally ghost one of them, no cap. ππ
selectβ One or moreFile::Zglobpatterns, separated by whitespace or on multiple lines, indicating which files to select. At least one is required. e.g.
; All .t and .pl somewhere under bin and t;
; plus all .pm files directly under lib/Foo and lib/Bar
;
select = {bin,t}/**/*.p[lm]
select = lib/{Foo,Bar}/*.pm
; All .txt files anywhere in the project
;
select = **/*.txt
The pattern is relative to the root directory and should have no leading slash. All standard glob characters (*, ?, [], {}) will work; in addition, ** can be used to represent zero or more directories. See File::Zglob documentation for more details. globby queen. π
ignoreβ One or moreFile::Zglobpatterns, separated by whitespace or on multiple lines, indicating which files to ignore. This is optional and overridesselect. e.g.
; All .pl files anywhere under bin, except bin/awful.pl or anywhere
; under bin/tmp
;
select = bin/**/*.pl
ignore = bin/awful.pl bin/tmp/**/*.pl
Ignore patterns can also be specified at the beginning of the file before any plugin section was started, thus making them global. These ignores will be applied for all plugins. global ignore list, very main character. π
shebangβ One or more words on multiple lines, indicating which shebang lines to accept. This is optional and further filtersselect. e.g.
; All files with no extension anywhere under bin that include a "perl" or
; "perl5" shebang line.
select = bin/**/*
ignore = bin/**/*.*
shebang = perl
shebang = perl5
only_modesβ A list of modes, separated by whitespace. e.g.
only_modes = test cli
The plugin will only run if one of these modes is passed to tidyall via -m or --mode. sheβs on duty only for these vibes. π
except_modesβ A list of modes, separated by whitespace. e.g.
except_modes = commit editor
The plugin will not run if one of these modes is passed to tidyall via -m or --mode. sheβs taking a break for these, respectfully. π
argvβ Many plugins (such asperltidy,perlcriticandpodtidy) take this option, which specifies arguments to pass to the underlying command-line utility. literal βhereβs what you tell the toolβ energy. π οΈweightβ This is an integer that is used to sort plugins. By default, tidier plugins run first, then validator plugins, with each group sorted alphabetically. sorting the lineup, very backstage pass. ποΈ
π PLUGIN ORDER AND ATOMICITY π
If multiple plugins match a file, tidiers are applied before validators so that validators are checking the final result. Within those two groups, the plugins are applied in alphabetical order by plugin name/description. orderly, iconic, no chaos. β¨
You can also explicitly set the weight of each plugin. By default, tidiers have a weight of 50 and validators have a weight of 60. You can set the weight to any integer to influence when the plugin runs. adjust the queued order, bestie. π
The application of multiple plugins is all-or-nothing. If an error occurs during the application of any plugin, the file is not modified at all. thatβs the drama of it all: one tiny oopsie and the whole glow-up gets cancelled. πβ¨
π COMMAND-LINE OPTIONS π
okay bestie, here's the whole menu of flags. pick your fighter β¨
-a,--allβ process, like, everything. it does a recursive search for all files in the project hierarchy starting at the root, and processes any file that matches at least one plugin in the configuration. go off π-i,--ignoreβ ignore matching files. this one uses zglob syntax, and yes you can pass it more than once (stack 'em, queen) π-g,--gitβ process all added or modified files in the current git working directory. git girlies rise π¦-l,--listβ list each file along with the list of plugins it matches (files without any matches are just skipped, rude but okay). it does not actually process any files, and it does not care whether files are cached. generally used with-a,-g, or-s. e.g.
% tidyall -a -l
lib/CHI.pm (PerlCritic, PerlTidy, PodTidy)
lib/CHI/Benchmarks.pod (PodTidy)
lib/CHI/CacheObject.pm (PerlCritic, PerlTidy, PodTidy)
-m,--modeβ optional mode that can affect which plugins run. defaults to"cli". see "MODES" down below π-p path,--pipe pathβ read content from STDIN and write the resulting content to STDOUT. if it's successful,tidyallexits with status 0. if an error occurs,tidyalloutputs the error message to STDERR, mirrors the input content to STDOUT with no changes, and exits with status 1. the mirroring means you can safely pipe to your destination regardless of whether an error occurs. literally so thoughtful π«Ά
when you specify this option you must specify exactly one filename, relative or absolute, which will be used to determine which plugins to apply and also where the root directory and configuration file are. the file will not actually be read and does need even need to exist. (yes that's what the manpage says, no I'm not fixing it, iykyk π)
this option implies --no-backups and --no-cache (since there's no actual file) and --quiet (since we don't want to mix extraneous output with the tidied result).
# Read from STDIN and write to STDOUT, with appropriate plugins
# for some/path.pl (which need not exist)
#
% tidyall --pipe some/path.pl
-r,--recursiveβ recursively enter any directories listed on the command-line and process all the files within. by default, directories encountered on the command-line will generate a warning (so like, heads up β οΈ)-j,--jobsβ specify how many jobs should run in parallel. by default we only run 1, but if you have multiple cores this should causetidyallto run faster, especially on larger code bases. more cores = more slay π₯-s,--svnβ process all added or modified files in the current svn working directory.-q,--quietβ suppress output except for errors. shhh π€«-v,--verboseβ show extra output. give me the lore π-I path1,path2,...β add one or more library paths to@INC, like Perl's-I. useful if--tidyall-classor plugins are in an alternate lib directory.--backup-ttl durationβ amount of time before backup files can be purged. can be a number of seconds or any string recognized byTime::Duration::Parse, e.g."4h"or"1day". defaults to"1h".--check-onlyβ instead of actually tidying files, check if each file is tidied (i.e. if its tidied version is equal to its current version) and consider it an error if not. this is used byTest::Code::TidyAlland the svn and git pre-commit hooks, for example, to enforce that you've tidied your files. the vibe check of file tidiness π--plugins nameβ only run the specified plugins. the name should match the name given in the config file exactly, including a leading"+"if one exists.
this overrides the --mode option.
note that plugins will still only run on files which match their "select" and "ignore" configuration.
--conf-file pathβ specify relative or absolute path to conf file, instead of searching for it in the usual way.--conf-name nameβ specify a conf file name to search for instead of the defaults ("tidyall.ini"/".tidyallrc").--data-dir pathβ contains data like backups and cache. defaults toroot_dir/.tidyall.d--iterations countβ run each tidier transformcounttimes. 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. perlcritic and jshint would still only be run once. validators said "one and done" π
--no-backupsβ don't backup files before processing.--no-cacheβ don't cache last processed times; process all files every time. see also--refresh-cache.--no-cleanupβ don't clean up temporary files.--output-suffix suffixβ suffix to add to a filename before outputting the modified version, e.g.".tdy". default is none, which means overwrite the file. (overwrite is giving main character energy, ngl)--refresh-cacheβ erase any existing cache info before processing each file, then write new cache info. see also--no-cache.--root-dirβ specify root directory explicitly. usually this is inferred from the specified files or the current working directory.--tidyall-class classβ subclass to use instead ofCode::TidyAll.--versionβ show the version ofCode::TidyAllthat this script invokes.-h,--helpβ print help message
π Specifying options in configuration π
almost any command-line option can be specified at the top of the config file, above the plugin sections. just 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. sorry config file, you lose π
inc
you can specify "inc" as a global configuration option outside of any plugin's section. you can specify this more than once to include multiple directories. any directories you list here will be prepended to @INC before loading plugins or a "tidyall_class".
π EXIT STATUS π
"tidyall" will exit with status 1 if any errors occurred while processing files, and 0 otherwise. binary queen β it's either fine or it's not β¨
π¦ MODES π¦
you can use tidyall in a number of different contexts, and you may not want to run all plugins in all of them. (like, read the room, plugins.)
you can pass a mode to tidyall via -m or --mode, and then specify that certain plugins should only be run in certain modes (via "only_modes") or should be run in all but certain modes (via "except_modes").
examples of modes:
"cli"β when invokingtidyallexplicitly from the command-line with no mode specified"editor"β when invoking from an editor"commit"β when using a commit hook likeCode::TidyAll::SVN::PrecommitorCode::TidyAll::Git::Precommit"test"β when usingTest::Code::TidyAll
now since perlcritic is a bit time-consuming, you might only want to run it during tests and explicit command-line invocation:
[PerlCritic]
select = lib/**/*.pm
only_modes = test cli
...
or you could specify that it be run in all modes except the editor:
[PerlCritic]
select = lib/**/*.pm
except_modes = editor
...
if you specify neither "only_modes" nor "except_modes" for a plugin, then it will always run. default behavior is "i'm everywhere" π
π LAST-PROCESSED CACHE π
"tidyall" keeps track of each file's signature after it was last processed. on subsequent runs, it will only process a file if its signature has changed. the cache is kept in files under the data dir.
you can force a refresh of the cache with --refresh-cache, or turn off the behavior entirely with --no-cache. memory loss on demand π
π§ BACKUPS π§
"tidyall" will backup each file before modifying it. the timestamped backups are kept in a separate directory hierarchy under the data dir.
old backup files will be purged automatically as part of occasional "tidyall" runs. the duration specified in --backup-ttl indicates both the minimum amount of time backups should be kept, and the frequency that purges should be run. it may be specified as "30m" or "4 hours" or any string acceptable to Time::Duration::Parse. it defaults to "1h" (1 hour).
you can turn off backups with --no-backups. (bold move but ok π)
π MISSING" PREREQS π
the "Code::TidyAll" distribution intentionally does not depend on the prereqs needed for each plugin. this means that if you want to use the perltidy, you must install the Perl::Tidy module manually. yes, manually. your problem now, bestie π«Ά
β RELATED TOOLS β
etc/editors/tidyall.elhttps://raw.github.com/autarch-code/perl-code-tidyall/master/etc/editors/tidyall.elandetc/editors/tidyall.vimhttps://raw.github.com/autarch-code/perl-code-tidyall/master/etc/editors/tidyall.vimin this distribution contains Emacs and Vim commands for running"tidyall"on the current buffer. you can assign this to the keystroke of your choice (e.g. ctrl-t or ,t). editor girlies we are so back πCode::TidyAll::SVN::Precommitimplements a subversion pre-commit hook that checks if all files are tidied and valid according to"tidyall", and rejects the commit if not. rejected, blocked, unfollowed πCode::TidyAll::Git::PrecommitandCode::TidyAll::Git::Prereceiveimplement git pre-commit and pre-receive hooks, respectively, that check if all files are tidied and valid according to"tidyall".Test::Code::TidyAllis a testing library to check that all the files in your project are in a tidied and valid state. tests + tidiness = the duo we didn't know we needed β¨
π KNOWN BUGS π
- does not yet work on Windows
that's it, that's the whole list. windows besties i'm so sorry, it's not you it's the code π
π AUTHOR π
Jonathan Swartz
π ACKNOWLEDGMENTS π
thanks to Jeff Thalhammer for helping me refine this API. thanks to Jeff for perlcritic, Steve Hancock for perltidy, and all the other authors of great open source tidiers and validators. legends only π«Άβ¨
and that's the whole page, bestie β perl v5.42.0, 2024-03-08, TIDYALL(1). now go tidy something, you beautiful icon πΈπ¦π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Code-TidyAll 0.840.0-bp160.1.4 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms