script to have tsc strict, but allow current errors to have grace period

pull/5693/head
TruongSinh Tran-Nguyen 5 years ago
parent daec25604f
commit b93c815191

@ -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 }}

@ -0,0 +1 @@
observed-errors-*.log

@ -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}`);
}

@ -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",

@ -21,8 +21,7 @@
"resolveJsonModule": true,
"allowSyntheticDefaultImports": true,
// TODO: error all the things
//"strict": true,
"strict": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true

Loading…
Cancel
Save