From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 17 Mar 2025 07:34:28 +0000 (+0100)
Subject: Allow linting of entire source file directories.
X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/static/%7B%7Bdb.prefix%7D%7D/condition?a=commitdiff_plain;h=90663c1a9843b2ebf1f1aaa4e70988cfaf3ea853;p=lintplom

Allow linting of entire source file directories.
---

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