labels: one module knows how to draw a code, seven views stop guessing
Three core pages and four plugin pages each imported qrcode and jsbarcode directly, and each carried its own answer to the same questions: what margin, what width, which error correction, how big a module must be before a scanner can read it. The answers had already drifted - margin 0 in one place and 2 in another, width 150 against 160 - and on a label that is the difference between a sticker that scans and one that does not. frontend/src/utils/codes.js owns it now: the label-stock presets, the quiet-zone and margin defaults, CODE128 with no printed value, and the printer-resolution arithmetic that only the Tech Tools generator had. A view passes what is specific to its own label and nothing else - MachineBadge still asks for CODE39, because the badge readers predate the shop-floor scanners and decode nothing else, and that is exactly the kind of thing a call site should say out loud. views/print/qrLogo.js is folded in rather than left as a second half-shared helper that only some of the pages reached into. The check script now fails a build that imports either library outside that module. Without it this re-forks within a month: the next label page starts by copying the nearest existing one, which is how it happened the first time. Tests cover the part no amount of looking at a screen verifies - a QR that looks fine at 96 dpi on a monitor can be unreadable at 203 dpi on half-inch stock.
This commit is contained in:
@@ -140,6 +140,24 @@ fi
|
||||
# cannot see and did not choose. Use a setting with a NEUTRAL default, a
|
||||
# site-namespaced directory (scripts/site_imports/<site>/), or seed data.
|
||||
#
|
||||
# Code generation lives in one module. Seven views were importing qrcode and
|
||||
# jsbarcode directly, each with its own margin, width and error correction, and
|
||||
# the answers had already drifted - which on a label means one page scans and
|
||||
# another does not. frontend/src/utils/codes.js owns that knowledge now; a view
|
||||
# passes what is specific to its label and nothing else.
|
||||
echo "==> Checking that only the shared module imports the code libraries..."
|
||||
CODE_LIB_IMPORTS=$(grep -rn "from ['\"]\(qrcode\|jsbarcode\)['\"]" \
|
||||
--include='*.vue' --include='*.js' \
|
||||
frontend/src plugins/ 2>/dev/null \
|
||||
| grep -v 'frontend/src/utils/codes\.js' \
|
||||
| grep -v '\.plugins-staged/' || true)
|
||||
if [ -n "$CODE_LIB_IMPORTS" ]; then
|
||||
echo "FAIL: import qrcode/jsbarcode through @/utils/codes, not directly:"
|
||||
echo "$CODE_LIB_IMPORTS"
|
||||
echo
|
||||
VIOLATIONS=$((VIOLATIONS + 1))
|
||||
fi
|
||||
|
||||
# ENFORCING. It was report-only while the backlog was worked off, and the hit
|
||||
# count then did not move for weeks - a rule that only prints is read as no rule.
|
||||
# Set SITE_LITERALS_ENFORCE=0 to drop back to reporting for a local run.
|
||||
|
||||
Reference in New Issue
Block a user