From 90663c1a9843b2ebf1f1aaa4e70988cfaf3ea853 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Mon, 17 Mar 2025 08:34:28 +0100 Subject: [PATCH] Allow linting of entire source file directories. --- lintplom | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/lintplom b/lintplom index fa6dc60..9c369d2 100755 --- a/lintplom +++ b/lintplom @@ -3,17 +3,18 @@ set -e # check existence of file, ensure absoluteness of path if [ "$#" -ne 1 ]; then - echo "usage: lintplom FILEPATH" + echo "usage: lintplom TARGET" echo "" echo "arguments:" - echo " FILEPATH - source file to run Python linters against" + echo " TARGET – what to run Python linters against: either an individual source file," + echo " or a directory to scan for those (by their .py endings)" exit 1 fi # check existence of file, ensure absoluteness of path TARGET="$1" -if [ ! -f "$1" ]; then - echo "Must provide valid file path as argument." +if ! [ -f "$1" -o -d "$1" ]; then + echo "Must provide valid file or directory path as argument." exit 1 fi if [ $(echo "${TARGET}" | cut -c1) != '/' ]; then @@ -28,7 +29,11 @@ if [ $(echo "${TARGET}" | cut -d'/' -f'1-3') != "${HOME}" ]; then fi FILE_REQS=requirements.txt DIR_REQS= -cd "$(dirname ${TARGET})" +if [ -d "${TARGET}" ]; then + cd "${TARGET}" +else + cd "$(dirname ${TARGET})" +fi while true; do if [ "$(pwd)" = "${HOME}" ]; then break @@ -67,9 +72,14 @@ fi # run actual tests set +e -echo "\n\n============================[ FLAKE results ]==================================\n" -flake8 "${TARGET}" -echo "\n\n============================[ PYLINT results ]=================================\n" -pylint "${TARGET}" -echo "\n\n============================[ MYPY results ]===================================\n" -mypy "${TARGET}" +for LINTER in flake8 pylint mypy; do + echo "\n=====[ ${LINTER} results ]=====\n" + if [ -d "${TARGET}" ]; then + for FILE in "${TARGET}"/*.py; do + ${LINTER} "${FILE}" + done + else + ${LINTER} "${TARGET}" + fi + echo "" +done -- 2.30.2