Skip to content

Commit

Permalink
Use tidyall instead of custom implementation
Browse files Browse the repository at this point in the history
Same as in os-autoinst, see
os-autoinst/os-autoinst#1795
  • Loading branch information
okurz committed Jan 25, 2022
1 parent 0966958 commit 366782c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ base_state.json
job.json
node_modules
package-lock.json
.tidyall.d/
4 changes: 4 additions & 0 deletions .perltidyrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Workaround needed for handling non-ASCII in files.
# # See <https://github.com/houseabsolute/perl-code-tidyall/issues/84>.
--character-encoding=none
--no-valign
-l=120 # 120 characters per line
-fbl # don't change blank lines
-nsfs # no spaces before semicolons
Expand Down
3 changes: 3 additions & 0 deletions .tidyallrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[PerlTidy]
select = **/*.{pl,pm,t}
argv = --profile=$ROOT/.perltidyrc
2 changes: 1 addition & 1 deletion t/01-test-utilities.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ subtest 'warnings in sub processes are fatal test failures' => sub {
# Give Utils.pm a chance to install $SIG{CHLD}
sleep 1; # uncoverable statement
OpenQA::Test::Utils::_setup_sub_process 'test-process-1'; # uncoverable statement
'' . undef; # uncoverable statement: provoke Perl warning "Use of uninitialized value in concatenation …"
'' . undef; # uncoverable statement: provoke Perl warning "Use of uninitialized value in concatenation …"
};
note "waiting at most $signal_timeout seconds for SIGCHLD (sleep is supposed to be interrupted by SIGCHLD)";
sleep $signal_timeout;
Expand Down
44 changes: 8 additions & 36 deletions tools/tidy
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,24 @@ EOF
exit
}

find-tdy() { find . \( -type d -path '*/container/webui/workdir/db' -prune -type f \) -or \( -name '*.tdy' \) ; }
cleanup() { find-tdy | xargs -r rm ; }

set -eo pipefail

check=
only_changed=false
args=""
selection='--all'
opts=$(getopt -o hco --long help,check,only-changed -n "$0" -- "$@") || usage
eval set -- "$opts"
while true; do
case "$1" in
-h | --help ) usage; shift ;;
-c | --check ) check=true; shift ;;
-o | --only-changed ) only_changed=true; shift ;;
-c | --check ) args+=' --check-only'; shift ;;
-o | --only-changed ) selection='--git'; shift ;;
-- ) shift; break ;;
* ) break ;;
esac
done

trap cleanup EXIT
shift $((OPTIND - 1))
filename=${*:-"$selection"}

if ! command -v perltidy > /dev/null 2>&1; then
echo "No perltidy found, install it first!"
Expand All @@ -54,37 +52,11 @@ if [ "$perltidy_version_found" != "$perltidy_version_expected" ]; then
exit 1
fi

find-files() {
local files=()
[[ -d script ]] && files+=(script/*)
# shellcheck disable=SC2207
files=($(file --mime-type -- * "${files[@]}" | (grep text/x-perl || true) | awk -F':' '{ print $1 }'))
files+=('**.p[ml]' '**.t')
if $only_changed; then
git status --porcelain "${files[@]}" | awk '{ print $2 }'
else
git ls-files "${files[@]}"
fi
}

# go to caller directory
cd "$(dirname "$0")/.."

# just to make sure we are at the right location
test -e tools/tidy || exit 1

cleanup

find-files | xargs perltidy --no-valign --pro=.../.perltidyrc

find-tdy | while read -r file; do
if diff -u "${file%.tdy}" "$file"; then
continue
fi
if [[ -n "$check" ]]; then
echo "RUN tools/tidy script before checkin"
exit 1
else
mv -v "$file" "${file%.tdy}"
fi
done
# shellcheck disable=SC2086
tidyall $args $filename

0 comments on commit 366782c

Please sign in to comment.