Skip to content
Snippets Groups Projects
Commit ccdc0787 authored by Jonathan Smith's avatar Jonathan Smith Committed by Fran Garcia-Linares
Browse files

Issue #3508450 by jonathan1055: run-local-checks should ignore vendor and node_modules

parent 0ea8352c
No related branches found
No related tags found
1 merge request!333#3508450 Improvments to run-local-checks
Pipeline #440618 passed
#!/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 --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.
......
......@@ -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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment