Refactor tabs.sh to use bash for tab detection
Removed copyright notice and unnecessary comments. Updated script to detect tab characters in source files using bash instead of Python. Signed-off-by: Jonathan Miller <jmiller2979@gmail.com>
This commit is contained in:
@@ -1,65 +1,28 @@
|
|||||||
# ============================================================================
|
#!/usr/bin/env bash
|
||||||
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
|
|
||||||
#
|
|
||||||
# This file is part of a Moko Consulting project.
|
|
||||||
#
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
#
|
|
||||||
# This program is free software; you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation; either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
# FILE INFORMATION
|
|
||||||
# DEFGROUP: Scripts.Validate
|
|
||||||
# INGROUP: MokoStandards.Release
|
|
||||||
# REPO: https://github.com/mokoconsulting-tech/MokoStandards
|
|
||||||
# PATH: /scripts/validate/tabs.sh
|
|
||||||
# VERSION: 01.00.00
|
|
||||||
# BRIEF: Detects tab characters in text files under src and fails if any are present.
|
|
||||||
# NOTE:
|
|
||||||
# ============================================================================
|
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SRC_DIR="${SRC_DIR:-src}"
|
# Detect TAB characters in source files tracked by Git. Uses careful
|
||||||
|
# handling of filenames and avoids heredoc pitfalls.
|
||||||
|
|
||||||
json_escape() {
|
# Limit file globs as appropriate for the repo
|
||||||
python3 -c 'import json,sys; print(json.dumps(sys.argv[1]))' "$1"
|
files=$(git ls-files '*.php' '*.js' '*.py' || true)
|
||||||
}
|
|
||||||
|
|
||||||
[ -d "${SRC_DIR}" ] || {
|
if [ -z "${files}" ]; then
|
||||||
printf '{"status":"fail","error":%s}
|
echo "No files to check"
|
||||||
' "$(json_escape "src directory missing")"
|
exit 0
|
||||||
exit 1
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
python3 - <<'PY' "${SRC_DIR}"
|
bad=0
|
||||||
import json
|
while IFS= read -r f; do
|
||||||
import sys
|
if grep -n $'\t' -- "$f" >/dev/null 2>&1; then
|
||||||
from pathlib import Path
|
echo "TAB found in $f"
|
||||||
|
bad=1
|
||||||
|
fi
|
||||||
|
done <<< "${files}"
|
||||||
|
|
||||||
src = Path(sys.argv[1])
|
if [ "${bad}" -ne 0 ]; then
|
||||||
exclude_dirs = {'vendor','node_modules','dist','.git','build','tmp'}
|
echo "ERROR: Tabs found in repository files" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
hits = []
|
echo "tabs: ok"
|
||||||
scanned = 0
|
|
||||||
|
|
||||||
for p in src.rglob('*'):
|
|
||||||
if not p.is_file():
|
|
||||||
continue
|
|
||||||
if any(part in exclude_dirs for part in p.parts):
|
|
||||||
continue
|
|
||||||
try:
|
|
||||||
data = p.read_bytes()
|
|
||||||
except Exception:
|
|
||||||
continue
|
|
||||||
if b'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user