Skip to content

Commit d315776

Browse files
authored
Changed way of linting YAML files. (drwahl#90)
* Changed way of linting YAML files. * Fixed checking for puppet syntax
1 parent 0d54866 commit d315776

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ gem 'rspec-puppet'
55
gem 'json_pure'
66
gem 'psych'
77
gem 'metadata-json-lint'
8+
gem 'yaml-lint'
89
gem 'puppet', '3.8.6'
910
gem 'puppet-lint', '2.0.0'

commit_hooks/puppet_manifest_syntax_check.sh

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
# to a puppet manifest file for which it will run syntax checks against.
55

66
manifest_path="$1"
7-
module_dir="$2"
8-
USE_PUPPET_FUTURE_PARSER="$3"
7+
USE_PUPPET_FUTURE_PARSER="$2"
98

109
syntax_errors=0
1110
error_msg=$(mktemp /tmp/error_msg_puppet-syntax.XXXXX)
12-
13-
if [[ $module_dir ]]; then
14-
manifest_name="${manifest_path##*$module_dir}"
15-
error_msg_filter="sed -e s|$module_dir||"
16-
else
17-
manifest_name="$manifest_path"
18-
error_msg_filter="sed"
19-
fi
11+
manifest_name="$manifest_path"
12+
error_msg_filter="sed"
2013

2114
# Get list of new/modified manifest and template files to check (in git index)
2215
# Check puppet manifest syntax

commit_hooks/yaml_syntax_check.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fi
1414

1515
# Check YAML file syntax
1616
$ERRORS_ONLY || echo -e "$(tput setaf 6)Checking yaml syntax for $module_path...$(tput sgr0)"
17-
ruby -e "require 'yaml'; YAML.parse(File.open('$1'))" 2> "$error_msg" > /dev/null
17+
yaml-lint $1 > "$error_msg"
1818
if [ $? -ne 0 ]; then
1919
sed -e "s/^/$(tput setaf 1)/" -e "s/$/$(tput sgr0)/" "$error_msg"
2020
syntax_errors=$((syntax_errors + 1))

pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ for changedfile in $files_to_check; do
8282
failures=$((failures + 1))
8383
fi
8484
elif echo "$changedfile" | grep -iq '\.pp$'; then
85-
${subhook_root}/puppet_manifest_syntax_check.sh "$changedfile_native" "" "$USE_PUPPET_FUTURE_PARSER"
85+
${subhook_root}/puppet_manifest_syntax_check.sh "$changedfile_native" "$USE_PUPPET_FUTURE_PARSER"
8686
RC=$?
8787
if [[ "$RC" -ne 0 ]]; then
8888
failures=$((failures + 1))

0 commit comments

Comments
 (0)