Skip to content

Commit 8a3c091

Browse files
authored
Treat UI lint warnings as errors (#3885)
* Add lint warnings-as-errors Genericize the existing unit-tests.sh script to handle other commands and apply it for linting. Signed-off-by: michael sorens <[email protected]> * Update unit tests to use generic script, too Signed-off-by: michael sorens <[email protected]> * Forced lint error and warning This should be reverted before merging! Signed-off-by: michael sorens <[email protected]> * Revert "Forced lint error and warning" This reverts commit d5c6fb77e4198e110f08628e17fb3572cb877ff4. That commit was provided only for exposition in the pull request. Signed-off-by: michael sorens <[email protected]> * Apply review feedback A cooler bit of code! Signed-off-by: michael sorens <[email protected]> * Add some helpful in-code comments Signed-off-by: michael sorens <[email protected]>
1 parent d1fbf37 commit 8a3c091

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

components/automate-ui/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
"copy-ui-lib:fonts": "cp -r ../chef-ui-library/dist/collection/assets/fonts/ src/assets/fonts",
1616
"build": "ng build",
1717
"build:prod": "npm run build -- --prod",
18-
"test": "scripts/unit-tests.sh",
18+
"test": "scripts/build.sh 'ng test --watch=false --code-coverage --source-map=false --configuration=no_auth' 'WARN:'",
1919
"test:watch": "ng test --watch=true --browsers='Chrome' --source-map=true --configuration=no_auth",
2020
"e2e": "ng e2e --no-webdriver-update",
21-
"lint": "ng lint",
21+
"lint": "scripts/build.sh 'ng lint' 'WARNING:'",
2222
"lint:html": "node_modules/htmlhint/bin/htmlhint --config .htmlhintrc src/app/**/*.html",
2323
"lint:sass": "node node_modules/sass-lint/bin/sass-lint.js -v -q"
2424
},
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
# The build machine is using sh; need to use bash to be able to use PIPESTATUS.
3+
4+
# Purpose:
5+
# Treat warnings as errors for build commands that do not provide innate support to do that.
6+
7+
CMD_STRING=$1
8+
# Examples:
9+
# "ng lint"
10+
# "ng lint | grep -v 'deprecated'"
11+
12+
WARNING_LABEL=$2
13+
# Examples:
14+
# "WARN:" (as `ng test` uses)
15+
# "WARNING:" (as `ng lint` uses)
16+
17+
# Setup an unused stream to redirect to stdout in the next command.
18+
exec 5>&1
19+
# We want to capture the target command's output to reuse it (rather than have to re-run the command),
20+
# so sending to an unused stream and redirecting that to stdout (stream 1) where it can be captured into the `out` variable.
21+
# In order to check the exit code of the target command itself, need to use PIPESTATUS
22+
# to grab the exit code of the first pipe component inside CMD_STRING rather than the final one.
23+
out=$(eval "$CMD_STRING | tee /dev/fd/5; exit \${PIPESTATUS[0]}")
24+
25+
# If the unit test run reported non-zero--an actual unit test error--then exit with non-zero return code.
26+
# shellcheck disable=SC2181
27+
if [ $? -ne 0 ]; then
28+
exit 1
29+
fi
30+
31+
# If no errors, next check for any warnings.
32+
grep -q "$WARNING_LABEL" <<< "$out"
33+
34+
# Return a non-zero exit code if any warnings present.
35+
# $? will be 0 if warnings were found, so `test` inverts that result.
36+
test $? -ne 0

components/automate-ui/scripts/unit-tests.sh

-24
This file was deleted.

0 commit comments

Comments
 (0)