From 24e0472ac41ea03cdd89ffaea8c5f410ecf6054f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 3 Jun 2022 10:28:16 +0200 Subject: [PATCH] chore(lint): enable recommended configs (#12902) --- .eslintrc.cjs | 24 +++++++++++++++++++ e2e/__tests__/multiProjectRunner.test.ts | 6 ++--- e2e/__tests__/runProgrammatically.test.ts | 4 ++-- e2e/__tests__/version.test.ts | 2 +- .../empty-sourcemap/types.ts | 1 + .../__tests__/snapshotEscapeRegex.js | 2 +- packages/babel-plugin-jest-hoist/src/index.ts | 1 + packages/expect/src/index.ts | 1 + packages/jest-circus/src/index.ts | 1 + .../jestAdapterInit.ts | 2 +- packages/jest-circus/src/run.ts | 1 + packages/jest-circus/src/types.ts | 1 + packages/jest-cli/src/init/errors.ts | 2 ++ packages/jest-config/src/utils.ts | 2 +- packages/jest-console/src/NullConsole.ts | 1 + packages/jest-core/src/cli/index.ts | 1 + packages/jest-environment-jsdom/src/index.ts | 3 ++- packages/jest-environment-node/src/index.ts | 3 ++- .../jest-fake-timers/src/modernFakeTimers.ts | 2 +- .../src/watchers/FSEventsWatcher.ts | 2 +- packages/jest-jasmine2/src/PCancelable.ts | 1 + packages/jest-jasmine2/src/errorOnPrivate.ts | 2 +- packages/jest-jasmine2/src/index.ts | 2 +- packages/jest-jasmine2/src/jasmine/Env.ts | 1 + .../src/jasmine/JsApiReporter.ts | 2 +- .../src/jasmine/ReportDispatcher.ts | 14 +++++------ packages/jest-jasmine2/src/jasmine/Spec.ts | 8 ++++--- .../jest-jasmine2/src/jasmine/SpyStrategy.ts | 2 +- packages/jest-jasmine2/src/jasmine/Suite.ts | 2 ++ .../jest-jasmine2/src/jasmine/jasmineLight.ts | 1 + .../jest-jasmine2/src/jasmineAsyncInstall.ts | 8 ++++++- packages/jest-jasmine2/src/reporter.ts | 1 + .../jest-jasmine2/src/setup_jest_globals.ts | 4 ++-- packages/jest-jasmine2/src/treeProcessor.ts | 7 ++++-- packages/jest-jasmine2/src/types.ts | 2 ++ packages/jest-leak-detector/src/index.ts | 2 +- packages/jest-message-util/src/index.ts | 4 ++-- .../jest-mock/src/__tests__/index.test.ts | 4 ++++ packages/jest-mock/src/index.ts | 9 ++++--- packages/jest-reporters/src/BaseReporter.ts | 2 ++ packages/jest-runner/src/runTest.ts | 2 +- .../__tests__/runtime_require_mock.test.js | 2 +- packages/jest-runtime/src/index.ts | 15 ++++++------ packages/jest-snapshot/src/InlineSnapshots.ts | 11 +++++---- packages/jest-snapshot/src/State.ts | 2 +- packages/jest-snapshot/src/dedentLines.ts | 2 +- .../jest-transform/src/ScriptTransformer.ts | 1 + packages/jest-types/src/Global.ts | 1 + packages/jest-validate/src/condition.ts | 4 ++-- packages/jest-validate/src/exampleConfig.ts | 2 ++ packages/jest-validate/src/utils.ts | 1 + packages/jest-watcher/src/BaseWatchPlugin.ts | 2 ++ packages/jest-watcher/src/lib/Prompt.ts | 2 ++ packages/jest-worker/__benchmarks__/test.js | 2 ++ .../jest-worker/src/base/BaseWorkerPool.ts | 1 + packages/jest-worker/src/types.ts | 16 ++++++------- .../src/workers/ChildProcessWorker.ts | 1 + .../src/__tests__/setPrettyPrint.ts | 1 + scripts/checkCopyrightHeaders.mjs | 2 +- scripts/watch.mjs | 2 +- 60 files changed, 145 insertions(+), 67 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 30f531b14487..cdd36255e1e9 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable sort-keys */ + const fs = require('fs'); const path = require('path'); const {sync: readPkg} = require('read-pkg'); @@ -27,6 +29,7 @@ module.exports = { 'jest/globals': true, }, extends: [ + 'eslint:recommended', 'plugin:markdown/recommended', 'plugin:import/errors', 'plugin:eslint-comments/recommended', @@ -38,6 +41,7 @@ module.exports = { overrides: [ { extends: [ + 'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/eslint-recommended', 'plugin:import/typescript', ], @@ -52,10 +56,14 @@ module.exports = { {argsIgnorePattern: '^_'}, ], '@typescript-eslint/prefer-ts-expect-error': 'error', + '@typescript-eslint/no-var-requires': 'off', // TS verifies these 'consistent-return': 'off', 'no-dupe-class-members': 'off', 'no-unused-vars': 'off', + // TODO: enable at some point + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', }, }, { @@ -144,6 +152,9 @@ module.exports = { files: ['**/*.md/**'], rules: { '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-namespace': 'off', + '@typescript-eslint/no-empty-interface': 'off', 'arrow-body-style': 'off', 'consistent-return': 'off', 'import/export': 'off', @@ -201,6 +212,13 @@ module.exports = { ], }, }, + { + files: ['**/__tests__/**', '**/__mocks__/**'], + rules: { + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/no-empty-function': 'off', + }, + }, { files: [ '**/__tests__/**', @@ -247,6 +265,12 @@ module.exports = { 'import/no-extraneous-dependencies': 'off', }, }, + { + files: ['**/__typetests__/**'], + rules: { + '@typescript-eslint/no-empty-function': 'off', + }, + }, { files: [ '**/__typetests__/**', diff --git a/e2e/__tests__/multiProjectRunner.test.ts b/e2e/__tests__/multiProjectRunner.test.ts index 50dd3d04af21..589974ae592a 100644 --- a/e2e/__tests__/multiProjectRunner.test.ts +++ b/e2e/__tests__/multiProjectRunner.test.ts @@ -49,7 +49,7 @@ test('can pass projects or global config', () => { getHasteName(filename) { return filename .substr(filename.lastIndexOf(path.sep) + 1) - .replace(/\.js$/, ''); + .replace(/\\.js$/, ''); }, }; `, @@ -446,7 +446,7 @@ test('Does transform files with the corresponding project transformer', () => { 'project1/jest.config.js': ` module.exports = { rootDir: './', - transform: {'file\.js': './transformer.js'}, + transform: {'file\\.js': './transformer.js'}, };`, 'project1/transformer.js': ` module.exports = { @@ -461,7 +461,7 @@ test('Does transform files with the corresponding project transformer', () => { 'project2/jest.config.js': ` module.exports = { rootDir: './', - transform: {'file\.js': './transformer.js'}, + transform: {'file\\.js': './transformer.js'}, };`, 'project2/transformer.js': ` module.exports = { diff --git a/e2e/__tests__/runProgrammatically.test.ts b/e2e/__tests__/runProgrammatically.test.ts index d4dbc8b6345f..6d1fc6857636 100644 --- a/e2e/__tests__/runProgrammatically.test.ts +++ b/e2e/__tests__/runProgrammatically.test.ts @@ -12,10 +12,10 @@ const dir = resolve(__dirname, '..', 'run-programmatically'); test('run Jest programmatically cjs', () => { const {stdout} = run('node cjs.js --version', dir); - expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/); + expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[-\S]*-dev$/); }); test('run Jest programmatically esm', () => { const {stdout} = run('node index.js --version', dir); - expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/); + expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[-\S]*-dev$/); }); diff --git a/e2e/__tests__/version.test.ts b/e2e/__tests__/version.test.ts index 54df9a3dca4a..564e6aa8c79f 100644 --- a/e2e/__tests__/version.test.ts +++ b/e2e/__tests__/version.test.ts @@ -22,7 +22,7 @@ test('works with jest.config.js', () => { }); const {exitCode, stdout, stderr} = runJest(DIR, ['--version']); - expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/); + expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[-\S]*-dev$/); // Only version gets printed and nothing else expect(stdout.split(/\n/)).toHaveLength(1); expect(stderr).toBe(''); diff --git a/e2e/coverage-provider-v8/empty-sourcemap/types.ts b/e2e/coverage-provider-v8/empty-sourcemap/types.ts index 3f87a5afc924..40c64863155c 100644 --- a/e2e/coverage-provider-v8/empty-sourcemap/types.ts +++ b/e2e/coverage-provider-v8/empty-sourcemap/types.ts @@ -5,4 +5,5 @@ * LICENSE file in the root directory of this source tree. */ +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface obj {} diff --git a/e2e/snapshot-escape/__tests__/snapshotEscapeRegex.js b/e2e/snapshot-escape/__tests__/snapshotEscapeRegex.js index f5751fd83d80..9d91f8159556 100644 --- a/e2e/snapshot-escape/__tests__/snapshotEscapeRegex.js +++ b/e2e/snapshot-escape/__tests__/snapshotEscapeRegex.js @@ -6,7 +6,7 @@ */ 'use strict'; -const regex = /\dd\ \s+ \w \\\[ \. blahzz.* [xyz]+/; +const regex = /\dd \s+ \w \\\[ \. blahzz.* [xyz]+/; test('escape regex', () => expect(regex).toMatchSnapshot()); diff --git a/packages/babel-plugin-jest-hoist/src/index.ts b/packages/babel-plugin-jest-hoist/src/index.ts index 47d6dba84890..d77ff26afded 100644 --- a/packages/babel-plugin-jest-hoist/src/index.ts +++ b/packages/babel-plugin-jest-hoist/src/index.ts @@ -305,6 +305,7 @@ export default function jestHoist(): PluginObj<{ }, // in `post` to make sure we come after an import transform and can unshift above the `require`s post({path: program}) { + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; visitBlock(program); diff --git a/packages/expect/src/index.ts b/packages/expect/src/index.ts index 4511b9e0b8bb..b6bd5505d013 100644 --- a/packages/expect/src/index.ts +++ b/packages/expect/src/index.ts @@ -64,6 +64,7 @@ export class JestAssertionError extends Error { matcherResult?: Omit & {message: string}; } +// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint const isPromise = (obj: any): obj is PromiseLike => !!obj && (typeof obj === 'object' || typeof obj === 'function') && diff --git a/packages/jest-circus/src/index.ts b/packages/jest-circus/src/index.ts index 7d49ba1ddc07..21974ebc5e18 100644 --- a/packages/jest-circus/src/index.ts +++ b/packages/jest-circus/src/index.ts @@ -155,6 +155,7 @@ const test: Global.It = (() => { test.todo, ); } + // eslint-disable-next-line @typescript-eslint/no-empty-function return _addTest(testName, 'todo', false, () => {}, test.todo); }; diff --git a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts index 6e00f54eed5f..e160c964d226 100644 --- a/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts +++ b/packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts @@ -63,7 +63,7 @@ export const initialize = async ({ } getRunnerState().maxConcurrency = globalConfig.maxConcurrency; - // @ts-expect-error + // @ts-expect-error: missing `concurrent` which is added later const globalsObject: Global.TestFrameworkGlobals = { ...globals, fdescribe: globals.describe.only, diff --git a/packages/jest-circus/src/run.ts b/packages/jest-circus/src/run.ts index 4a944d186c2d..8d8242b6c203 100644 --- a/packages/jest-circus/src/run.ts +++ b/packages/jest-circus/src/run.ts @@ -52,6 +52,7 @@ const _runTestsForDescribeBlock = async ( const promise = mutex(test.fn); // Avoid triggering the uncaught promise rejection handler in case the // test errors before being awaited on. + // eslint-disable-next-line @typescript-eslint/no-empty-function promise.catch(() => {}); test.fn = () => promise; } catch (err) { diff --git a/packages/jest-circus/src/types.ts b/packages/jest-circus/src/types.ts index 9192e2412b2d..17a4019d3251 100644 --- a/packages/jest-circus/src/types.ts +++ b/packages/jest-circus/src/types.ts @@ -14,6 +14,7 @@ export const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL'); export const LOG_ERRORS_BEFORE_RETRY = Symbol.for('LOG_ERRORS_BEFORE_RETRY'); declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace namespace NodeJS { interface Global { [STATE_SYM]: Circus.State; diff --git a/packages/jest-cli/src/init/errors.ts b/packages/jest-cli/src/init/errors.ts index 2c85b6585a7f..f828c41858ba 100644 --- a/packages/jest-cli/src/init/errors.ts +++ b/packages/jest-cli/src/init/errors.ts @@ -9,6 +9,7 @@ export class NotFoundPackageJsonError extends Error { constructor(rootDir: string) { super(`Could not find a "package.json" file in ${rootDir}`); this.name = ''; + // eslint-disable-next-line @typescript-eslint/no-empty-function Error.captureStackTrace(this, () => {}); } } @@ -20,6 +21,7 @@ export class MalformedPackageJsonError extends Error { 'Fix it, and then run "jest --init"', ); this.name = ''; + // eslint-disable-next-line @typescript-eslint/no-empty-function Error.captureStackTrace(this, () => {}); } } diff --git a/packages/jest-config/src/utils.ts b/packages/jest-config/src/utils.ts index c32b717a0fbd..9d60f8fc9573 100644 --- a/packages/jest-config/src/utils.ts +++ b/packages/jest-config/src/utils.ts @@ -52,7 +52,7 @@ export const resolve = ( }; export const escapeGlobCharacters = (path: string): string => - path.replace(/([()*{}\[\]!?\\])/g, '\\$1'); + path.replace(/([()*{}[\]!?\\])/g, '\\$1'); export const replaceRootDirInPath = ( rootDir: string, diff --git a/packages/jest-console/src/NullConsole.ts b/packages/jest-console/src/NullConsole.ts index de8d3e2ba5e2..7ade28629ac4 100644 --- a/packages/jest-console/src/NullConsole.ts +++ b/packages/jest-console/src/NullConsole.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-empty-function */ /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * diff --git a/packages/jest-core/src/cli/index.ts b/packages/jest-core/src/cli/index.ts index 478b7f0d9cc4..29487d5aff3c 100644 --- a/packages/jest-core/src/cli/index.ts +++ b/packages/jest-core/src/cli/index.ts @@ -105,6 +105,7 @@ export async function runCLI( // If in watch mode, return the promise that will never resolve. // If the watch mode is interrupted, watch should handle the process // shutdown. + // eslint-disable-next-line @typescript-eslint/no-empty-function return new Promise(() => {}); } diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 17dd28dbba10..7ae1345df4be 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -142,6 +142,7 @@ export default class JSDOMEnvironment implements JestEnvironment { }); } + // eslint-disable-next-line @typescript-eslint/no-empty-function async setup(): Promise {} async teardown(): Promise { @@ -165,7 +166,7 @@ export default class JSDOMEnvironment implements JestEnvironment { Object.defineProperty(this.global, 'document', {value: null}); } this.errorEventListener = null; - // @ts-expect-error + // @ts-expect-error: this.global not allowed to be `null` this.global = null; this.dom = null; this.fakeTimers = null; diff --git a/packages/jest-environment-node/src/index.ts b/packages/jest-environment-node/src/index.ts index 7b5f8b9861b7..96c5db2acffa 100644 --- a/packages/jest-environment-node/src/index.ts +++ b/packages/jest-environment-node/src/index.ts @@ -77,7 +77,7 @@ export default class NodeEnvironment implements JestEnvironment { configurable: descriptor.configurable, enumerable: descriptor.enumerable, get() { - // @ts-expect-error + // @ts-expect-error: no index signature const val = globalThis[nodeGlobalsKey]; // override lazy getter @@ -157,6 +157,7 @@ export default class NodeEnvironment implements JestEnvironment { }); } + // eslint-disable-next-line @typescript-eslint/no-empty-function async setup(): Promise {} async teardown(): Promise { diff --git a/packages/jest-fake-timers/src/modernFakeTimers.ts b/packages/jest-fake-timers/src/modernFakeTimers.ts index f8363388c9ce..633ddd22272a 100644 --- a/packages/jest-fake-timers/src/modernFakeTimers.ts +++ b/packages/jest-fake-timers/src/modernFakeTimers.ts @@ -80,7 +80,7 @@ export default class FakeTimers { runAllTicks(): void { if (this._checkFakeTimers()) { - // @ts-expect-error + // @ts-expect-error - doesn't exist? this._clock.runMicrotasks(); } } diff --git a/packages/jest-haste-map/src/watchers/FSEventsWatcher.ts b/packages/jest-haste-map/src/watchers/FSEventsWatcher.ts index bb39acf233c4..da9530af2520 100644 --- a/packages/jest-haste-map/src/watchers/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/watchers/FSEventsWatcher.ts @@ -14,7 +14,7 @@ import micromatch = require('micromatch'); // @ts-expect-error no types import walker from 'walker'; -// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error +// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment // @ts-ignore: this is for CI which runs linux and might not have this let fsevents: typeof import('fsevents') | null = null; try { diff --git a/packages/jest-jasmine2/src/PCancelable.ts b/packages/jest-jasmine2/src/PCancelable.ts index 2c7b0aa826fe..4bc49293803d 100644 --- a/packages/jest-jasmine2/src/PCancelable.ts +++ b/packages/jest-jasmine2/src/PCancelable.ts @@ -17,6 +17,7 @@ export default class PCancelable implements PromiseLike { private _canceled = false; private _promise: Promise; private _cancel?: () => void; + // eslint-disable-next-line @typescript-eslint/no-empty-function private _reject: (reason?: unknown) => void = () => {}; constructor( diff --git a/packages/jest-jasmine2/src/errorOnPrivate.ts b/packages/jest-jasmine2/src/errorOnPrivate.ts index 56874b058de4..db94d0e34afa 100644 --- a/packages/jest-jasmine2/src/errorOnPrivate.ts +++ b/packages/jest-jasmine2/src/errorOnPrivate.ts @@ -52,7 +52,7 @@ export function installErrorOnPrivate(global: Global.Global): void { ( Object.keys(disabledJasmineMethods) as Array ).forEach(methodName => { - // @ts-expect-error + // @ts-expect-error - void unallowd, but it throws 🤷 jasmine[methodName] = () => { throwAtFunction(disabledJasmineMethods[methodName], jasmine[methodName]); }; diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index e09cbcc941cd..417c5262f0be 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -64,7 +64,7 @@ export default async function jasmine2( if (stack.getFileName()?.startsWith(jestEachBuildDir)) { stack = getCallsite(4, sourcemaps); } - // @ts-expect-error + // @ts-expect-error: `it` is `void` for some reason it.result.__callsite = stack; return it; diff --git a/packages/jest-jasmine2/src/jasmine/Env.ts b/packages/jest-jasmine2/src/jasmine/Env.ts index 16a7b6f50000..803508dee57e 100644 --- a/packages/jest-jasmine2/src/jasmine/Env.ts +++ b/packages/jest-jasmine2/src/jasmine/Env.ts @@ -599,6 +599,7 @@ export default function jasmineEnv(j$: Jasmine) { const spec = specFactory( description, + // eslint-disable-next-line @typescript-eslint/no-empty-function () => {}, currentDeclarationSuite, ); diff --git a/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts b/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts index b206b5408e84..86f85b897174 100644 --- a/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts +++ b/packages/jest-jasmine2/src/jasmine/JsApiReporter.ts @@ -28,7 +28,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/* eslint-disable sort-keys */ +/* eslint-disable sort-keys, @typescript-eslint/no-empty-function */ import type {Reporter, RunDetails} from '../types'; import type {SpecResult} from './Spec'; import type {SuiteResult} from './Suite'; diff --git a/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts b/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts index e06f5712c1c1..9aaa2a157035 100644 --- a/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts +++ b/packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts @@ -40,17 +40,17 @@ export default class ReportDispatcher implements Reporter { provideFallbackReporter: (reporter: Reporter) => void; clearReporters: () => void; - // @ts-expect-error + // @ts-expect-error: confused by loop in ctor jasmineDone: (runDetails: RunDetails) => void; - // @ts-expect-error + // @ts-expect-error: confused by loop in ctor jasmineStarted: (runDetails: RunDetails) => void; - // @ts-expect-error + // @ts-expect-error: confused by loop in ctor specDone: (result: SpecResult) => void; - // @ts-expect-error + // @ts-expect-error: confused by loop in ctor specStarted: (spec: SpecResult) => void; - // @ts-expect-error + // @ts-expect-error: confused by loop in ctor suiteDone: (result: SuiteResult) => void; - // @ts-expect-error + // @ts-expect-error: confused by loop in ctor suiteStarted: (result: SuiteResult) => void; constructor(methods: Array) { @@ -89,7 +89,7 @@ export default class ReportDispatcher implements Reporter { for (let i = 0; i < reporters.length; i++) { const reporter = reporters[i]; if (reporter[method]) { - // @ts-expect-error + // @ts-expect-error: wrong context reporter[method].apply(reporter, args); } } diff --git a/packages/jest-jasmine2/src/jasmine/Spec.ts b/packages/jest-jasmine2/src/jasmine/Spec.ts index bb020debc2dd..9300c3fe416c 100644 --- a/packages/jest-jasmine2/src/jasmine/Spec.ts +++ b/packages/jest-jasmine2/src/jasmine/Spec.ts @@ -28,7 +28,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/* eslint-disable sort-keys, local/prefer-spread-eventually, local/prefer-rest-params-eventually */ +/* eslint-disable sort-keys, local/prefer-spread-eventually, local/prefer-rest-params-eventually, @typescript-eslint/no-empty-function */ import {AssertionError} from 'assert'; import type {FailedAssertion, Milliseconds, Status} from '@jest/test-result'; @@ -138,11 +138,12 @@ export default class Spec { // in the stack in the Error object. This line stringifies the stack // property to allow garbage-collecting objects on the stack // https://crbug.com/v8/7142 + // eslint-disable-next-line no-self-assign this.initError.stack = this.initError.stack; this.queueableFn.initError = this.initError; - // @ts-expect-error + // @ts-expect-error: misses some fields added later this.result = { id: this.id, description: this.description, @@ -172,6 +173,7 @@ export default class Spec { } execute(onComplete?: () => void, enabled?: boolean) { + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this; this.onStart(this); @@ -192,7 +194,7 @@ export default class Spec { this.currentRun = this.queueRunnerFactory({ queueableFns: allFns, onException() { - // @ts-expect-error + // @ts-expect-error: wrong context self.onException.apply(self, arguments); }, userContext: this.userContext(), diff --git a/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts b/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts index 280bc6bd7b05..ffc11d5df19b 100644 --- a/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts +++ b/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts @@ -29,7 +29,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually */ +/* eslint-disable local/ban-types-eventually, local/prefer-rest-params-eventually, @typescript-eslint/no-empty-function */ export default class SpyStrategy { identity: () => string; diff --git a/packages/jest-jasmine2/src/jasmine/Suite.ts b/packages/jest-jasmine2/src/jasmine/Suite.ts index 14a4ed10f8e6..7b1a3ba03d17 100644 --- a/packages/jest-jasmine2/src/jasmine/Suite.ts +++ b/packages/jest-jasmine2/src/jasmine/Suite.ts @@ -100,6 +100,7 @@ export default class Suite { getFullName() { const fullName = []; for ( + // eslint-disable-next-line @typescript-eslint/no-this-alias let parentSuite: Suite | undefined = this; parentSuite; parentSuite = parentSuite.parentSuite @@ -215,6 +216,7 @@ export default class Suite { } } + // eslint-disable-next-line @typescript-eslint/no-empty-function execute(..._args: Array) {} } diff --git a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts index 4cb23daaaf3f..87c9324070c7 100644 --- a/packages/jest-jasmine2/src/jasmine/jasmineLight.ts +++ b/packages/jest-jasmine2/src/jasmine/jasmineLight.ts @@ -43,6 +43,7 @@ import SpyRegistry from './spyRegistry'; const testTimeoutSymbol = Symbol.for('TEST_TIMEOUT_SYMBOL'); declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace namespace NodeJS { interface Global { [testTimeoutSymbol]: number; diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index 5e0cb5288bc6..b4023ba58474 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -23,8 +23,10 @@ function isPromise(obj: any): obj is PromiseLike { return obj && typeof obj.then === 'function'; } +// eslint-disable-next-line @typescript-eslint/no-empty-function const doneFnNoop = () => {}; +// eslint-disable-next-line @typescript-eslint/no-empty-function doneFnNoop.fail = () => {}; function promisifyLifeCycleFunction( @@ -70,6 +72,7 @@ function promisifyLifeCycleFunction( // in the stack in the Error object. This line stringifies the stack // property to allow garbage-collecting objects on the stack // https://crbug.com/v8/7142 + // eslint-disable-next-line no-self-assign extraError.stack = extraError.stack; // We make *all* functions async and run `done` right away if they @@ -145,6 +148,7 @@ function promisifyIt( // in the stack in the Error object. This line stringifies the stack // property to allow garbage-collecting objects on the stack // https://crbug.com/v8/7142 + // eslint-disable-next-line no-self-assign extraError.stack = extraError.stack; const asyncJestTest = function (done: DoneFn) { @@ -217,11 +221,13 @@ function makeConcurrent( } // Avoid triggering the uncaught promise rejection handler in case the test errors before // being awaited on. + // eslint-disable-next-line @typescript-eslint/no-empty-function promise.catch(() => {}); return spec; }; - // each is binded after the function is made concurrent, so for now it is made noop + // each is bound after the function is made concurrent, so for now it is made noop + // eslint-disable-next-line @typescript-eslint/no-empty-function concurrentFn.each = () => () => {}; concurrentFn.failing = () => () => { throw new Error( diff --git a/packages/jest-jasmine2/src/reporter.ts b/packages/jest-jasmine2/src/reporter.ts index ad94e6b3ac09..a82caa84100c 100644 --- a/packages/jest-jasmine2/src/reporter.ts +++ b/packages/jest-jasmine2/src/reporter.ts @@ -43,6 +43,7 @@ export default class Jasmine2Reporter implements Reporter { this._startTimes = new Map(); } + // eslint-disable-next-line @typescript-eslint/no-empty-function jasmineStarted(_runDetails: RunDetails): void {} specStarted(spec: SpecResult): void { diff --git a/packages/jest-jasmine2/src/setup_jest_globals.ts b/packages/jest-jasmine2/src/setup_jest_globals.ts index 1a8cec06c940..635546f8fbbf 100644 --- a/packages/jest-jasmine2/src/setup_jest_globals.ts +++ b/packages/jest-jasmine2/src/setup_jest_globals.ts @@ -63,7 +63,7 @@ const addAssertionErrors = (result: SpecResult) => { }; const patchJasmine = () => { - // @ts-expect-error + // @ts-expect-error: jasmine doesn't exist on globalThis globalThis.jasmine.Spec = (realSpec => { class Spec extends realSpec { constructor(attr: Attributes) { @@ -83,7 +83,7 @@ const patchJasmine = () => { } return Spec; - // @ts-expect-error + // @ts-expect-error: jasmine doesn't exist on globalThis })(globalThis.jasmine.Spec); }; diff --git a/packages/jest-jasmine2/src/treeProcessor.ts b/packages/jest-jasmine2/src/treeProcessor.ts index 59d40680a232..d7906280f98e 100644 --- a/packages/jest-jasmine2/src/treeProcessor.ts +++ b/packages/jest-jasmine2/src/treeProcessor.ts @@ -25,6 +25,9 @@ export type TreeNode = { children?: Array; } & Pick; +// eslint-disable-next-line @typescript-eslint/no-empty-function +const noop = () => {}; + export default function treeProcessor(options: Options): void { const {nodeComplete, nodeStart, queueRunnerFactory, runnableIds, tree} = options; @@ -41,13 +44,13 @@ export default function treeProcessor(options: Options): void { } function getNodeWithoutChildrenHandler(node: TreeNode, enabled: boolean) { - return function fn(done: (error?: unknown) => void = () => {}) { + return function fn(done: (error?: unknown) => void = noop) { node.execute(done, enabled); }; } function getNodeWithChildrenHandler(node: TreeNode, enabled: boolean) { - return async function fn(done: (error?: unknown) => void = () => {}) { + return async function fn(done: (error?: unknown) => void = noop) { nodeStart(node); await queueRunnerFactory({ onException: (error: Error) => node.onException(error), diff --git a/packages/jest-jasmine2/src/types.ts b/packages/jest-jasmine2/src/types.ts index 427f1aaefe4e..9aa520a10f7d 100644 --- a/packages/jest-jasmine2/src/types.ts +++ b/packages/jest-jasmine2/src/types.ts @@ -72,6 +72,7 @@ export type Jasmine = { } & AsymmetricMatchers & {process: NodeJS.Process}; declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace namespace NodeJS { interface Global { expect: JestExpect; @@ -81,6 +82,7 @@ declare global { } declare module '@jest/types' { + // eslint-disable-next-line @typescript-eslint/no-namespace namespace Global { interface GlobalAdditions { jasmine: Jasmine; diff --git a/packages/jest-leak-detector/src/index.ts b/packages/jest-leak-detector/src/index.ts index 0ec02801040d..33a5e8cefe97 100644 --- a/packages/jest-leak-detector/src/index.ts +++ b/packages/jest-leak-detector/src/index.ts @@ -61,7 +61,7 @@ export default class LeakDetector { } private _runGarbageCollector() { - // @ts-expect-error + // @ts-expect-error: not a function on `globalThis` const isGarbageCollectorHidden = globalThis.gc == null; // GC is usually hidden, so we have to expose it before running. diff --git a/packages/jest-message-util/src/index.ts b/packages/jest-message-util/src/index.ts index b26ab2310aa2..7ef98dda1931 100644 --- a/packages/jest-message-util/src/index.ts +++ b/packages/jest-message-util/src/index.ts @@ -46,7 +46,7 @@ const PATH_JEST_PACKAGES = `${path.sep}jest${path.sep}packages${path.sep}`; // filter for noisy stack trace lines const JASMINE_IGNORE = - /^\s+at(?:(?:.jasmine\-)|\s+jasmine\.buildExpectationResult)/; + /^\s+at(?:(?:.jasmine-)|\s+jasmine\.buildExpectationResult)/; const JEST_INTERNALS_IGNORE = /^\s+at.*?jest(-.*?)?(\/|\\)(build|node_modules|packages)(\/|\\)/; const ANONYMOUS_FN_IGNORE = /^\s+at .*$/; @@ -59,7 +59,7 @@ const STACK_INDENT = ' '; const ANCESTRY_SEPARATOR = ' \u203A '; const TITLE_BULLET = chalk.bold('\u25cf '); const STACK_TRACE_COLOR = chalk.dim; -const STACK_PATH_REGEXP = /\s*at.*\(?(\:\d*\:\d*|native)\)?/; +const STACK_PATH_REGEXP = /\s*at.*\(?(:\d*:\d*|native)\)?/; const EXEC_ERROR_MESSAGE = 'Test suite failed to run'; const NOT_EMPTY_LINE_REGEXP = /^(?!$)/gm; diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index 07a4706f29a5..6b9f716d7ef0 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -1168,6 +1168,7 @@ describe('moduleMocker', () => { const obj = { method() { isOriginalCalled = true; + // eslint-disable-next-line @typescript-eslint/no-this-alias originalCallThis = this; originalCallArguments = arguments; }, @@ -1255,6 +1256,7 @@ describe('moduleMocker', () => { get method() { return function () { isOriginalCalled = true; + // eslint-disable-next-line @typescript-eslint/no-this-alias originalCallThis = this; originalCallArguments = arguments; }; @@ -1309,6 +1311,7 @@ describe('moduleMocker', () => { get method() { return function () { isOriginalCalled = true; + // eslint-disable-next-line @typescript-eslint/no-this-alias originalCallThis = this; originalCallArguments = arguments; }; @@ -1423,6 +1426,7 @@ describe('moduleMocker', () => { get method() { return function () { isOriginalCalled = true; + // eslint-disable-next-line @typescript-eslint/no-this-alias originalCallThis = this; originalCallArguments = arguments; }; diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index c2f31b82ff36..90c90be26ab8 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -160,6 +160,7 @@ export interface MockInstance { mockRejectedValueOnce(value: RejectType): this; } +// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface SpyInstance extends MockInstance {} @@ -230,7 +231,7 @@ type MockFunctionConfig = { const MOCK_CONSTRUCTOR_NAME = 'mockConstructor'; -const FUNCTION_NAME_RESERVED_PATTERN = /[\s!-\/:-@\[-`{-~]/; +const FUNCTION_NAME_RESERVED_PATTERN = /[\s!-/:-@[-`{-~]/; const FUNCTION_NAME_RESERVED_REPLACE = new RegExp( FUNCTION_NAME_RESERVED_PATTERN.source, 'g', @@ -633,6 +634,7 @@ export class ModuleMocker { metadata.members.prototype.members) || {}; const prototypeSlots = this._getSlots(prototype); + // eslint-disable-next-line @typescript-eslint/no-this-alias const mocker = this; const mockConstructor = matchArity(function ( this: ReturnType, @@ -896,7 +898,7 @@ export class ModuleMocker { ): Mock { // metadata not compatible but it's the same type, maybe problem with // overloading of _makeComponent and not _generateMock? - // @ts-expect-error + // @ts-expect-error - unsure why TSC complains here? const mock = this._makeComponent(metadata); if (metadata.refID != null) { refs[metadata.refID] = mock; @@ -1020,6 +1022,7 @@ export class ModuleMocker { isMockFunction( fn: SpyInstance, ): fn is SpyInstance; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint isMockFunction

, R extends unknown>( fn: (...args: P) => R, ): fn is Mock<(...args: P) => R>; @@ -1207,7 +1210,7 @@ export class ModuleMocker { (descriptor[accessType] as Mock<() => T>).mockImplementation(function ( this: unknown, ) { - // @ts-expect-error + // @ts-expect-error - wrong context return original.apply(this, arguments); }); } diff --git a/packages/jest-reporters/src/BaseReporter.ts b/packages/jest-reporters/src/BaseReporter.ts index 8f526555b12d..07923a739242 100644 --- a/packages/jest-reporters/src/BaseReporter.ts +++ b/packages/jest-reporters/src/BaseReporter.ts @@ -31,6 +31,7 @@ export default class BaseReporter implements Reporter { preRunMessageRemove(process.stderr); } + /* eslint-disable @typescript-eslint/no-empty-function */ onTestCaseResult(_test: Test, _testCaseResult: TestCaseResult): void {} onTestResult( @@ -45,6 +46,7 @@ export default class BaseReporter implements Reporter { _testContexts?: Set, _aggregatedResults?: AggregatedResult, ): Promise | void {} + /* eslint-enable */ protected _setError(error: Error): void { this._error = error; diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index f6e0d40848cc..9bdb6e719216 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -339,7 +339,7 @@ async function runTestInternal( } if (globalConfig.logHeapUsage) { - // @ts-expect-error + // @ts-expect-error - doesn't exist on globalThis globalThis.gc?.(); result.memoryUsage = process.memoryUsage().heapUsed; diff --git a/packages/jest-runtime/src/__tests__/runtime_require_mock.test.js b/packages/jest-runtime/src/__tests__/runtime_require_mock.test.js index 71b07e4ebeb7..b2df33131af6 100644 --- a/packages/jest-runtime/src/__tests__/runtime_require_mock.test.js +++ b/packages/jest-runtime/src/__tests__/runtime_require_mock.test.js @@ -93,7 +93,7 @@ describe('Runtime', () => { error = e; } finally { expect(error.message).toMatch( - /NativeModule.node\: file too short|not a valid Win\d+ application/, + /NativeModule.node: file too short|not a valid Win\d+ application/, ); } }); diff --git a/packages/jest-runtime/src/index.ts b/packages/jest-runtime/src/index.ts index 1dc2c9a56322..5cceb9bef2b6 100644 --- a/packages/jest-runtime/src/index.ts +++ b/packages/jest-runtime/src/index.ts @@ -751,7 +751,7 @@ export default class Runtime { [...cjsExports, 'default'], function () { cjsExports.forEach(exportName => { - // @ts-expect-error + // @ts-expect-error: TS doesn't know what `this` is this.setExport(exportName, cjs[exportName]); }); // @ts-expect-error: TS doesn't know what `this` is @@ -1514,8 +1514,8 @@ export default class Runtime { module.require, // require implementation module.path, // __dirname module.filename, // __filename - // @ts-expect-error - ...lastArgs.filter(notEmpty), + lastArgs[0], + ...lastArgs.slice(1).filter(notEmpty), ); } catch (error: any) { this.handleExecutionError(error, module); @@ -1680,10 +1680,9 @@ export default class Runtime { : fileURLToPath(modulePath); if (!path.isAbsolute(filename)) { - const error = new TypeError( + const error: NodeJS.ErrnoException = new TypeError( `The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '${filename}'`, ); - // @ts-expect-error error.code = 'ERR_INVALID_ARG_TYPE'; throw error; } @@ -1702,7 +1701,7 @@ export default class Runtime { class Module extends nativeModule.Module {} Object.entries(nativeModule.Module).forEach(([key, value]) => { - // @ts-expect-error + // @ts-expect-error: no index signature Module[key] = value; }); @@ -1716,14 +1715,13 @@ export default class Runtime { filename: string | URL, ) { if (typeof filename !== 'string') { - const error = new TypeError( + const error: NodeJS.ErrnoException = new TypeError( `The argument 'filename' must be string. Received '${filename}'.${ filename instanceof URL ? ' Use createRequire for URL filename.' : '' }`, ); - // @ts-expect-error error.code = 'ERR_INVALID_ARG_TYPE'; throw error; } @@ -1733,6 +1731,7 @@ export default class Runtime { if ('syncBuiltinESMExports' in nativeModule) { // cast since TS seems very confused about whether it exists or not (Module as any).syncBuiltinESMExports = + // eslint-disable-next-line @typescript-eslint/no-empty-function function syncBuiltinESMExports() {}; } diff --git a/packages/jest-snapshot/src/InlineSnapshots.ts b/packages/jest-snapshot/src/InlineSnapshots.ts index 4f1310528f47..2324ae7372fc 100644 --- a/packages/jest-snapshot/src/InlineSnapshots.ts +++ b/packages/jest-snapshot/src/InlineSnapshots.ts @@ -269,11 +269,12 @@ const runPrettier = ( // Detect the parser for the test file. // For older versions of Prettier, fallback to a simple parser detection. - // @ts-expect-error - const inferredParser: PrettierParserName | undefined = prettier.getFileInfo - ? prettier.getFileInfo.sync(sourceFilePath).inferredParser - : (config && typeof config.parser === 'string' && config.parser) || - simpleDetectParser(sourceFilePath); + // @ts-expect-error - `inferredParser` is `string` + const inferredParser: PrettierParserName | null | undefined = + prettier.getFileInfo + ? prettier.getFileInfo.sync(sourceFilePath).inferredParser + : (config && typeof config.parser === 'string' && config.parser) || + simpleDetectParser(sourceFilePath); if (!inferredParser) { throw new Error( diff --git a/packages/jest-snapshot/src/State.ts b/packages/jest-snapshot/src/State.ts index fc96a3b47add..ef3aa5d72cfa 100644 --- a/packages/jest-snapshot/src/State.ts +++ b/packages/jest-snapshot/src/State.ts @@ -54,7 +54,7 @@ type SaveStatus = { export default class SnapshotState { private _counters: Map; private _dirty: boolean; - // @ts-expect-error + // @ts-expect-error - seemingly unused? private _index: number; private _updateSnapshot: Config.SnapshotUpdateState; private _snapshotData: SnapshotData; diff --git a/packages/jest-snapshot/src/dedentLines.ts b/packages/jest-snapshot/src/dedentLines.ts index 3d637a2200d1..02a38ac2631d 100644 --- a/packages/jest-snapshot/src/dedentLines.ts +++ b/packages/jest-snapshot/src/dedentLines.ts @@ -31,7 +31,7 @@ const hasUnmatchedDoubleQuoteMarks = (string: string): boolean => { return n % 2 !== 0; }; -const isFirstLineOfTag = (line: string) => /^( {2})*\ /^( {2})*( resolverPath, + // eslint-disable-next-line @typescript-eslint/no-empty-function () => {}, { applyInteropRequireDefault, diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index d21bcf62782f..bc0716c14306 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -86,6 +86,7 @@ interface Each { timeout?: number, ) => void; + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint ( strings: TemplateStringsArray, ...expressions: Array diff --git a/packages/jest-validate/src/condition.ts b/packages/jest-validate/src/condition.ts index 8302f865f10d..6352e7fe2254 100644 --- a/packages/jest-validate/src/condition.ts +++ b/packages/jest-validate/src/condition.ts @@ -24,7 +24,7 @@ function validationConditionSingle( export function getValues(validOption: T): Array { if ( Array.isArray(validOption) && - // @ts-expect-error + // @ts-expect-error: no index signature validOption[MULTIPLE_VALID_OPTIONS_SYMBOL] ) { return validOption; @@ -43,7 +43,7 @@ export function multipleValidOptions>( ...args: T ): T[number] { const options = [...args]; - // @ts-expect-error + // @ts-expect-error: no index signature options[MULTIPLE_VALID_OPTIONS_SYMBOL] = true; return options; diff --git a/packages/jest-validate/src/exampleConfig.ts b/packages/jest-validate/src/exampleConfig.ts index 5275a48bc5df..143150da1e2b 100644 --- a/packages/jest-validate/src/exampleConfig.ts +++ b/packages/jest-validate/src/exampleConfig.ts @@ -14,6 +14,7 @@ const config: ValidationOptions = { deprecatedConfig: { key: (): string => 'Deprecation message', }, + // eslint-disable-next-line @typescript-eslint/no-empty-function error: () => {}, exampleConfig: {key: 'value', test: 'case'}, recursive: true, @@ -23,6 +24,7 @@ const config: ValidationOptions = { error: 'Validation Error', warning: 'Validation Warning', }, + // eslint-disable-next-line @typescript-eslint/no-empty-function unknown: () => {}, }; diff --git a/packages/jest-validate/src/utils.ts b/packages/jest-validate/src/utils.ts index d6890f7914cd..a28fe979e41a 100644 --- a/packages/jest-validate/src/utils.ts +++ b/packages/jest-validate/src/utils.ts @@ -33,6 +33,7 @@ export class ValidationError extends Error { comment = comment ? `\n\n${comment}` : '\n'; this.name = ''; this.message = chalk.red(`${chalk.bold(name)}:\n\n${message}${comment}`); + // eslint-disable-next-line @typescript-eslint/no-empty-function Error.captureStackTrace(this, () => {}); } } diff --git a/packages/jest-watcher/src/BaseWatchPlugin.ts b/packages/jest-watcher/src/BaseWatchPlugin.ts index 99d3c9e331ac..d386cc2726ff 100644 --- a/packages/jest-watcher/src/BaseWatchPlugin.ts +++ b/packages/jest-watcher/src/BaseWatchPlugin.ts @@ -28,12 +28,14 @@ abstract class BaseWatchPlugin implements WatchPlugin { this._stdout = stdout; } + // eslint-disable-next-line @typescript-eslint/no-empty-function apply(_hooks: JestHookSubscriber): void {} getUsageInfo(_globalConfig: Config.GlobalConfig): UsageData | null { return null; } + // eslint-disable-next-line @typescript-eslint/no-empty-function onKey(_key: string): void {} run( diff --git a/packages/jest-watcher/src/lib/Prompt.ts b/packages/jest-watcher/src/lib/Prompt.ts index 114bd4821a91..af857770910f 100644 --- a/packages/jest-watcher/src/lib/Prompt.ts +++ b/packages/jest-watcher/src/lib/Prompt.ts @@ -26,9 +26,11 @@ export default class Prompt { this._offset = -1; this._promptLength = 0; + /* eslint-disable @typescript-eslint/no-empty-function */ this._onChange = () => {}; this._onSuccess = () => {}; this._onCancel = () => {}; + /* eslint-enable */ } private _onResize = (): void => { diff --git a/packages/jest-worker/__benchmarks__/test.js b/packages/jest-worker/__benchmarks__/test.js index 3d72d37844e0..f76494f13af1 100644 --- a/packages/jest-worker/__benchmarks__/test.js +++ b/packages/jest-worker/__benchmarks__/test.js @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable no-async-promise-executor */ + /** * To start the test, build the repo and run: * node --expose-gc test.js empty 100000 diff --git a/packages/jest-worker/src/base/BaseWorkerPool.ts b/packages/jest-worker/src/base/BaseWorkerPool.ts index c5c447353c8f..da6e57d1b707 100644 --- a/packages/jest-worker/src/base/BaseWorkerPool.ts +++ b/packages/jest-worker/src/base/BaseWorkerPool.ts @@ -19,6 +19,7 @@ import { const FORCE_EXIT_DELAY = 500; /* istanbul ignore next */ +// eslint-disable-next-line @typescript-eslint/no-empty-function const emptyMethod = () => {}; export default class BaseWorkerPool { diff --git a/packages/jest-worker/src/types.ts b/packages/jest-worker/src/types.ts index 455d6c8b6233..7bf383a4d7cc 100644 --- a/packages/jest-worker/src/types.ts +++ b/packages/jest-worker/src/types.ts @@ -33,14 +33,14 @@ export type WorkerModule = { // coming from any of the other processes cannot be typed. Thus, many types // include "unknown" as a TS type, which is (unfortunately) correct here. -export const CHILD_MESSAGE_INITIALIZE: 0 = 0; -export const CHILD_MESSAGE_CALL: 1 = 1; -export const CHILD_MESSAGE_END: 2 = 2; - -export const PARENT_MESSAGE_OK: 0 = 0; -export const PARENT_MESSAGE_CLIENT_ERROR: 1 = 1; -export const PARENT_MESSAGE_SETUP_ERROR: 2 = 2; -export const PARENT_MESSAGE_CUSTOM: 3 = 3; +export const CHILD_MESSAGE_INITIALIZE = 0; +export const CHILD_MESSAGE_CALL = 1; +export const CHILD_MESSAGE_END = 2; + +export const PARENT_MESSAGE_OK = 0; +export const PARENT_MESSAGE_CLIENT_ERROR = 1; +export const PARENT_MESSAGE_SETUP_ERROR = 2; +export const PARENT_MESSAGE_CUSTOM = 3; export type PARENT_MESSAGE_ERROR = | typeof PARENT_MESSAGE_CLIENT_ERROR diff --git a/packages/jest-worker/src/workers/ChildProcessWorker.ts b/packages/jest-worker/src/workers/ChildProcessWorker.ts index c3a2f2ab4d78..39d2109fa168 100644 --- a/packages/jest-worker/src/workers/ChildProcessWorker.ts +++ b/packages/jest-worker/src/workers/ChildProcessWorker.ts @@ -242,6 +242,7 @@ export default class ChildProcessWorker implements WorkerInterface { this._request = request; this._retries = 0; + // eslint-disable-next-line @typescript-eslint/no-empty-function this._child.send(request, () => {}); } diff --git a/packages/pretty-format/src/__tests__/setPrettyPrint.ts b/packages/pretty-format/src/__tests__/setPrettyPrint.ts index b6bc35e1ffc5..5317d89f9cce 100644 --- a/packages/pretty-format/src/__tests__/setPrettyPrint.ts +++ b/packages/pretty-format/src/__tests__/setPrettyPrint.ts @@ -9,6 +9,7 @@ import prettyFormat from '../'; import type {OptionsReceived, Plugins} from '../types'; declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace namespace jest { interface Matchers { toPrettyPrintTo(expected: unknown, options?: OptionsReceived): R; diff --git a/scripts/checkCopyrightHeaders.mjs b/scripts/checkCopyrightHeaders.mjs index 19d9549a5093..3d4f73b72244 100755 --- a/scripts/checkCopyrightHeaders.mjs +++ b/scripts/checkCopyrightHeaders.mjs @@ -72,7 +72,7 @@ const GENERIC_IGNORED_EXTENSIONS = [ 'htm', 'toml', 'pro', -].map(extension => createRegExp(`\.${extension}$`)); +].map(extension => createRegExp(`\\.${extension}$`)); const GENERIC_IGNORED_PATTERNS = [ '(^|/)\\.[^/]+(/|$)', diff --git a/scripts/watch.mjs b/scripts/watch.mjs index a4734d14ea3d..bfb6a3e2c722 100644 --- a/scripts/watch.mjs +++ b/scripts/watch.mjs @@ -37,7 +37,7 @@ chokidar getPackages().map(p => path.resolve(p.packageDir, 'src')), { ignoreInitial: true, - ignored: /(^|[\/\\])\../, // ignore dotfiles + ignored: /(^|[/\\])\../, // ignore dotfiles }, ) .on('all', (event, filePath) => {