Skip to content

Commit 24e0472

Browse files
authored
chore(lint): enable recommended configs (#12902)
1 parent 1bf9f36 commit 24e0472

File tree

60 files changed

+145
-67
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+145
-67
lines changed

.eslintrc.cjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
/* eslint-disable sort-keys */
9+
810
const fs = require('fs');
911
const path = require('path');
1012
const {sync: readPkg} = require('read-pkg');
@@ -27,6 +29,7 @@ module.exports = {
2729
'jest/globals': true,
2830
},
2931
extends: [
32+
'eslint:recommended',
3033
'plugin:markdown/recommended',
3134
'plugin:import/errors',
3235
'plugin:eslint-comments/recommended',
@@ -38,6 +41,7 @@ module.exports = {
3841
overrides: [
3942
{
4043
extends: [
44+
'plugin:@typescript-eslint/recommended',
4145
'plugin:@typescript-eslint/eslint-recommended',
4246
'plugin:import/typescript',
4347
],
@@ -52,10 +56,14 @@ module.exports = {
5256
{argsIgnorePattern: '^_'},
5357
],
5458
'@typescript-eslint/prefer-ts-expect-error': 'error',
59+
'@typescript-eslint/no-var-requires': 'off',
5560
// TS verifies these
5661
'consistent-return': 'off',
5762
'no-dupe-class-members': 'off',
5863
'no-unused-vars': 'off',
64+
// TODO: enable at some point
65+
'@typescript-eslint/no-explicit-any': 'off',
66+
'@typescript-eslint/no-non-null-assertion': 'off',
5967
},
6068
},
6169
{
@@ -144,6 +152,9 @@ module.exports = {
144152
files: ['**/*.md/**'],
145153
rules: {
146154
'@typescript-eslint/no-unused-vars': 'off',
155+
'@typescript-eslint/no-empty-function': 'off',
156+
'@typescript-eslint/no-namespace': 'off',
157+
'@typescript-eslint/no-empty-interface': 'off',
147158
'arrow-body-style': 'off',
148159
'consistent-return': 'off',
149160
'import/export': 'off',
@@ -201,6 +212,13 @@ module.exports = {
201212
],
202213
},
203214
},
215+
{
216+
files: ['**/__tests__/**', '**/__mocks__/**'],
217+
rules: {
218+
'@typescript-eslint/ban-ts-comment': 'off',
219+
'@typescript-eslint/no-empty-function': 'off',
220+
},
221+
},
204222
{
205223
files: [
206224
'**/__tests__/**',
@@ -247,6 +265,12 @@ module.exports = {
247265
'import/no-extraneous-dependencies': 'off',
248266
},
249267
},
268+
{
269+
files: ['**/__typetests__/**'],
270+
rules: {
271+
'@typescript-eslint/no-empty-function': 'off',
272+
},
273+
},
250274
{
251275
files: [
252276
'**/__typetests__/**',

e2e/__tests__/multiProjectRunner.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('can pass projects or global config', () => {
4949
getHasteName(filename) {
5050
return filename
5151
.substr(filename.lastIndexOf(path.sep) + 1)
52-
.replace(/\.js$/, '');
52+
.replace(/\\.js$/, '');
5353
},
5454
};
5555
`,
@@ -446,7 +446,7 @@ test('Does transform files with the corresponding project transformer', () => {
446446
'project1/jest.config.js': `
447447
module.exports = {
448448
rootDir: './',
449-
transform: {'file\.js': './transformer.js'},
449+
transform: {'file\\.js': './transformer.js'},
450450
};`,
451451
'project1/transformer.js': `
452452
module.exports = {
@@ -461,7 +461,7 @@ test('Does transform files with the corresponding project transformer', () => {
461461
'project2/jest.config.js': `
462462
module.exports = {
463463
rootDir: './',
464-
transform: {'file\.js': './transformer.js'},
464+
transform: {'file\\.js': './transformer.js'},
465465
};`,
466466
'project2/transformer.js': `
467467
module.exports = {

e2e/__tests__/runProgrammatically.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const dir = resolve(__dirname, '..', 'run-programmatically');
1212

1313
test('run Jest programmatically cjs', () => {
1414
const {stdout} = run('node cjs.js --version', dir);
15-
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
15+
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[-\S]*-dev$/);
1616
});
1717

1818
test('run Jest programmatically esm', () => {
1919
const {stdout} = run('node index.js --version', dir);
20-
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
20+
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[-\S]*-dev$/);
2121
});

e2e/__tests__/version.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test('works with jest.config.js', () => {
2222
});
2323

2424
const {exitCode, stdout, stderr} = runJest(DIR, ['--version']);
25-
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[\-\S]*-dev$/);
25+
expect(stdout).toMatch(/\d{2}\.\d{1,2}\.\d{1,2}[-\S]*-dev$/);
2626
// Only version gets printed and nothing else
2727
expect(stdout.split(/\n/)).toHaveLength(1);
2828
expect(stderr).toBe('');

e2e/coverage-provider-v8/empty-sourcemap/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
89
export interface obj {}

e2e/snapshot-escape/__tests__/snapshotEscapeRegex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
'use strict';
88

9-
const regex = /\dd\ \s+ \w \\\[ \. blahzz.* [xyz]+/;
9+
const regex = /\dd \s+ \w \\\[ \. blahzz.* [xyz]+/;
1010

1111
test('escape regex', () => expect(regex).toMatchSnapshot());
1212

packages/babel-plugin-jest-hoist/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ export default function jestHoist(): PluginObj<{
305305
},
306306
// in `post` to make sure we come after an import transform and can unshift above the `require`s
307307
post({path: program}) {
308+
// eslint-disable-next-line @typescript-eslint/no-this-alias
308309
const self = this;
309310

310311
visitBlock(program);

packages/expect/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export class JestAssertionError extends Error {
6464
matcherResult?: Omit<SyncExpectationResult, 'message'> & {message: string};
6565
}
6666

67+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
6768
const isPromise = <T extends any>(obj: any): obj is PromiseLike<T> =>
6869
!!obj &&
6970
(typeof obj === 'object' || typeof obj === 'function') &&

packages/jest-circus/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ const test: Global.It = (() => {
155155
test.todo,
156156
);
157157
}
158+
// eslint-disable-next-line @typescript-eslint/no-empty-function
158159
return _addTest(testName, 'todo', false, () => {}, test.todo);
159160
};
160161

packages/jest-circus/src/legacy-code-todo-rewrite/jestAdapterInit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const initialize = async ({
6363
}
6464
getRunnerState().maxConcurrency = globalConfig.maxConcurrency;
6565

66-
// @ts-expect-error
66+
// @ts-expect-error: missing `concurrent` which is added later
6767
const globalsObject: Global.TestFrameworkGlobals = {
6868
...globals,
6969
fdescribe: globals.describe.only,

packages/jest-circus/src/run.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const _runTestsForDescribeBlock = async (
5252
const promise = mutex(test.fn);
5353
// Avoid triggering the uncaught promise rejection handler in case the
5454
// test errors before being awaited on.
55+
// eslint-disable-next-line @typescript-eslint/no-empty-function
5556
promise.catch(() => {});
5657
test.fn = () => promise;
5758
} catch (err) {

packages/jest-circus/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const TEST_TIMEOUT_SYMBOL = Symbol.for('TEST_TIMEOUT_SYMBOL');
1414
export const LOG_ERRORS_BEFORE_RETRY = Symbol.for('LOG_ERRORS_BEFORE_RETRY');
1515

1616
declare global {
17+
// eslint-disable-next-line @typescript-eslint/no-namespace
1718
namespace NodeJS {
1819
interface Global {
1920
[STATE_SYM]: Circus.State;

packages/jest-cli/src/init/errors.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class NotFoundPackageJsonError extends Error {
99
constructor(rootDir: string) {
1010
super(`Could not find a "package.json" file in ${rootDir}`);
1111
this.name = '';
12+
// eslint-disable-next-line @typescript-eslint/no-empty-function
1213
Error.captureStackTrace(this, () => {});
1314
}
1415
}
@@ -20,6 +21,7 @@ export class MalformedPackageJsonError extends Error {
2021
'Fix it, and then run "jest --init"',
2122
);
2223
this.name = '';
24+
// eslint-disable-next-line @typescript-eslint/no-empty-function
2325
Error.captureStackTrace(this, () => {});
2426
}
2527
}

packages/jest-config/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const resolve = (
5252
};
5353

5454
export const escapeGlobCharacters = (path: string): string =>
55-
path.replace(/([()*{}\[\]!?\\])/g, '\\$1');
55+
path.replace(/([()*{}[\]!?\\])/g, '\\$1');
5656

5757
export const replaceRootDirInPath = (
5858
rootDir: string,

packages/jest-console/src/NullConsole.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-empty-function */
12
/**
23
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
34
*

packages/jest-core/src/cli/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export async function runCLI(
105105
// If in watch mode, return the promise that will never resolve.
106106
// If the watch mode is interrupted, watch should handle the process
107107
// shutdown.
108+
// eslint-disable-next-line @typescript-eslint/no-empty-function
108109
return new Promise(() => {});
109110
}
110111

packages/jest-environment-jsdom/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
142142
});
143143
}
144144

145+
// eslint-disable-next-line @typescript-eslint/no-empty-function
145146
async setup(): Promise<void> {}
146147

147148
async teardown(): Promise<void> {
@@ -165,7 +166,7 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
165166
Object.defineProperty(this.global, 'document', {value: null});
166167
}
167168
this.errorEventListener = null;
168-
// @ts-expect-error
169+
// @ts-expect-error: this.global not allowed to be `null`
169170
this.global = null;
170171
this.dom = null;
171172
this.fakeTimers = null;

packages/jest-environment-node/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
7777
configurable: descriptor.configurable,
7878
enumerable: descriptor.enumerable,
7979
get() {
80-
// @ts-expect-error
80+
// @ts-expect-error: no index signature
8181
const val = globalThis[nodeGlobalsKey];
8282

8383
// override lazy getter
@@ -157,6 +157,7 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
157157
});
158158
}
159159

160+
// eslint-disable-next-line @typescript-eslint/no-empty-function
160161
async setup(): Promise<void> {}
161162

162163
async teardown(): Promise<void> {

packages/jest-fake-timers/src/modernFakeTimers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class FakeTimers {
8080

8181
runAllTicks(): void {
8282
if (this._checkFakeTimers()) {
83-
// @ts-expect-error
83+
// @ts-expect-error - doesn't exist?
8484
this._clock.runMicrotasks();
8585
}
8686
}

packages/jest-haste-map/src/watchers/FSEventsWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import micromatch = require('micromatch');
1414
// @ts-expect-error no types
1515
import walker from 'walker';
1616

17-
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
17+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment
1818
// @ts-ignore: this is for CI which runs linux and might not have this
1919
let fsevents: typeof import('fsevents') | null = null;
2020
try {

packages/jest-jasmine2/src/PCancelable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default class PCancelable<T> implements PromiseLike<T> {
1717
private _canceled = false;
1818
private _promise: Promise<T>;
1919
private _cancel?: () => void;
20+
// eslint-disable-next-line @typescript-eslint/no-empty-function
2021
private _reject: (reason?: unknown) => void = () => {};
2122

2223
constructor(

packages/jest-jasmine2/src/errorOnPrivate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function installErrorOnPrivate(global: Global.Global): void {
5252
(
5353
Object.keys(disabledJasmineMethods) as Array<DisabledJasmineMethodsKeys>
5454
).forEach(methodName => {
55-
// @ts-expect-error
55+
// @ts-expect-error - void unallowd, but it throws 🤷
5656
jasmine[methodName] = () => {
5757
throwAtFunction(disabledJasmineMethods[methodName], jasmine[methodName]);
5858
};

packages/jest-jasmine2/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default async function jasmine2(
6464
if (stack.getFileName()?.startsWith(jestEachBuildDir)) {
6565
stack = getCallsite(4, sourcemaps);
6666
}
67-
// @ts-expect-error
67+
// @ts-expect-error: `it` is `void` for some reason
6868
it.result.__callsite = stack;
6969

7070
return it;

packages/jest-jasmine2/src/jasmine/Env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ export default function jasmineEnv(j$: Jasmine) {
599599

600600
const spec = specFactory(
601601
description,
602+
// eslint-disable-next-line @typescript-eslint/no-empty-function
602603
() => {},
603604
currentDeclarationSuite,
604605
);

packages/jest-jasmine2/src/jasmine/JsApiReporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2828
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2929
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3030
*/
31-
/* eslint-disable sort-keys */
31+
/* eslint-disable sort-keys, @typescript-eslint/no-empty-function */
3232
import type {Reporter, RunDetails} from '../types';
3333
import type {SpecResult} from './Spec';
3434
import type {SuiteResult} from './Suite';

packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ export default class ReportDispatcher implements Reporter {
4040
provideFallbackReporter: (reporter: Reporter) => void;
4141
clearReporters: () => void;
4242

43-
// @ts-expect-error
43+
// @ts-expect-error: confused by loop in ctor
4444
jasmineDone: (runDetails: RunDetails) => void;
45-
// @ts-expect-error
45+
// @ts-expect-error: confused by loop in ctor
4646
jasmineStarted: (runDetails: RunDetails) => void;
47-
// @ts-expect-error
47+
// @ts-expect-error: confused by loop in ctor
4848
specDone: (result: SpecResult) => void;
49-
// @ts-expect-error
49+
// @ts-expect-error: confused by loop in ctor
5050
specStarted: (spec: SpecResult) => void;
51-
// @ts-expect-error
51+
// @ts-expect-error: confused by loop in ctor
5252
suiteDone: (result: SuiteResult) => void;
53-
// @ts-expect-error
53+
// @ts-expect-error: confused by loop in ctor
5454
suiteStarted: (result: SuiteResult) => void;
5555

5656
constructor(methods: Array<keyof Reporter>) {
@@ -89,7 +89,7 @@ export default class ReportDispatcher implements Reporter {
8989
for (let i = 0; i < reporters.length; i++) {
9090
const reporter = reporters[i];
9191
if (reporter[method]) {
92-
// @ts-expect-error
92+
// @ts-expect-error: wrong context
9393
reporter[method].apply(reporter, args);
9494
}
9595
}

packages/jest-jasmine2/src/jasmine/Spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
2828
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2929
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3030
*/
31-
/* eslint-disable sort-keys, local/prefer-spread-eventually, local/prefer-rest-params-eventually */
31+
/* eslint-disable sort-keys, local/prefer-spread-eventually, local/prefer-rest-params-eventually, @typescript-eslint/no-empty-function */
3232

3333
import {AssertionError} from 'assert';
3434
import type {FailedAssertion, Milliseconds, Status} from '@jest/test-result';
@@ -138,11 +138,12 @@ export default class Spec {
138138
// in the stack in the Error object. This line stringifies the stack
139139
// property to allow garbage-collecting objects on the stack
140140
// https://crbug.com/v8/7142
141+
// eslint-disable-next-line no-self-assign
141142
this.initError.stack = this.initError.stack;
142143

143144
this.queueableFn.initError = this.initError;
144145

145-
// @ts-expect-error
146+
// @ts-expect-error: misses some fields added later
146147
this.result = {
147148
id: this.id,
148149
description: this.description,
@@ -172,6 +173,7 @@ export default class Spec {
172173
}
173174

174175
execute(onComplete?: () => void, enabled?: boolean) {
176+
// eslint-disable-next-line @typescript-eslint/no-this-alias
175177
const self = this;
176178

177179
this.onStart(this);
@@ -192,7 +194,7 @@ export default class Spec {
192194
this.currentRun = this.queueRunnerFactory({
193195
queueableFns: allFns,
194196
onException() {
195-
// @ts-expect-error
197+
// @ts-expect-error: wrong context
196198
self.onException.apply(self, arguments);
197199
},
198200
userContext: this.userContext(),

0 commit comments

Comments
 (0)