Skip to content

Commit

Permalink
feat: allow per project linters (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
evadnoob authored and yj-yan committed Aug 8, 2023
1 parent 1c78e07 commit fce6d81
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<lintername>.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.
17 changes: 12 additions & 5 deletions shell/linters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fce6d81

Please sign in to comment.