home · contact · privacy
Allow linting of entire source file directories.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 17 Mar 2025 07:34:28 +0000 (08:34 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 17 Mar 2025 07:34:28 +0000 (08:34 +0100)
lintplom

index fa6dc60a6520fa70e518d3b3ee69e9652b94af0a..9c369d20adce1f1185c1f359e4695eba8f216d2c 100755 (executable)
--- 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