From fce6d81c54a95296479d6be70210bf216e354d70 Mon Sep 17 00:00:00 2001 From: David Boon Date: Tue, 1 Aug 2023 08:08:53 -0700 Subject: [PATCH] feat: allow per project linters (#600) --- docs/linters.md | 10 ++++++++++ shell/linters.sh | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/linters.md b/docs/linters.md index 24f3bf8a..d0c1802e 100644 --- a/docs/linters.md +++ b/docs/linters.md @@ -10,3 +10,13 @@ There is currently no way to ignore files outside of the `.gitignore` file. There is currently a bash issue where the exit code is not getting detected when there is multiple commands being ran. The easy solution for now is to return the value 1 from the function indicating an error has occurred and terminating the `make test/lint` command that triggered it + +## Project specific linters ## + +Projects can create additional linters to be run in addition to the built-in +linters. + +To add a linter place the linter shell script in `scripts/linters/.sh`. +The linter will be discovered when globbing `.sh` files run with the built-in +linters. Follow the conventions of the existing linter shell scripts when creating +the new linter. diff --git a/shell/linters.sh b/shell/linters.sh index 9843e0cf..018cfb54 100755 --- a/shell/linters.sh +++ b/shell/linters.sh @@ -17,23 +17,30 @@ if [[ -n $SKIP_LINTERS ]] || [[ -n $SKIP_VALIDATE ]]; then exit 0 fi +# add extra (per project) linters +linters=("$DIR/linters"/*.sh) +if [[ -z $workspaceFolder ]]; then + workspaceFolder="$(get_repo_directory)" +fi +if [[ -d "$workspaceFolder"/scripts/linters ]]; then + linters+=("$workspaceFolder/scripts/linters/"*.sh) +fi + info "Running linters" started_at="$(get_time_ms)" -for languageScript in "$DIR/linters"/*.sh; do - languageName="$(basename "${languageScript%.sh}")" - +for linterScript in "${linters[@]}"; do # We use a sub-shell to prevent inheriting # the changes to functions/variables to the parent # (this) script ( - # Note: These are modified by the source'd language file + # Note: These are modified by the source'd linter file # extensions are the extensions this linter should run on extensions=() # Why: Dynamic # shellcheck disable=SC1090 - source "$DIR/linters/$languageName.sh" + source "$linterScript" # If we don't find any files with the extension, skip the run. matched=false