Merge remote-tracking branch 'origin/wj' into wilm
# Conflicts: # scripts/check-naming-and-style.sh
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<#
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Day-to-day control of a ShopDB-Flask installation, on the server itself.
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ EXCLUDES=(
|
||||
--exclude-dir=.vs
|
||||
--exclude-dir=versions
|
||||
--exclude-dir=staticdocs
|
||||
--exclude-dir=_transfer
|
||||
--exclude-dir=instance
|
||||
# Local, gitignored scratch notes (see .gitignore devnotes/). Not product
|
||||
# source, never committed, and free to hold pasted logs full of em-dashes
|
||||
# and arrows - grep does not consult .gitignore, so exclude it explicitly.
|
||||
@@ -94,10 +96,20 @@ drop_scratch() { grep -v '^\./devnotes/' || true; }
|
||||
# post-filter, because the flag form cancelled every --include on the command
|
||||
# (see the warning above the EXCLUDES array). Also drops .env, which is local
|
||||
# configuration rather than source.
|
||||
#
|
||||
# scan.log arrived from wj as --exclude=scan.log. Carried here rather than to
|
||||
# the array for the same reason: the flag form would have cancelled the include
|
||||
# lists it sat beside.
|
||||
drop_generated() {
|
||||
grep -vP '^\./(.*/)?(findings\.sarif|report\.md|\.env):' || true
|
||||
grep -vP '^\./(.*/)?(findings\.sarif|report\.md|scan\.log|\.env):' || true
|
||||
}
|
||||
|
||||
# CONTRIBUTING.md documents the conventions by SHOWING violations as examples,
|
||||
# so the naming checks hit it every time. Came from wj as
|
||||
# --exclude=CONTRIBUTING.md; it is a post-filter here because the flag form
|
||||
# cancels every --include on the same command (see the EXCLUDES warning above).
|
||||
drop_contributing() { grep -v '^\./CONTRIBUTING\.md:' || true; }
|
||||
|
||||
INCLUDES_CODE=(
|
||||
--include='*.py'
|
||||
--include='*.vue'
|
||||
@@ -125,6 +137,9 @@ echo "==> Checking for non-ASCII characters..."
|
||||
# archive or compiled artifact that slips past the excludes, which is noise no
|
||||
# author can act on: there is no line to fix. The excludes above are the primary
|
||||
# defence; this is the backstop for whatever they miss.
|
||||
#
|
||||
# wj wrote this as --binary-files=without-match, which is the same behaviour
|
||||
# spelled long-hand; -I is kept for consistency with the rest of the file.
|
||||
NON_ASCII=$(grep -rPnI '[^\x00-\x7F]' "${EXCLUDES[@]}" "${INCLUDES_ALL[@]}" . 2>/dev/null | drop_scratch | drop_generated || true)
|
||||
if [ -n "$NON_ASCII" ]; then
|
||||
echo "FAIL: non-ASCII characters found (em-dashes, smart quotes, arrows, emojis):"
|
||||
@@ -137,8 +152,18 @@ echo "==> Checking for banned shorthand (standalone)..."
|
||||
# Match the word as a standalone identifier: not preceded or followed by underscore/word char
|
||||
# Word boundary in grep is \b but we want to exclude suffix usage like printers_bp
|
||||
# So: match (^|[^a-zA-Z0-9_])(banned)([^a-zA-Z0-9_]|$)
|
||||
# Exclude: docs (CONTRIBUTING.md examples), external code (agent/, installer/), this script
|
||||
# Only check PRODUCT CODE in shopdb/ plugins/ frontend/src/ - not docs, examples, or tools
|
||||
# Exclude C# client code (.cs files) - they're not Python and have different conventions
|
||||
for word in cfg ctx mgr req res; do
|
||||
HITS=$(grep -rPn "(^|[^a-zA-Z0-9_])${word}([^a-zA-Z0-9_]|\$)" "${EXCLUDES[@]}" --include='*.py' --include='*.vue' --include='*.js' --include='*.ts' . 2>/dev/null \
|
||||
HITS=$(grep -rPn --binary-files=without-match \
|
||||
"(^|[^a-zA-Z0-9_])${word}([^a-zA-Z0-9_]|\$)" "${EXCLUDES[@]}" \
|
||||
--include='*.py' --include='*.vue' --include='*.js' --include='*.ts' \
|
||||
shopdb/ plugins/ frontend/src/ 2>/dev/null \
|
||||
| grep -v '/tests\?/' \
|
||||
| grep -v '\.spec\.js' \
|
||||
| grep -v '\.plugins-staged' \
|
||||
| grep -v '\.cs:' \
|
||||
| grep -vP "(^|[^a-zA-Z0-9_])(request_obj|response_obj)" \
|
||||
| drop_scratch \
|
||||
| drop_generated \
|
||||
@@ -152,7 +177,8 @@ for word in cfg ctx mgr req res; do
|
||||
done
|
||||
|
||||
echo "==> Checking for snake_case DB tablenames..."
|
||||
SNAKE_TABLES=$(grep -rPn "__tablename__\s*=\s*['\"][^'\"]*_" "${EXCLUDES[@]}" --include='*.py' . 2>/dev/null | drop_scratch || true)
|
||||
SNAKE_TABLES=$(grep -rPn "__tablename__\s*=\s*['\"][^'\"]*_" "${EXCLUDES[@]}" \
|
||||
--include='*.py' . 2>/dev/null | drop_scratch | drop_contributing || true)
|
||||
if [ -n "$SNAKE_TABLES" ]; then
|
||||
echo "FAIL: snake_case __tablename__ found (must be lowercase concatenated):"
|
||||
echo "$SNAKE_TABLES"
|
||||
@@ -161,7 +187,8 @@ if [ -n "$SNAKE_TABLES" ]; then
|
||||
fi
|
||||
|
||||
echo "==> Checking for snake_case DB column attrs..."
|
||||
SNAKE_COLS=$(grep -rPn "^\s+[a-z]+_[a-z_]+\s*=\s*db\.Column" "${EXCLUDES[@]}" --include='*.py' . 2>/dev/null | drop_scratch || true)
|
||||
SNAKE_COLS=$(grep -rPn "^\s+[a-z]+_[a-z_]+\s*=\s*db\.Column" "${EXCLUDES[@]}" \
|
||||
--include='*.py' . 2>/dev/null | drop_scratch | drop_contributing || true)
|
||||
if [ -n "$SNAKE_COLS" ]; then
|
||||
echo "FAIL: snake_case db.Column attribute found (must match column name, no underscores):"
|
||||
echo "$SNAKE_COLS"
|
||||
@@ -179,7 +206,8 @@ if [ -n "$SNAKE_FK" ]; then
|
||||
fi
|
||||
|
||||
echo "==> Checking for snake_case API params in frontend (DB-mirrored fields)..."
|
||||
SNAKE_FE=$(grep -rPn "params\.(machine_id|location_id|vendor_id|type_id|business_unit_id|model_id|status_id|operating_system_id|asset_id|user_id|is_active|is_shopfloor)" "${EXCLUDES[@]}" --include='*.vue' --include='*.js' --include='*.ts' . 2>/dev/null | drop_scratch || true)
|
||||
SNAKE_FE=$(grep -rPn "params\.(machine_id|location_id|vendor_id|type_id|business_unit_id|model_id|status_id|operating_system_id|asset_id|user_id|is_active|is_shopfloor)" "${EXCLUDES[@]}" \
|
||||
--exclude=DEVELOPMENT-STANDARDS.md --include='*.vue' --include='*.js' --include='*.ts' . 2>/dev/null | drop_scratch || true)
|
||||
if [ -n "$SNAKE_FE" ]; then
|
||||
echo "FAIL: snake_case API params in frontend (must match DB column names without underscores):"
|
||||
echo "$SNAKE_FE"
|
||||
@@ -327,7 +355,9 @@ SITE_NETS='10\.134\.48\.|10\.48\.249\.'
|
||||
# itself is fine to mention; the tenant is not.
|
||||
SITE_TENANTS='geaero''spaceqa'
|
||||
SITE_PATTERNS="${SITE_HOST}|${SITE_DOMAIN}|\bwjs\b|${SITE_NAME}|${SITE_NETS}|${SITE_TENANTS}"
|
||||
SITE_HITS=$(grep -rPni "$SITE_PATTERNS" "${EXCLUDES[@]}" \
|
||||
SITE_HITS=$(grep -rPni --binary-files=without-match \
|
||||
"$SITE_PATTERNS" "${EXCLUDES[@]}" \
|
||||
--exclude=README.md \
|
||||
--include='*.py' --include='*.vue' --include='*.js' \
|
||||
--include='*.ps1' --include='*.psm1' --include='*.sh' --include='*.iss' \
|
||||
--include='*.json' --include='*.html' \
|
||||
@@ -336,6 +366,7 @@ SITE_HITS=$(grep -rPni "$SITE_PATTERNS" "${EXCLUDES[@]}" \
|
||||
| grep -v '\.spec\.js:' \
|
||||
| grep -v 'site_imports/' \
|
||||
| grep -v 'installer/bundle/' \
|
||||
| grep -v 'offline-packages/' \
|
||||
| grep -v '\.plugins-staged/' \
|
||||
| grep -v 'check-naming-and-style\.sh' \
|
||||
| grep -v 'export-github\.sh' \
|
||||
|
||||
Reference in New Issue
Block a user