From c6375c563e0ece32dcdb3b11841c72f63c96619e Mon Sep 17 00:00:00 2001 From: Christian Lopez Espinola Date: Mon, 31 Aug 2026 09:44:07 +0200 Subject: [PATCH] feat: Allow xb-cspell to check only staged files, fixes #74 Adds an optional 'staged' argument to xb-cspell that runs cspell against only the files staged for commit (git diff --cached), making it usable in pre-commit hooks. With no argument the command still lints the whole module. Co-Authored-By: Claude Opus 4.8 --- commands/web/xb-cspell | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/commands/web/xb-cspell b/commands/web/xb-cspell index 285d18b..0dd61b6 100755 --- a/commands/web/xb-cspell +++ b/commands/web/xb-cspell @@ -2,12 +2,27 @@ ## #ddev-generated ## Description: Check for spelling errors with cspell. -## Usage: xb-cspell -## Example: ddev xb-cspell # Check for spelling errors.\nddev cspell # Same, via alias. +## Usage: xb-cspell [staged] +## Example: ddev xb-cspell # Check for spelling errors across the module.\nddev xb-cspell staged # Check only files staged for commit. ## Aliases: cspell,spell ## ExecRaw: false ## Flags: [] +## AutocompleteTerms: ["staged"] cd "$DDEV_COMPOSER_ROOT/$DDEV_DOCROOT/modules/contrib/canvas" || exit 1 -npm run lint:cspell +case "$1" in + "staged") + staged_files=$(git diff --cached --name-only --diff-filter=ACMR) + if [ -z "$staged_files" ]; then + echo "Nothing staged; skipping cspell." + exit 0 + fi + npx cspell --no-progress --no-must-find-files $staged_files + ;; + "") npm run lint:cspell ;; + *) + echo "Invalid argument: $1" + exit 1 + ;; +esac