From 366782cb75534e1185f66fc03c851e1405c16208 Mon Sep 17 00:00:00 2001 From: Oliver Kurz Date: Fri, 21 Jan 2022 17:14:06 +0100 Subject: [PATCH] Use tidyall instead of custom implementation Same as in os-autoinst, see https://github.com/os-autoinst/os-autoinst/pull/1795 --- .gitignore | 1 + .perltidyrc | 4 ++++ .tidyallrc | 3 +++ t/01-test-utilities.t | 2 +- tools/tidy | 44 ++++++++----------------------------------- 5 files changed, 17 insertions(+), 37 deletions(-) create mode 100644 .tidyallrc diff --git a/.gitignore b/.gitignore index ed57a8f7eba..dd83cce690b 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ base_state.json job.json node_modules package-lock.json +.tidyall.d/ diff --git a/.perltidyrc b/.perltidyrc index b6519f3e7c4..24a69487529 100644 --- a/.perltidyrc +++ b/.perltidyrc @@ -1,3 +1,7 @@ +# Workaround needed for handling non-ASCII in files. +# # See . +--character-encoding=none +--no-valign -l=120 # 120 characters per line -fbl # don't change blank lines -nsfs # no spaces before semicolons diff --git a/.tidyallrc b/.tidyallrc new file mode 100644 index 00000000000..7e0352c5729 --- /dev/null +++ b/.tidyallrc @@ -0,0 +1,3 @@ +[PerlTidy] +select = **/*.{pl,pm,t} +argv = --profile=$ROOT/.perltidyrc diff --git a/t/01-test-utilities.t b/t/01-test-utilities.t index 9d67d52c595..6a4529855d5 100644 --- a/t/01-test-utilities.t +++ b/t/01-test-utilities.t @@ -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; diff --git a/tools/tidy b/tools/tidy index 48bc400bcfb..800af99ccce 100755 --- a/tools/tidy +++ b/tools/tidy @@ -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!" @@ -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