Skip to content

Commit

Permalink
Enforce new code must have not errors or warns
Browse files Browse the repository at this point in the history
Travis Ci will run the linter on any modifed js or php files. If
there are errors or warnings, then lint will be run on the previous
version of the file (if there was one). If new errors or warning have been introduced then
the build is in error.
  • Loading branch information
jpwhite4 committed Jan 17, 2017
1 parent 2ac5ce1 commit f0e4479
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
39 changes: 38 additions & 1 deletion .travis.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if [ "$TEST_SUITE" = "syntax" ] || [ "$TEST_SUITE" = "style" ]; then
files_changed=()
while IFS= read -r -d $'\0' file; do
files_changed+=("$file")
done < <(git diff --name-only --diff-filter=d -z "$TRAVIS_COMMIT_RANGE")
done < <(git diff --name-only --diff-filter=da -z "$TRAVIS_COMMIT_RANGE")

# Separate the changed files by language.
php_files_changed=()
Expand All @@ -44,6 +44,17 @@ if [ "$TEST_SUITE" = "syntax" ] || [ "$TEST_SUITE" = "style" ]; then
js_files_changed+=("$file")
fi
done

# Get any added files by language
php_files_added=()
js_files_added=()
while IFS= read -r -d $'\0' file; do
if [[ "$file" == *.php ]]; then
php_files_added+=("$file")
elif [[ "$file" == *.js ]]; then
js_files_added+=("$file")
fi
done < <(git diff --name-only --diff-filter=A -z "$TRAVIS_COMMIT_RANGE")
fi

# Perform a test set based on the value of $TEST_SUITE.
Expand All @@ -62,13 +73,39 @@ if [ "$TEST_SUITE" = "syntax" ]; then
fi
done
elif [ "$TEST_SUITE" = "style" ]; then
npm install https://github.com/jpwhite4/lint-diff/tarball/master

for file in "${php_files_changed[@]}"; do
phpcs "$file" --report=json > "$file.lint.new.json"
if [ $? != 0 ]; then
git show "$commit_range_start:$file" | phpcs --stdin-path="$file" --report=json > "$file.lint.orig.json"
./node_modules/.bin/lint-diff "$file.lint.orig.json" "$file.lint.new.json"
if [ $? != 0 ]; then
build_exit_value=2
fi
rm "$file.lint.orig.json"
fi
rm "$file.lint.new.json"
done
for file in "${php_files_added[@]}"; do
phpcs "$file"
if [ $? != 0 ]; then
build_exit_value=2
fi
done
for file in "${js_files_changed[@]}"; do
eslint "$file" -f json > "$file.lint.new.json"
if [ $? != 0 ]; then
git show "$commit_range_start:$file" | eslint --stdin --stdin-filename "$file" -f json > "$file.lint.orig.json"
./node_modules/.bin/lint-diff "$file.lint.orig.json" "$file.lint.new.json"
if [ $? != 0 ]; then
build_exit_value=2
fi
rm "$file.lint.orig.json"
fi
rm "$file.lint.new.json"
done
for file in "${js_files_added[@]}"; do
eslint "$file"
if [ $? != 0 ]; then
build_exit_value=2
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ env:
- TEST_SUITE=unit
- TEST_SUITE=build

matrix:
allow_failures:
- env: TEST_SUITE=style

# Add dependency directories to the Travis cache
cache:
directories:
Expand Down

0 comments on commit f0e4479

Please sign in to comment.