From 59c89bd40898ff9f400b556918fccd5c7464adb1 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 29 Sep 2024 22:23:36 +0300 Subject: [PATCH] make TS check strictest (#421) --- playwright.config.ts | 7 ++++--- scripts/gen-changelog.ts | 27 ++++++++++++++++----------- src/introspection/introspection.ts | 8 ++++---- src/introspection/utils.ts | 2 +- tsconfig.json | 22 +++++++++++++++++++++- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index d1c95c8d..fd26f748 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,6 +1,7 @@ import type { PlaywrightTestConfig } from '@playwright/test'; import { devices } from '@playwright/test'; +const isCI = !!process.env['CI']; /** * See https://playwright.dev/docs/test-configuration. */ @@ -18,11 +19,11 @@ const config: PlaywrightTestConfig = { /* Run tests in files in parallel */ fullyParallel: true, /* Fail the build on CI if you accidentally left test.only in the source code. */ - forbidOnly: !!process.env.CI, + forbidOnly: isCI, /* Retry on CI only */ - retries: process.env.CI ? 2 : 0, + retries: isCI ? 2 : 0, /* Opt out of parallel tests on CI. */ - workers: process.env.CI ? 1 : undefined, + workers: isCI ? 1 : undefined, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: [['html', { open: 'never' }]], /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ diff --git a/scripts/gen-changelog.ts b/scripts/gen-changelog.ts index 19f8bdcc..074c8c0a 100644 --- a/scripts/gen-changelog.ts +++ b/scripts/gen-changelog.ts @@ -83,7 +83,8 @@ async function genChangeLog(): Promise { .map((label) => label.name) .filter((label) => label.startsWith('PR: ')); - if (labels.length === 0) { + const label = labels[0]; + if (label == null) { throw new Error(`PR is missing label. See ${pr.url}`); } if (labels.length > 1) { @@ -92,7 +93,6 @@ async function genChangeLog(): Promise { ); } - const label = labels[0]; if (labelsConfig[label] == null) { throw new Error(`Unknown label: ${label}. See ${pr.url}`); } @@ -275,22 +275,27 @@ function commitInfoToPR(commit: CommitInfo): number { const associatedPRs = commit.associatedPullRequests.nodes.filter( (pr) => pr.repository.nameWithOwner === `${githubOrg}/${githubRepo}`, ); - if (associatedPRs.length === 0) { - const match = / \(#(?[0-9]+)\)$/m.exec(commit.message); - if (match?.groups?.prNumber != null) { - return parseInt(match.groups.prNumber, 10); - } + + if (associatedPRs.length > 1) { throw new Error( - `Commit ${commit.oid} has no associated PR: ${commit.message}`, + `Commit ${commit.oid} is associated with multiple PRs: ${commit.message}`, ); } - if (associatedPRs.length > 1) { + + const associatedPR = associatedPRs[0]; + if (associatedPR == null) { + const match = / \(#(?[0-9]+)\)$/m.exec(commit.message); + const { prNumber } = match?.groups ?? {}; + + if (prNumber != null) { + return parseInt(prNumber, 10); + } throw new Error( - `Commit ${commit.oid} is associated with multiple PRs: ${commit.message}`, + `Commit ${commit.oid} has no associated PR: ${commit.message}`, ); } - return associatedPRs[0].number; + return associatedPR.number; } async function getPRsInfo( diff --git a/src/introspection/introspection.ts b/src/introspection/introspection.ts index 8a75d078..e85ef662 100644 --- a/src/introspection/introspection.ts +++ b/src/introspection/introspection.ts @@ -65,14 +65,14 @@ function removeRelayTypes(schema: GraphQLSchema) { } const connectionFields = connectionType.getFields(); - const edgeType = getNamedType(connectionFields.edges?.type); - if (!isObjectType(edgeType) || connectionFields.pageInfo == null) { + const edgeType = getNamedType(connectionFields['edges']?.type); + if (!isObjectType(edgeType) || connectionFields['pageInfo'] == null) { continue; } const edgeFields = edgeType.getFields(); - const nodeType = edgeFields.node?.type; - if (nodeType == null || edgeFields.cursor == null) { + const nodeType = edgeFields['node']?.type; + if (nodeType == null || edgeFields['cursor'] == null) { continue; } diff --git a/src/introspection/utils.ts b/src/introspection/utils.ts index 6497f3ea..a2676a7f 100644 --- a/src/introspection/utils.ts +++ b/src/introspection/utils.ts @@ -17,7 +17,7 @@ export function typeNameToId(name: string) { return `TYPE::${name}`; } -export function extractTypeName(typeID: string) { +export function extractTypeName(typeID: string): string { const [, type] = typeID.split('::'); return type; } diff --git a/tsconfig.json b/tsconfig.json index 3bc99c29..170f07f7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,30 @@ { "compilerOptions": { + // copy of https://github.com/tsconfig/bases/blob/main/bases/strictest.json + "strict": true, + "allowUnusedLabels": false, + "allowUnreachableCode": false, + // FIXME: "exactOptionalPropertyTypes": true, + "noFallthroughCasesInSwitch": true, + // FIXME: "noImplicitOverride": true, + "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, + // FIXME: "noUncheckedIndexedAccess": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + + "isolatedModules": true, + + "checkJs": true, + + // FIXME: "esModuleInterop": true, + "skipLibCheck": true, + // end copy + "module": "es2015", "moduleResolution": "node", "target": "es2021", "allowSyntheticDefaultImports": true, - "strict": true, "sourceMap": true, "noEmit": true, "pretty": true,