Skip to content

Commit ed97886

Browse files
committed
Automatically fix lint errors and include in commit
1 parent 7461b24 commit ed97886

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tools/git/hooks/pre-commit

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ run_lint() {
176176
if [[ -z "${SKIP_LINT_JAVASCRIPT_SRC}" ]]; then
177177
files=$(echo "${changed_files}" | grep '\.js$' | grep -v -e '/examples' -e '/test' -e '/benchmark' -e '^dist/' | tr '\n' ' ')
178178
if [[ -n "${files}" ]]; then
179-
make FILES="${files}" lint-javascript-files > /dev/null >&2
179+
make FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
180180
if [[ "$?" -ne 0 ]]; then
181181
echo '' >&2
182182
echo 'JavaScript lint errors for source files.' >&2
@@ -188,7 +188,7 @@ run_lint() {
188188
if [[ -z "${SKIP_LINT_JAVASCRIPT_CLI}" ]]; then
189189
files=$(echo "${changed_files}" | grep '/bin/cli$' | tr '\n' ' ')
190190
if [[ -n "${files}" ]]; then
191-
make FILES="${files}" lint-javascript-files > /dev/null >&2
191+
make FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
192192
if [[ "$?" -ne 0 ]]; then
193193
echo '' >&2
194194
echo 'JavaScript lint errors for command-line interface files.' >&2
@@ -200,7 +200,7 @@ run_lint() {
200200
if [[ -z "${SKIP_LINT_JAVASCRIPT_EXAMPLES}" ]]; then
201201
files=$(echo "${changed_files}" | grep '/examples/.*\.js$' | tr '\n' ' ')
202202
if [[ -n "${files}" ]]; then
203-
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_examples_conf}" FILES="${files}" lint-javascript-files > /dev/null >&2
203+
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_examples_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
204204
if [[ "$?" -ne 0 ]]; then
205205
echo '' >&2
206206
echo 'JavaScript lint errors for example files.' >&2
@@ -212,7 +212,7 @@ run_lint() {
212212
if [[ -z "${SKIP_LINT_JAVASCRIPT_TESTS}" ]]; then
213213
files=$(echo "${changed_files}" | grep '/test/.*\.js$' | tr '\n' ' ')
214214
if [[ -n "${files}" ]]; then
215-
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_tests_conf}" FILES="${files}" lint-javascript-files > /dev/null >&2
215+
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_tests_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
216216
if [[ "$?" -ne 0 ]]; then
217217
echo '' >&2
218218
echo 'JavaScript lint errors for test files.' >&2
@@ -224,7 +224,7 @@ run_lint() {
224224
if [[ -z "${SKIP_LINT_JAVASCRIPT_BENCHMARKS}" ]]; then
225225
files=$(echo "${changed_files}" | grep '/benchmark/.*\.js$' | tr '\n' ' ')
226226
if [[ -n "${files}" ]]; then
227-
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_benchmarks_conf}" FILES="${files}" lint-javascript-files > /dev/null >&2
227+
make JAVASCRIPT_LINTER=eslint ESLINT_CONF="${eslint_benchmarks_conf}" FILES="${files}" FIX=1 lint-javascript-files > /dev/null >&2
228228
if [[ "$?" -ne 0 ]]; then
229229
echo '' >&2
230230
echo 'JavaScript lint errors for benchmark files.' >&2
@@ -379,6 +379,9 @@ run_lint() {
379379

380380
# TODO: if datapackage.json, validate via schema
381381

382+
# Re-add files that may have been fixed by linting...
383+
git add "${changed_files[@]}"
384+
382385
return 0
383386
}
384387

0 commit comments

Comments
 (0)