From ada7aa19ce090c6054ae1f1f51e0c12127cf040a Mon Sep 17 00:00:00 2001 From: Jonathan Smith <jonathan1055@sandfordsolutions.com> Date: Sat, 22 Feb 2025 15:59:40 +0000 Subject: [PATCH 1/3] Ignore vendor and node_modules --- scripts/run-local-checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-local-checks.sh b/scripts/run-local-checks.sh index e39e5af5..5f0802f3 100755 --- a/scripts/run-local-checks.sh +++ b/scripts/run-local-checks.sh @@ -27,7 +27,7 @@ composer install EXIT_CODE=0 npx cspell --show-suggestions --show-context --no-progress --dot {**,.**} || EXIT_CODE=$((EXIT_CODE+1)) ESLINT_FIX=$([[ "$1" == "fix" ]] && echo "--fix" || echo ""); -npx eslint --no-error-on-unmatched-pattern --ext=.yml $ESLINT_FIX . && echo "ESLint passed." || EXIT_CODE=$((EXIT_CODE+1)) +npx eslint --no-error-on-unmatched-pattern --ignore-pattern=vendor --ignore-pattern=node_modules --ext=.yml $ESLINT_FIX . && echo "ESLint passed." || EXIT_CODE=$((EXIT_CODE+1)) [[ "$1" == "fix" ]] && vendor/bin/phpcbf --colors scripts/*.php -s vendor/bin/phpcs --colors scripts/*.php -s && echo "PHPCS passed." || EXIT_CODE=$((EXIT_CODE+1)) shellcheck scripts/*.sh && echo "Shellcheck passed." || EXIT_CODE=$((EXIT_CODE+1)) -- GitLab From 403c59f14849c54c7f175f750ddff2a1f5e7e915 Mon Sep 17 00:00:00 2001 From: Jonathan Smith <jonathan1055@sandfordsolutions.com> Date: Sat, 22 Feb 2025 16:25:34 +0000 Subject: [PATCH 2/3] Add debug argument to unformatted-links.php for less verbose option --- scripts/unformatted-links.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/unformatted-links.php b/scripts/unformatted-links.php index 09349dc7..4d31d426 100644 --- a/scripts/unformatted-links.php +++ b/scripts/unformatted-links.php @@ -7,56 +7,58 @@ * Arguments: * -p --path path Path to search in. Default is 'docs'. Do not include *. * Partial paths will be matched. - * -v --verbose Show verbose debug output. + * -d --debug Show debug output. + * -v --verbose Show more verbose detailed output. */ // Get the options. -$options = getopt('p:v', ['path:', 'verbose']); -$quiet = !array_key_exists('v', $options) && !array_key_exists('verbose', $options); +$options = getopt('p:dv', ['path:', 'debug', 'verbose']); +$verbose = array_key_exists('v', $options) || array_key_exists('verbose', $options); +$debug = $verbose || array_key_exists('d', $options) || array_key_exists('debug', $options); $path = $options['p'] ?? $options['path'] ?? './docs'; -$quiet ?: print "quiet=$quiet\npath=$path\n"; +!$debug ?: print "path=$path\ndebug=$debug\nverbose=$verbose\n"; $found = 0; $code_block = FALSE; // Allow for optional / before second { } pattern for partial paths. $files = array_values(array_unique(glob($path . '{,/}{*.md,**/*.md}', GLOB_BRACE))); -$quiet ?: print ".md files found: " . count($files) . "\n" . print_r($files, TRUE) . "\n"; +!$debug ?: print ".md files found: " . count($files) . "\n" . print_r($files, TRUE) . "\n"; foreach ($files as $f => $filename) { $lines = file($filename); - $quiet ?: print "===== file {$f} = {$filename}\nlines=" . print_r($lines, TRUE) . PHP_EOL; + !$verbose ?: print "===== file {$f} = {$filename}\nlines=" . print_r($lines, TRUE) . PHP_EOL; foreach ($lines as $lnum => $text) { switch (TRUE) { // Detect when a code block begins and ends. case strstr($text, "```"): $code_block = !$code_block; - $quiet ?: print $lnum . ' $code_block changed to ' . ($code_block ? 'true' : 'false') . ' in: ' . $text; + !$verbose ?: print $lnum . ' $code_block changed to ' . ($code_block ? 'true' : 'false') . ' in: ' . $text; break; // If the line does not contain http or we are still in a code block then // move on to the next line. case !stristr($text, 'http') || $code_block: - $quiet ?: print $lnum . ' No http or still in code block in: ' . $text; + !$verbose ?: print $lnum . ' No http or still in code block in: ' . $text; break; // If the http is part of an inline code block then it is OK. case preg_match('/`.*http.*`/', $text, $matches): - $quiet ?: print $lnum . ' Found inline code with http so ignore: ' . $text; - $quiet ?: print_r($matches, TRUE); + !$verbose ?: print $lnum . ' Found inline code with http so ignore: ' . $text; + !$verbose ?: print_r($matches, TRUE); break; // If the http link is properly formatted with [text](url) then it is OK. // Note that this only checking the markup, not validating the url format. case preg_match('/\[.+\]\(http.+\)/', $text, $matches): - $quiet ?: print $lnum . ' Link is correctly formatted in ' . $text . '$matches=' . print_r($matches, TRUE) . PHP_EOL; + !$verbose ?: print $lnum . ' Link is correctly formatted in ' . $text . '$matches=' . print_r($matches, TRUE) . PHP_EOL; break; // Report all remaining 'http' as these are formatted incorrectly. default: print str_repeat('-', 80) . "\n$filename:" . ($lnum + 1) . "\n$text"; $found++; - $quiet ?: print $lnum . ' Found bad link in ' . $text . '$found=' . $found . PHP_EOL; + !$verbose ?: print $lnum . ' Found bad link in ' . $text . '$found=' . $found . PHP_EOL; break; } @@ -65,5 +67,5 @@ foreach ($files as $f => $filename) { $found > 0 ? print str_repeat('-', 80) . "\nTo fix these links use the syntax: [text to show](url)\n" : NULL; print "Unformatted links: Files searched in {$path}: " . count($files) . ", Issues found: {$found}\n"; $exit_code = $found ? 1 : 0; -$quiet ?: print "Ending with exit_code {$exit_code}" . PHP_EOL; +!$debug ?: print "Ending with exit_code {$exit_code}" . PHP_EOL; exit($exit_code); -- GitLab From c2ffecc267cc81ee297eac96463d60e70b730cca Mon Sep 17 00:00:00 2001 From: Jonathan Smith <jonathan1055@sandfordsolutions.com> Date: Sat, 22 Feb 2025 16:26:07 +0000 Subject: [PATCH 3/3] add debug argument to run-local-checks.sh --- scripts/run-local-checks.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/run-local-checks.sh b/scripts/run-local-checks.sh index 5f0802f3..b4651cfa 100755 --- a/scripts/run-local-checks.sh +++ b/scripts/run-local-checks.sh @@ -1,9 +1,10 @@ #!/bin/bash -# Launch from the root of this project: "./scripts/run-local-checks.sh [fix] [clean]". +# Launch from the root of this project: "./scripts/run-local-checks.sh [fix] [debug] [clean]". # # Optional arguments: # fix - to run the fixer options of eslint and phpcs. +# debug - to show verbose output. # clean - to remove the installed software and files copied from assets. # # Helper script to run all the checks that will be run via GitLab CI. @@ -25,13 +26,16 @@ php scripts/prepare-cspell.php npm install composer install EXIT_CODE=0 -npx cspell --show-suggestions --show-context --no-progress --dot {**,.**} || EXIT_CODE=$((EXIT_CODE+1)) +NO_PROGRESS=$([[ "$1" == "debug" ]] && echo "" || echo "--no-progress"); +npx cspell --show-suggestions --show-context --dot $NO_PROGRESS {**,.**} || EXIT_CODE=$((EXIT_CODE+1)) ESLINT_FIX=$([[ "$1" == "fix" ]] && echo "--fix" || echo ""); -npx eslint --no-error-on-unmatched-pattern --ignore-pattern=vendor --ignore-pattern=node_modules --ext=.yml $ESLINT_FIX . && echo "ESLint passed." || EXIT_CODE=$((EXIT_CODE+1)) +DEBUG=$([[ "$1" == "debug" ]] && echo "--debug" || echo ""); +npx eslint --no-error-on-unmatched-pattern --ignore-pattern=vendor --ignore-pattern=node_modules --ext=.yml $DEBUG $ESLINT_FIX . && echo "ESLint passed." || EXIT_CODE=$((EXIT_CODE+1)) [[ "$1" == "fix" ]] && vendor/bin/phpcbf --colors scripts/*.php -s -vendor/bin/phpcs --colors scripts/*.php -s && echo "PHPCS passed." || EXIT_CODE=$((EXIT_CODE+1)) +VERBOSE=$([[ "$1" == "debug" ]] && echo "-v" || echo ""); +vendor/bin/phpcs --colors scripts/*.php -s $VERBOSE && echo "PHPCS passed." || EXIT_CODE=$((EXIT_CODE+1)) shellcheck scripts/*.sh && echo "Shellcheck passed." || EXIT_CODE=$((EXIT_CODE+1)) -php scripts/unformatted-links.php || EXIT_CODE=$((EXIT_CODE+1)) +php scripts/unformatted-links.php $VERBOSE || EXIT_CODE=$((EXIT_CODE+1)) [[ "$EXIT_CODE" != 0 ]] && echo -e "\n===========================\nNumber of failed checks: $EXIT_CODE\n===========================\n" || echo "= All OK =" # Clean up all files that were copied. -- GitLab