From 7f3cc12b35468dc0de7a32471edc629d5683c701 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 10 Sep 2022 13:46:23 +0200 Subject: [PATCH] chore: use `@tsconfig/node14` and stricter TS config (#1242) --- package.json | 1 + src/index.ts | 2 +- src/rules/no-commented-out-tests.ts | 2 +- src/rules/no-conditional-in-test.ts | 2 +- src/rules/no-mocks-import.ts | 2 +- src/rules/prefer-each.ts | 2 +- src/rules/prefer-lowercase-title.ts | 2 +- src/rules/require-top-level-describe.ts | 2 +- .../utils/__tests__/detectJestVersion.test.ts | 2 +- .../utils/__tests__/parseJestFnCall.test.ts | 4 ++-- src/rules/utils/detectJestVersion.ts | 2 +- tools/regenerate-docs.ts | 2 +- tsconfig.json | 18 ++++++++++++++---- yarn.lock | 3 ++- 14 files changed, 29 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 3433ad32d..546d8a741 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "@schemastore/package": "^0.0.6", "@semantic-release/changelog": "^6.0.0", "@semantic-release/git": "^10.0.0", + "@tsconfig/node14": "^1.0.3", "@types/dedent": "^0.7.0", "@types/jest": "^29.0.0", "@types/node": "^14.18.26", diff --git a/src/index.ts b/src/index.ts index 44254e380..06e45e2e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { readdirSync } from 'fs'; import { join, parse } from 'path'; -import { TSESLint } from '@typescript-eslint/utils'; +import type { TSESLint } from '@typescript-eslint/utils'; import globals from './globals.json'; import * as snapshotProcessor from './processors/snapshot-processor'; diff --git a/src/rules/no-commented-out-tests.ts b/src/rules/no-commented-out-tests.ts index e5a0b64e1..f933506b6 100644 --- a/src/rules/no-commented-out-tests.ts +++ b/src/rules/no-commented-out-tests.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/utils'; +import type { TSESTree } from '@typescript-eslint/utils'; import { createRule } from './utils'; function hasTests(node: TSESTree.Comment) { diff --git a/src/rules/no-conditional-in-test.ts b/src/rules/no-conditional-in-test.ts index f6ad78fbf..6a58a4f77 100644 --- a/src/rules/no-conditional-in-test.ts +++ b/src/rules/no-conditional-in-test.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/utils'; +import type { TSESTree } from '@typescript-eslint/utils'; import { createRule, isTypeOfJestFnCall } from './utils'; export default createRule({ diff --git a/src/rules/no-mocks-import.ts b/src/rules/no-mocks-import.ts index 2666181fe..784aeee57 100644 --- a/src/rules/no-mocks-import.ts +++ b/src/rules/no-mocks-import.ts @@ -1,5 +1,5 @@ import { posix } from 'path'; -import { TSESTree } from '@typescript-eslint/utils'; +import type { TSESTree } from '@typescript-eslint/utils'; import { createRule, getStringValue, isStringNode } from './utils'; const mocksDirName = '__mocks__'; diff --git a/src/rules/prefer-each.ts b/src/rules/prefer-each.ts index 975869e1a..09976a303 100644 --- a/src/rules/prefer-each.ts +++ b/src/rules/prefer-each.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/utils'; +import type { TSESTree } from '@typescript-eslint/utils'; import { JestFnType, createRule, parseJestFnCall } from './utils'; export default createRule({ diff --git a/src/rules/prefer-lowercase-title.ts b/src/rules/prefer-lowercase-title.ts index ccc077596..b4ab6affa 100644 --- a/src/rules/prefer-lowercase-title.ts +++ b/src/rules/prefer-lowercase-title.ts @@ -1,4 +1,4 @@ -import { TSESLint, TSESTree } from '@typescript-eslint/utils'; +import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; import { CallExpressionWithSingleArgument, DescribeAlias, diff --git a/src/rules/require-top-level-describe.ts b/src/rules/require-top-level-describe.ts index e5e4c3d03..876881e2b 100644 --- a/src/rules/require-top-level-describe.ts +++ b/src/rules/require-top-level-describe.ts @@ -1,4 +1,4 @@ -import { TSESTree } from '@typescript-eslint/utils'; +import type { TSESTree } from '@typescript-eslint/utils'; import { createRule, isTypeOfJestFnCall, parseJestFnCall } from './utils'; const messages = { diff --git a/src/rules/utils/__tests__/detectJestVersion.test.ts b/src/rules/utils/__tests__/detectJestVersion.test.ts index 1611d3032..1aec7460f 100644 --- a/src/rules/utils/__tests__/detectJestVersion.test.ts +++ b/src/rules/utils/__tests__/detectJestVersion.test.ts @@ -2,7 +2,7 @@ import { spawnSync } from 'child_process'; import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; +import type { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; import { create } from 'ts-node'; import { detectJestVersion } from '../detectJestVersion'; diff --git a/src/rules/utils/__tests__/parseJestFnCall.test.ts b/src/rules/utils/__tests__/parseJestFnCall.test.ts index 3ecaa04de..e4526b791 100644 --- a/src/rules/utils/__tests__/parseJestFnCall.test.ts +++ b/src/rules/utils/__tests__/parseJestFnCall.test.ts @@ -1,4 +1,4 @@ -import { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; +import type { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; import { TSESLint, TSESTree } from '@typescript-eslint/utils'; import dedent from 'dedent'; import { espreeParser } from '../../__tests__/test-utils'; @@ -76,7 +76,7 @@ const rule = createRule({ messageId: 'details', node, data: { - data: JSON.stringify(sorted, (key, value) => { + data: JSON.stringify(sorted, (_key, value) => { if (isNode(value)) { if (isSupportedAccessor(value)) { return getAccessorValue(value); diff --git a/src/rules/utils/detectJestVersion.ts b/src/rules/utils/detectJestVersion.ts index 0e5ba5bea..fed1f0b99 100644 --- a/src/rules/utils/detectJestVersion.ts +++ b/src/rules/utils/detectJestVersion.ts @@ -1,4 +1,4 @@ -import { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; +import type { JSONSchemaForNPMPackageJsonFiles } from '@schemastore/package'; export type JestVersion = | 14 diff --git a/tools/regenerate-docs.ts b/tools/regenerate-docs.ts index 4f404da04..975554c22 100644 --- a/tools/regenerate-docs.ts +++ b/tools/regenerate-docs.ts @@ -2,7 +2,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import { TSESLint } from '@typescript-eslint/utils'; +import type { TSESLint } from '@typescript-eslint/utils'; import prettier, { Options } from 'prettier'; import { prettier as prettierRC } from '../package.json'; import config from '../src/index'; diff --git a/tsconfig.json b/tsconfig.json index 2b4f96ad5..ba737fdeb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,25 @@ { + "extends": "@tsconfig/node14/tsconfig.json", "compilerOptions": { - "target": "es2015", - "module": "commonjs", "moduleResolution": "node", - "lib": ["es2018"], "noEmit": true, + "importsNotUsedAsValues": "error", + "stripInternal": true, + + /* Additional Checks */ + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitOverride": true, "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "strict": true, "esModuleInterop": true, "resolveJsonModule": true, + "isolatedModules": true, + "skipLibCheck": false, "forceConsistentCasingInFileNames": true }, - "include": ["src/**/*", "tools/**/*"] + "include": ["src/**/*", "tools/**/*"], + "exclude": ["src/rules/__tests__/fixtures/**/*"] } diff --git a/yarn.lock b/yarn.lock index 07cb52486..e692ee937 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2506,7 +2506,7 @@ __metadata: languageName: node linkType: hard -"@tsconfig/node14@npm:^1.0.0": +"@tsconfig/node14@npm:^1.0.0, @tsconfig/node14@npm:^1.0.3": version: 1.0.3 resolution: "@tsconfig/node14@npm:1.0.3" checksum: 19275fe80c4c8d0ad0abed6a96dbf00642e88b220b090418609c4376e1cef81bf16237bf170ad1b341452feddb8115d8dd2e5acdfdea1b27422071163dc9ba9d @@ -4570,6 +4570,7 @@ __metadata: "@schemastore/package": ^0.0.6 "@semantic-release/changelog": ^6.0.0 "@semantic-release/git": ^10.0.0 + "@tsconfig/node14": ^1.0.3 "@types/dedent": ^0.7.0 "@types/jest": ^29.0.0 "@types/node": ^14.18.26