From 8109c13e661ccafdd0929260a286688d0e05f150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20Fournier?= Date: Fri, 10 Mar 2023 10:27:56 +0100 Subject: [PATCH] chore: enable strictNullCheck but ignore problems at compile time (#3273) ## About the changes This enables strictNullChecks which will give us nice hints in our IDEs to avoid introducing more and hopefully will encourage us to fix some of the existing problems. Also: 1. The compiler explicitly ignores these errors 2. The "null checks action" still verifies we're not introducing new ones. The combination of these two things should help us to reduce the number of nulls For testing that the action still works (cause it was modified), [a commit](https://github.com/Unleash/unleash/pull/3273/commits/5c4b818d1acc3f46053f22c32ded167b01a045b8) was added introducing a bunch of null check errors: https://github.com/Unleash/unleash/actions/runs/4364648191/jobs/7632224720 --- .github/workflows/gradual-strict-null-checks.yml | 11 +++++------ package.json | 4 ++-- tsconfig.json | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/workflows/gradual-strict-null-checks.yml b/.github/workflows/gradual-strict-null-checks.yml index 775e2b6091..f1ab17245e 100644 --- a/.github/workflows/gradual-strict-null-checks.yml +++ b/.github/workflows/gradual-strict-null-checks.yml @@ -47,13 +47,12 @@ jobs: --data "{ \"body\": \"${1}\" }" } - sed -i 's/\/\/\s*"strictNullChecks":\s*true,/"strictNullChecks": true,/' "current/tsconfig.json" - sed -i 's/\/\/\s*"strictNullChecks":\s*true,/"strictNullChecks": true,/' "main/tsconfig.json" + YARN_1="yarn --mutex network --cwd ./current" + YARN_2="yarn --mutex network --cwd ./main" - yarn --mutex network --cwd ./current 2> .stderr-current > .out-current & + $YARN_1 install --ignore-scripts &> /dev/null && $YARN_1 build --strictNullChecks true 2> .stderr-current > .out-current & pid1=$! - - yarn --mutex network --cwd ./main 2> .stderr-main > .out-main & + $YARN_2 install --ignore-scripts &> /dev/null && $YARN_2 build --strictNullChecks true 2> .stderr-main > .out-main & pid2=$! # wait for the processes that are expected to fail @@ -66,7 +65,7 @@ jobs: MAIN=$(grep "Found [0-9]* errors" .out-main | sed 's/Found \(.*\) errors in .* files./\1/') if [ $CURRENT -gt $MAIN ]; then - comment "After enabling [\`strictNullChecks\`](https://www.typescriptlang.org/tsconfig#strictNullChecks) this PR would be **increasing** the number of null check errors from ${MAIN} to ${CURRENT}.
Make sure your branch is up-to-date with ${MAIN_BRANCH} and **check the diff in the console output** to gather more details." + comment "After enabling [\`strictNullChecks\`](https://www.typescriptlang.org/tsconfig#strictNullChecks) this PR would be **increasing** the number of null check errors from ${MAIN} to ${CURRENT}.
Make sure your branch is up-to-date with ${MAIN_BRANCH} and **check the diff in the console output** to pinpoint the offending files." diff .out-current .out-main exit 1 else diff --git a/package.json b/package.json index 0cf3cc53ff..c5fe8169a2 100644 --- a/package.json +++ b/package.json @@ -35,9 +35,9 @@ "lint": "eslint ./src", "local:package": "del-cli --force build && mkdir build && cp -r dist docs CHANGELOG.md LICENSE README.md package.json build", "prebuild:watch": "yarn run clean", - "build:watch": "tsc -w", + "build:watch": "tsc -w --strictNullChecks false", "prebuild": "yarn run clean", - "build": "yarn run copy-templates && tsc --pretty", + "build": "yarn run copy-templates && tsc --pretty --strictNullChecks false", "prepare": "node scripts/husky-install && cd frontend && yarn && cd .. && yarn run build", "test": "NODE_ENV=test PORT=4243 jest", "test:unit": "NODE_ENV=test PORT=4243 jest --testPathIgnorePatterns=src/test/e2e --testPathIgnorePatterns=dist", diff --git a/tsconfig.json b/tsconfig.json index 3b9362f856..3a8552b43a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,7 +27,7 @@ /* Strict Type-Checking Options */ // "strict": true, /* Enable all strict type-checking options. */ // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ + "strictNullChecks": true /* Enable strict null checks. */, // "strictFunctionTypes": true, /* Enable strict checking of function types. */ "strictBindCallApply": true /* Enable strict 'bind', 'call', and 'apply' methods on functions. */, // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */