Created
September 20, 2018 20:35
-
-
Save elasticdog/258d51a8c63019e07603bf214bf5c01d to your computer and use it in GitHub Desktop.
Git pre-commit hook for linting YAML files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
current_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||') | |
if [[ $current_branch = 'master' ]]; then | |
printf 'Direct commits to the master branch are not allowed.\n' | |
exit 1 | |
fi | |
if command -v yamllint > /dev/null; then | |
while IFS= read -r -d '' file; do | |
if [[ $file =~ \.(yaml|yml)$ ]]; then | |
if ! yamllint <(git show ":${file}") > /dev/null; then | |
printf 'YAML syntax check failed for file: %s\n' "$file" | |
exit 1 | |
fi | |
fi | |
done < <(git diff --cached --name-only --diff-filter=ACM -z) | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
extends: default | |
rules: | |
braces: | |
max-spaces-inside: 1 | |
line-length: disable | |
indentation: | |
indent-sequences: consistent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment