Skip to content

Commit

Permalink
chore(lint): enable recommended configs (#12902)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Jun 3, 2022
1 parent 1bf9f36 commit 24e0472
Show file tree
Hide file tree
Showing 60 changed files with 145 additions and 67 deletions.
24 changes: 24 additions & 0 deletions .eslintrc.cjs
Expand Up @@ -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');
Expand All @@ -27,6 +29,7 @@ module.exports = {
'jest/globals': true,
},
extends: [
'eslint:recommended',
'plugin:markdown/recommended',
'plugin:import/errors',
'plugin:eslint-comments/recommended',
Expand All @@ -38,6 +41,7 @@ module.exports = {
overrides: [
{
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:import/typescript',
],
Expand All @@ -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',
},
},
{
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -201,6 +212,13 @@ module.exports = {
],
},
},
{
files: ['**/__tests__/**', '**/__mocks__/**'],
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
},
},
{
files: [
'**/__tests__/**',
Expand Down Expand Up @@ -247,6 +265,12 @@ module.exports = {
'import/no-extraneous-dependencies': 'off',
},
},
{
files: ['**/__typetests__/**'],
rules: {
'@typescript-eslint/no-empty-function': 'off',
},
},
{
files: [
'**/__typetests__/**',
Expand Down
6 changes: 3 additions & 3 deletions e2e/__tests__/multiProjectRunner.test.ts
Expand Up @@ -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$/, '');
},
};
`,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/runProgrammatically.test.ts
Expand Up @@ -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$/);
});
2 changes: 1 addition & 1 deletion e2e/__tests__/version.test.ts
Expand Up @@ -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('');
Expand Down
1 change: 1 addition & 0 deletions e2e/coverage-provider-v8/empty-sourcemap/types.ts
Expand Up @@ -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 {}
2 changes: 1 addition & 1 deletion e2e/snapshot-escape/__tests__/snapshotEscapeRegex.js
Expand Up @@ -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());

Expand Down
1 change: 1 addition & 0 deletions packages/babel-plugin-jest-hoist/src/index.ts
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/expect/src/index.ts
Expand Up @@ -64,6 +64,7 @@ export class JestAssertionError extends Error {
matcherResult?: Omit<SyncExpectationResult, 'message'> & {message: string};
}

// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
const isPromise = <T extends any>(obj: any): obj is PromiseLike<T> =>
!!obj &&
(typeof obj === 'object' || typeof obj === 'function') &&
Expand Down
1 change: 1 addition & 0 deletions packages/jest-circus/src/index.ts
Expand Up @@ -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);
};

Expand Down
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/jest-circus/src/run.ts
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions packages/jest-circus/src/types.ts
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-cli/src/init/errors.ts
Expand Up @@ -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, () => {});
}
}
Expand All @@ -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, () => {});
}
}
2 changes: 1 addition & 1 deletion packages/jest-config/src/utils.ts
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions 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.
*
Expand Down
1 change: 1 addition & 0 deletions packages/jest-core/src/cli/index.ts
Expand Up @@ -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(() => {});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -142,6 +142,7 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
});
}

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

async teardown(): Promise<void> {
Expand All @@ -165,7 +166,7 @@ export default class JSDOMEnvironment implements JestEnvironment<number> {
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;
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-environment-node/src/index.ts
Expand Up @@ -77,7 +77,7 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
configurable: descriptor.configurable,
enumerable: descriptor.enumerable,
get() {
// @ts-expect-error
// @ts-expect-error: no index signature
const val = globalThis[nodeGlobalsKey];

// override lazy getter
Expand Down Expand Up @@ -157,6 +157,7 @@ export default class NodeEnvironment implements JestEnvironment<Timer> {
});
}

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

async teardown(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-fake-timers/src/modernFakeTimers.ts
Expand Up @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/watchers/FSEventsWatcher.ts
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/PCancelable.ts
Expand Up @@ -17,6 +17,7 @@ export default class PCancelable<T> implements PromiseLike<T> {
private _canceled = false;
private _promise: Promise<T>;
private _cancel?: () => void;
// eslint-disable-next-line @typescript-eslint/no-empty-function
private _reject: (reason?: unknown) => void = () => {};

constructor(
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/errorOnPrivate.ts
Expand Up @@ -52,7 +52,7 @@ export function installErrorOnPrivate(global: Global.Global): void {
(
Object.keys(disabledJasmineMethods) as Array<DisabledJasmineMethodsKeys>
).forEach(methodName => {
// @ts-expect-error
// @ts-expect-error - void unallowd, but it throws 🤷
jasmine[methodName] = () => {
throwAtFunction(disabledJasmineMethods[methodName], jasmine[methodName]);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/index.ts
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/src/jasmine/Env.ts
Expand Up @@ -599,6 +599,7 @@ export default function jasmineEnv(j$: Jasmine) {

const spec = specFactory(
description,
// eslint-disable-next-line @typescript-eslint/no-empty-function
() => {},
currentDeclarationSuite,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/jasmine/JsApiReporter.ts
Expand Up @@ -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';
Expand Down
14 changes: 7 additions & 7 deletions packages/jest-jasmine2/src/jasmine/ReportDispatcher.ts
Expand Up @@ -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<keyof Reporter>) {
Expand Down Expand Up @@ -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);
}
}
Expand Down
8 changes: 5 additions & 3 deletions packages/jest-jasmine2/src/jasmine/Spec.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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(),
Expand Down

0 comments on commit 24e0472

Please sign in to comment.