Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- id: perltidy
name: 'perltidy'
entry: run-perltidy.sh
args: [--min-version=20021130]
files: '\.(pl|pm|t|PL)$'
language: 'script'
description: "Runs `perltidy`, requires script in PATH"
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ Add this to your `.pre-commit-config.yaml`
.perlcriticrc.
- `perltidy` - Runs `perltidy -pbp -nst -w -b`. Settings can be overridden by
.perltidyrc.

### Using a minimum version of `perltidy`

Pass `--min-version` as an argument for the perltidy hook.

- repo: https://github.com/henryykt/pre-commit-perl
rev: v0.0.4
hooks:
- id: perlcritic
- id: perltidy
args: [--min-version=20190601]
35 changes: 35 additions & 0 deletions run-perltidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,41 @@

set -eu

# default min-version to "oldest we know about"
# the oldest version on metacpan is 20021130
minversion=20021130

# bash arguments are ... fun
# the following came from https://bl.ocks.org/magnetikonline/22c1eb412daa350eeceee76c97519da8
ARGUMENT_LIST=(
"min-version"
);
# read arguments
opts=$(getopt \
--longoptions "$(printf "%s:," "${ARGUMENT_LIST[@]}")" \
--name "$(basename "$0")" \
--options "" \
-- "$@"
)
eval set --$opts
while [[ $# -gt 0 ]]; do
case "$1" in
--min-version)
minversion=$2
shift 2
;;
*)
break
;;
esac
done

# check for minversion
if ! perl -MPerl::Tidy=${minversion} -e1 >/dev/null 2>&1; then
echo "Please update Perl::Tidy to at least version ${minversion}";
exit 1;
fi

cmd=perltidy
if ! command -v "${cmd}" >/dev/null 2>&1; then
echo "This check needs ${cmd} from http://perltidy.sourceforge.net/."
Expand Down