diff --git a/.travis/check-strict-null-errors.snapshot b/.travis/check-strict-null-errors.snapshot new file mode 100644 index 000000000..4b9661fc9 --- /dev/null +++ b/.travis/check-strict-null-errors.snapshot @@ -0,0 +1 @@ +2829 \ No newline at end of file diff --git a/package.json b/package.json index 9d119e7db..c5f8d04a4 100644 --- a/package.json +++ b/package.json @@ -189,6 +189,7 @@ "extract-messages": "npm run extract-json-messages && npm run transpile-messages", "build-types": "apollo client:codegen --target=typescript types --globalTypesFile=src/types/globalTypes.ts", "check-types": "tsc --noEmit", + "check-strict-null-errors": "tsc --noEmit --strictNullChecks | node scripts/count-strict-null-check-errors.js", "generate-component": "plop --plopfile .plop/plopfile.js", "start": "webpack-dev-server --open -d", "storybook": "start-storybook -p 3000 -c src/storybook/", diff --git a/scripts/count-strict-null-check-errors.js b/scripts/count-strict-null-check-errors.js new file mode 100644 index 000000000..dfd245b03 --- /dev/null +++ b/scripts/count-strict-null-check-errors.js @@ -0,0 +1,29 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +/* eslint-disable no-console */ +const fs = require("fs"); +const readline = require("readline"); + +const updateSnapshot = process.argv.includes("-u"); +const snapshotPath = ".travis/check-strict-null-errors.snapshot"; +const shouldCount = /^src/; +let errors = 0; + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: false +}); + +rl.on("line", line => { + if (shouldCount.test(line)) { + errors++; + } +}); + +rl.on("close", () => { + if (updateSnapshot) { + fs.writeFileSync(snapshotPath, errors); + } else { + console.log(errors); + } +});