diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4e04386fcc..8a6fbbb4f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,8 @@ jobs: steps: - uses: actions/checkout@v1 - uses: actions/setup-node@v1 + with: + node-version: 14 - run: 'npm i && npm run lint' Unit: runs-on: ${{ matrix.os }} diff --git a/ci-script/.gitignore b/ci-script/.gitignore new file mode 100644 index 0000000000..b62e5d44d8 --- /dev/null +++ b/ci-script/.gitignore @@ -0,0 +1 @@ +observed-errors-*.log diff --git a/ci-script/tsc-strict-error.mjs b/ci-script/tsc-strict-error.mjs new file mode 100644 index 0000000000..04afea6e7b --- /dev/null +++ b/ci-script/tsc-strict-error.mjs @@ -0,0 +1,59 @@ +const dirToCheck = [ + 'compiler', + 'runtime', +] +const tsErrorsThreshold = [ + 883, /* 'compiler' */ + 362, /* 'runtime' */ +]; + +import { promisify } from 'util'; +import { exec as execCallback } from 'child_process'; +const exec = promisify(execCallback); + +const identity = i => i; + +async function main() { + const errors = await Promise.all(dirToCheck.map(dir => getTsErrors(dir))); + const errorsCount = errors.map(countTsErrors); + const noop = () => void 0; + + let conditionallyPrintError = [noop, noop]; + let conditionallyExplainError = noop; + let printErrorCount = [noop, noop]; + let conditionallyAskForFix = noop; + let conditionallyExitWithNonZeroCode = noop; + + for (let i = 0; i < tsErrorsThreshold.length; i++) { + if(errorsCount[i] > tsErrorsThreshold[i]) { + conditionallyPrintError[i] = () => console.log(errors[i]); + conditionallyExplainError = () => console.log(`This project is in the processing of enforcing TypeScript's "strict": true`); + printErrorCount[i] = () => printErrorFromCompileCount(dirToCheck[i], errorsCount[i], tsErrorsThreshold[i], 'higher than') + conditionallyAskForFix = () => console.log(`Please fix the some of the above mentioned errors to bring the number of errors below the allowed threshold`); + conditionallyExitWithNonZeroCode = () => process.exit(42); + } else { + printErrorCount[i] = () => printErrorFromCompileCount(dirToCheck[i], errorsCount[i], tsErrorsThreshold[i], 'less than or equal to') + } + } + conditionallyPrintError.forEach(f => f()); + conditionallyExplainError(); + printErrorCount.forEach(f => f()); + conditionallyAskForFix() + conditionallyExitWithNonZeroCode(); +} + +main(); + +async function getTsErrors(dir) { + const { stdout } = await exec(`npx tsc -p src/${dir} --noEmit`).then(identity, identity); + return stdout + +} + +function countTsErrors(stdout) { + return (stdout.match(/error TS/g) || []).length +} + +function printErrorFromCompileCount (dir, count, allowed, operator ) { + console.log(`in src/${dir}: The number of errors resulting from TypeScript's "strict": true is, ${count}, ${operator} allowed ${allowed}`); +} \ No newline at end of file diff --git a/package.json b/package.json index 61c213494c..ce837301e6 100644 --- a/package.json +++ b/package.json @@ -74,8 +74,9 @@ "pretest": "npm run build", "posttest": "agadoo internal/index.mjs", "prepublishOnly": "npm run lint && PUBLISH=true npm test", - "tsd": "tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly", - "lint": "eslint \"{src,test}/**/*.{ts,js}\"" + "tsd": "tsc -p src/compiler --emitDeclarationOnly --strict false && tsc -p src/runtime --emitDeclarationOnly --strict false", + "tsc-strict-error": "node ci-script/tsc-strict-error.mjs --unhandled-rejections=strict", + "lint": "npm run tsc-strict-error && eslint \"{src,test}/**/*.{ts,js}\"" }, "repository": { "type": "git", diff --git a/tsconfig.json b/tsconfig.json index 39476f3dd1..fd12c0cd49 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,8 +21,7 @@ "resolveJsonModule": true, "allowSyntheticDefaultImports": true, - // TODO: error all the things - //"strict": true, + "strict": true, "noImplicitThis": true, "noUnusedLocals": true, "noUnusedParameters": true