Page MenuHomeDevCentral

D2631.id.diff
No OneTemporary

D2631.id.diff

diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml
new file mode 100644
--- /dev/null
+++ b/.pre-commit-hooks.yaml
@@ -0,0 +1,6 @@
+- id: shellcheck
+ name: ShellCheck
+ description: Static analysis tool for shell scripts
+ entry: pre-commit-hooks/shellcheck.sh
+ language: script
+ exclude: \.jinja$
diff --git a/pre-commit-hooks/README.md b/pre-commit-hooks/README.md
new file mode 100644
--- /dev/null
+++ b/pre-commit-hooks/README.md
@@ -0,0 +1,19 @@
+## pre-commit hooks
+
+A collection of pre-commit hooks to use in Nasqueron projects.
+
+### ShellCheck
+
+Initial authors: 06kellyjac, Mark Butcher and Yevgeniy Brikman.
+
+To enable optional shellcheck features you can use the `--enable` flag.
+Other shellcheck flags can not be passed through.
+
+```yaml
+repos:
+ - repo: https://github.com/nasqueron/codestyle
+ rev: 0.1.0
+ hooks:
+ - id: shellcheck
+ args: ["--enable require-variable-braces,deprecate-which"]
+```
diff --git a/pre-commit-hooks/shellcheck.sh b/pre-commit-hooks/shellcheck.sh
new file mode 100755
--- /dev/null
+++ b/pre-commit-hooks/shellcheck.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+
+# -------------------------------------------------------------
+# pre-commit :: hooks :: shellcheck
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Forked from: gruntwork-io/pre-commit
+# Authors: 06kellyjac
+# Mark Butcher
+# Yevgeniy Brikman
+# Description: Call shellcheck as pre-commit hook
+# License: Apache License 2.0
+# -------------------------------------------------------------
+
+set -e
+
+exit_status=0
+enable_list=""
+
+parse_arguments() {
+ while (($# > 0)); do
+ # Grab param and value splitting on " " or "=" with parameter expansion
+ local PARAMETER="${1%[ =]*}"
+ local VALUE="${1#*[ =]}"
+ if [[ "$PARAMETER" == "$VALUE" ]]; then VALUE="$2"; fi
+ shift
+ case "$PARAMETER" in
+ --enable)
+ enable_list="$enable_list $VALUE"
+ ;;
+ -*)
+ echo "Error: Unknown option: $PARAMETER" >&2
+ exit 1
+ ;;
+ *)
+ files="$files $PARAMETER"
+ ;;
+ esac
+ done
+ enable_list="${enable_list## }" # remove preceeding space
+}
+
+parse_arguments "$@"
+
+for FILE in $files; do
+ SHEBANG_REGEX='^#!\(/\|/.*/\|/.* \)\(\(ba\|da\|k\|a\)*sh\|bats\)$'
+ if (head -1 "$FILE" | grep "$SHEBANG_REGEX" >/dev/null); then
+ if ! shellcheck ${enable_list:+ --enable="$enable_list"} "$FILE"; then
+ exit_status=1
+ fi
+ elif [[ "$FILE" =~ .+\.(sh|bash|dash|ksh|ash|bats)$ ]]; then
+ echo "$FILE: missing shebang"
+ exit_status=1
+ fi
+done
+
+exit $exit_status

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 16, 17:03 (20 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2247142
Default Alt Text
D2631.id.diff (2 KB)

Event Timeline