Skip to content

Commit f0e4479

Browse files
committed
Enforce new code must have not errors or warns
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.
1 parent 2ac5ce1 commit f0e4479

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

.travis.build.sh

+38-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ "$TEST_SUITE" = "syntax" ] || [ "$TEST_SUITE" = "style" ]; then
3232
files_changed=()
3333
while IFS= read -r -d $'\0' file; do
3434
files_changed+=("$file")
35-
done < <(git diff --name-only --diff-filter=d -z "$TRAVIS_COMMIT_RANGE")
35+
done < <(git diff --name-only --diff-filter=da -z "$TRAVIS_COMMIT_RANGE")
3636

3737
# Separate the changed files by language.
3838
php_files_changed=()
@@ -44,6 +44,17 @@ if [ "$TEST_SUITE" = "syntax" ] || [ "$TEST_SUITE" = "style" ]; then
4444
js_files_changed+=("$file")
4545
fi
4646
done
47+
48+
# Get any added files by language
49+
php_files_added=()
50+
js_files_added=()
51+
while IFS= read -r -d $'\0' file; do
52+
if [[ "$file" == *.php ]]; then
53+
php_files_added+=("$file")
54+
elif [[ "$file" == *.js ]]; then
55+
js_files_added+=("$file")
56+
fi
57+
done < <(git diff --name-only --diff-filter=A -z "$TRAVIS_COMMIT_RANGE")
4758
fi
4859

4960
# Perform a test set based on the value of $TEST_SUITE.
@@ -62,13 +73,39 @@ if [ "$TEST_SUITE" = "syntax" ]; then
6273
fi
6374
done
6475
elif [ "$TEST_SUITE" = "style" ]; then
76+
npm install https://github.com/jpwhite4/lint-diff/tarball/master
77+
6578
for file in "${php_files_changed[@]}"; do
79+
phpcs "$file" --report=json > "$file.lint.new.json"
80+
if [ $? != 0 ]; then
81+
git show "$commit_range_start:$file" | phpcs --stdin-path="$file" --report=json > "$file.lint.orig.json"
82+
./node_modules/.bin/lint-diff "$file.lint.orig.json" "$file.lint.new.json"
83+
if [ $? != 0 ]; then
84+
build_exit_value=2
85+
fi
86+
rm "$file.lint.orig.json"
87+
fi
88+
rm "$file.lint.new.json"
89+
done
90+
for file in "${php_files_added[@]}"; do
6691
phpcs "$file"
6792
if [ $? != 0 ]; then
6893
build_exit_value=2
6994
fi
7095
done
7196
for file in "${js_files_changed[@]}"; do
97+
eslint "$file" -f json > "$file.lint.new.json"
98+
if [ $? != 0 ]; then
99+
git show "$commit_range_start:$file" | eslint --stdin --stdin-filename "$file" -f json > "$file.lint.orig.json"
100+
./node_modules/.bin/lint-diff "$file.lint.orig.json" "$file.lint.new.json"
101+
if [ $? != 0 ]; then
102+
build_exit_value=2
103+
fi
104+
rm "$file.lint.orig.json"
105+
fi
106+
rm "$file.lint.new.json"
107+
done
108+
for file in "${js_files_added[@]}"; do
72109
eslint "$file"
73110
if [ $? != 0 ]; then
74111
build_exit_value=2

.travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ env:
1515
- TEST_SUITE=unit
1616
- TEST_SUITE=build
1717

18-
matrix:
19-
allow_failures:
20-
- env: TEST_SUITE=style
21-
2218
# Add dependency directories to the Travis cache
2319
cache:
2420
directories:

0 commit comments

Comments
 (0)