|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2018 The Stdlib Authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +#/ |
| 18 | + |
| 19 | +# VARIABLES # |
| 20 | + |
| 21 | +# Define the shell script linter: |
| 22 | +SHELL_LINTER ?= $(SHELLCHECK) |
| 23 | + |
| 24 | +# Define the command-line options to be used when invoking the executable: |
| 25 | +SHELL_LINTER_FLAGS ?= |
| 26 | + |
| 27 | + |
| 28 | +# RULES # |
| 29 | + |
| 30 | +#/ |
| 31 | +# Lints shell script files. |
| 32 | +# |
| 33 | +# ## Notes |
| 34 | +# |
| 35 | +# - This rule is useful when wanting to glob for files, irrespective of context, for a particular directory in order to lint all contained shell script files. |
| 36 | +# |
| 37 | +# @param {string} [SHELL_FILTER] - file path pattern (e.g., `.*/_tools/.*`) |
| 38 | +# @param {*} [FAST_FAIL] - flag indicating whether to stop linting upon encountering a lint error |
| 39 | +# |
| 40 | +# @example |
| 41 | +# make lint-shell |
| 42 | +# |
| 43 | +# @example |
| 44 | +# make lint-shell SHELL_FILTER=.*/_tools/.* |
| 45 | +#/ |
| 46 | +lint-shell: |
| 47 | +ifeq ($(FAIL_FAST), true) |
| 48 | + $(QUIET) $(FIND_SHELL_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ |
| 49 | + echo ''; \ |
| 50 | + echo "Linting file: $$file"; \ |
| 51 | + $(SHELL_LINTER) $(SHELL_LINTER_FLAGS) $$file || exit 1; \ |
| 52 | + done |
| 53 | +else |
| 54 | + $(QUIET) $(FIND_SHELL_CMD) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \ |
| 55 | + echo ''; \ |
| 56 | + echo "Linting file: $$file"; \ |
| 57 | + $(SHELL_LINTER) $(SHELL_LINTER_FLAGS) $$file || echo 'Linting failed.'; \ |
| 58 | + done |
| 59 | +endif |
| 60 | + |
| 61 | +.PHONY: lint-shell |
| 62 | + |
| 63 | +#/ |
| 64 | +# Lints a specified list of shell script files. |
| 65 | +# |
| 66 | +# ## Notes |
| 67 | +# |
| 68 | +# - This rule is useful when wanting to lint a list of shell script files generated by some other command (e.g., a list of changed shell script files obtained via `git diff`). |
| 69 | +# |
| 70 | +# @param {string} FILES - list of shell script file paths |
| 71 | +# @param {*} [FAST_FAIL] - flag indicating whether to stop linting upon encountering a lint error |
| 72 | +# |
| 73 | +# @example |
| 74 | +# make lint-shell-files FILES='/foo/file.sh /bar/file.sh' |
| 75 | +#/ |
| 76 | +lint-shell-files: |
| 77 | +ifeq ($(FAIL_FAST), true) |
| 78 | + $(QUIET) for file in $(FILES); do \ |
| 79 | + echo ''; \ |
| 80 | + echo "Linting file: $$file"; \ |
| 81 | + $(SHELL_LINTER) $(SHELL_LINTER_FLAGS) $$file || exit 1; \ |
| 82 | + done |
| 83 | +else |
| 84 | + $(QUIET) for file in $(FILES); do \ |
| 85 | + echo ''; \ |
| 86 | + echo "Linting file: $$file"; \ |
| 87 | + $(SHELL_LINTER) $(SHELL_LINTER_FLAGS) $$file || echo 'Linting failed.'; \ |
| 88 | + done |
| 89 | +endif |
| 90 | + |
| 91 | +.PHONY: lint-shell-files |
0 commit comments