diff --git a/.eslintplugin/index.js b/.eslintplugin/index.js new file mode 100644 index 000000000000..750870e8ab1c --- /dev/null +++ b/.eslintplugin/index.js @@ -0,0 +1,12 @@ +/** + * Copyright (c) 2016-present, Facebook, Inc. All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +exports.rules = { + 'ban-types-eventually': require('@typescript-eslint/eslint-plugin').rules[ + 'ban-types' + ], +}; diff --git a/.eslintrc.js b/.eslintrc.js index 52aeaf62c47c..6947aab62c61 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,14 +19,10 @@ module.exports = { extends: ['plugin:@typescript-eslint/eslint-recommended'], files: ['*.ts', '*.tsx'], parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint/eslint-plugin'], + plugins: ['@typescript-eslint/eslint-plugin', 'local'], rules: { '@typescript-eslint/array-type': ['error', {default: 'generic'}], - '@typescript-eslint/ban-types': [ - 'error', - // TODO: remove these overrides: https://github.com/facebook/jest/issues/10177 - {types: {Function: false, object: false, '{}': false}}, - ], + '@typescript-eslint/ban-types': 'error', '@typescript-eslint/no-unused-vars': [ 'error', {argsIgnorePattern: '^_'}, @@ -42,6 +38,66 @@ module.exports = { 'prefer-spread': 'off', }, }, + { + files: [ + 'e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts', + 'e2e/coverage-remapping/covered.ts', + 'packages/expect/src/jestMatchersObject.ts', + 'packages/expect/src/matchers.ts', + 'packages/expect/src/print.ts', + 'packages/expect/src/toThrowMatchers.ts', + 'packages/expect/src/types.ts', + 'packages/expect/src/utils.ts', + 'packages/jest-core/src/ReporterDispatcher.ts', + 'packages/jest-core/src/TestScheduler.ts', + 'packages/jest-core/src/collectHandles.ts', + 'packages/jest-core/src/plugins/update_snapshots_interactive.ts', + 'packages/jest-environment/src/index.ts', + 'packages/jest-fake-timers/src/legacyFakeTimers.ts', + 'packages/jest-haste-map/src/index.ts', + 'packages/jest-haste-map/src/lib/FSEventsWatcher.ts', + 'packages/jest-jasmine2/src/errorOnPrivate.ts', + 'packages/jest-jasmine2/src/jasmine/SpyStrategy.ts', + 'packages/jest-jasmine2/src/jasmine/Suite.ts', + 'packages/jest-leak-detector/src/index.ts', + 'packages/jest-matcher-utils/src/index.ts', + 'packages/jest-mock/src/__tests__/index.test.ts', + 'packages/jest-mock/src/index.ts', + 'packages/jest-resolve/src/isBuiltinModule.ts', + 'packages/jest-snapshot/src/index.ts', + 'packages/jest-snapshot/src/printSnapshot.ts', + 'packages/jest-snapshot/src/types.ts', + 'packages/jest-types/src/Global.ts', + 'packages/jest-util/src/ErrorWithStack.ts', + 'packages/jest-util/src/convertDescriptorToString.ts', + 'packages/jest-validate/src/types.ts', + 'packages/jest-worker/src/Farm.ts', + 'packages/jest-worker/src/index.ts', + 'packages/pretty-format/src/index.ts', + 'packages/pretty-format/src/plugins/DOMCollection.ts', + ], + rules: { + '@typescript-eslint/ban-types': [ + 'error', + // TODO: remove these overrides: https://github.com/facebook/jest/issues/10177 + {types: {Function: false, object: false, '{}': false}}, + ], + 'local/ban-types-eventually': [ + 'warn', + { + types: { + // none of these types are in use, so can be errored on + Boolean: false, + Number: false, + Object: false, + String: false, + Symbol: false, + }, + }, + ], + }, + }, + // to make it more suitable for running on code examples in docs/ folder { files: ['*.md'], diff --git a/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts b/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts index 4b8129acca0d..793eee7875fb 100644 --- a/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts +++ b/e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts @@ -6,6 +6,8 @@ * */ +/* eslint-disable local/ban-types-eventually */ + import type {Color} from '../types'; import {color} from '../entry'; diff --git a/e2e/coverage-remapping/covered.ts b/e2e/coverage-remapping/covered.ts index 36ba129fd3b2..c98fb1b4d9eb 100644 --- a/e2e/coverage-remapping/covered.ts +++ b/e2e/coverage-remapping/covered.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable local/ban-types-eventually, @typescript-eslint/no-unused-vars */ export = function difference(a: number, b: number): number { const branch1: boolean = true ? 1 : 0; diff --git a/package.json b/package.json index 1df7fd4db5e5..75763904f3e4 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "eslint-plugin-import": "^2.6.0", "eslint-plugin-jest": "^24.0.0", "eslint-plugin-jsx-a11y": "^6.0.2", + "eslint-plugin-local": "^1.0.0", "eslint-plugin-markdown": "^1.0.0", "eslint-plugin-prettier": "^3.0.1", "eslint-plugin-react": "^7.1.0", diff --git a/packages/expect/src/matchers.ts b/packages/expect/src/matchers.ts index de234b24b0b3..2a5e3959d612 100644 --- a/packages/expect/src/matchers.ts +++ b/packages/expect/src/matchers.ts @@ -6,6 +6,8 @@ * */ +/* eslint-disable local/ban-types-eventually */ + import getType = require('jest-get-type'); import { DIM_COLOR, diff --git a/packages/expect/src/print.ts b/packages/expect/src/print.ts index fbdd51350548..a9f84e5243f1 100644 --- a/packages/expect/src/print.ts +++ b/packages/expect/src/print.ts @@ -6,6 +6,8 @@ * */ +/* eslint-disable local/ban-types-eventually */ + import { EXPECTED_COLOR, INVERTED_COLOR, diff --git a/packages/expect/src/toThrowMatchers.ts b/packages/expect/src/toThrowMatchers.ts index b16780fb6de0..f21e760911c8 100644 --- a/packages/expect/src/toThrowMatchers.ts +++ b/packages/expect/src/toThrowMatchers.ts @@ -6,6 +6,8 @@ * */ +/* eslint-disable local/ban-types-eventually */ + import {formatStackTrace, separateMessageFromStack} from 'jest-message-util'; import { EXPECTED_COLOR, diff --git a/packages/expect/src/types.ts b/packages/expect/src/types.ts index e7555c2c09e4..04246ef95dd3 100644 --- a/packages/expect/src/types.ts +++ b/packages/expect/src/types.ts @@ -5,6 +5,9 @@ * LICENSE file in the root directory of this source tree. * */ + +/* eslint-disable local/ban-types-eventually */ + import type {Config} from '@jest/types'; import type * as jestMatcherUtils from 'jest-matcher-utils'; import {INTERNAL_MATCHER_FLAG} from './jestMatchersObject'; diff --git a/packages/expect/src/utils.ts b/packages/expect/src/utils.ts index f5ff252bce7e..1d568de8d117 100644 --- a/packages/expect/src/utils.ts +++ b/packages/expect/src/utils.ts @@ -6,6 +6,8 @@ * */ +/* eslint-disable local/ban-types-eventually */ + import {isPrimitive} from 'jest-get-type'; import { equals, @@ -100,7 +102,7 @@ export const getObjectSubset = ( subset: any, seenReferences: WeakMap = new WeakMap(), ): any => { - /* eslint-enable */ + /* eslint-enable @typescript-eslint/explicit-module-boundary-types */ if (Array.isArray(object)) { if (Array.isArray(subset) && subset.length === object.length) { // The map method returns correct subclass of subset. @@ -143,7 +145,7 @@ const hasIterator = (object: any) => export const iterableEquality = ( a: any, b: any, - /* eslint-enable */ + /* eslint-enable @typescript-eslint/explicit-module-boundary-types */ aStack: Array = [], bStack: Array = [], ): boolean | undefined => { diff --git a/packages/jest-core/src/ReporterDispatcher.ts b/packages/jest-core/src/ReporterDispatcher.ts index 32a358e49d5f..9f152607c5bb 100644 --- a/packages/jest-core/src/ReporterDispatcher.ts +++ b/packages/jest-core/src/ReporterDispatcher.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import type { AggregatedResult, TestCaseResult, diff --git a/packages/jest-core/src/TestScheduler.ts b/packages/jest-core/src/TestScheduler.ts index a1eac111ddce..3daa3731bb8c 100644 --- a/packages/jest-core/src/TestScheduler.ts +++ b/packages/jest-core/src/TestScheduler.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import chalk = require('chalk'); import {formatExecError} from 'jest-message-util'; import type {Config} from '@jest/types'; diff --git a/packages/jest-core/src/collectHandles.ts b/packages/jest-core/src/collectHandles.ts index 4db21d8fc2a1..f09eb7cd52ee 100644 --- a/packages/jest-core/src/collectHandles.ts +++ b/packages/jest-core/src/collectHandles.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import * as asyncHooks from 'async_hooks'; import type {Config} from '@jest/types'; import {formatExecError} from 'jest-message-util'; diff --git a/packages/jest-core/src/plugins/update_snapshots_interactive.ts b/packages/jest-core/src/plugins/update_snapshots_interactive.ts index 7a73d62b27c9..defb56b49a35 100644 --- a/packages/jest-core/src/plugins/update_snapshots_interactive.ts +++ b/packages/jest-core/src/plugins/update_snapshots_interactive.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import type {Config} from '@jest/types'; import type {AggregatedResult, AssertionLocation} from '@jest/test-result'; import {BaseWatchPlugin, JestHookSubscriber, UsageData} from 'jest-watcher'; diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index 482a460ef879..d24df7924c85 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import type {Context, Script} from 'vm'; import type {Circus, Config, Global} from '@jest/types'; import jestMock = require('jest-mock'); diff --git a/packages/jest-fake-timers/src/legacyFakeTimers.ts b/packages/jest-fake-timers/src/legacyFakeTimers.ts index 9bc714e90d65..1f865bcb0cf7 100644 --- a/packages/jest-fake-timers/src/legacyFakeTimers.ts +++ b/packages/jest-fake-timers/src/legacyFakeTimers.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import util = require('util'); import type {ModuleMocker} from 'jest-mock'; import {StackTraceConfig, formatStackTrace} from 'jest-message-util'; diff --git a/packages/jest-haste-map/src/index.ts b/packages/jest-haste-map/src/index.ts index 8d36ae87663f..7720ad6bdacf 100644 --- a/packages/jest-haste-map/src/index.ts +++ b/packages/jest-haste-map/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import {execSync} from 'child_process'; import {createHash} from 'crypto'; import {EventEmitter} from 'events'; diff --git a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts index 6d382459f36f..c0625f4cb172 100644 --- a/packages/jest-haste-map/src/lib/FSEventsWatcher.ts +++ b/packages/jest-haste-map/src/lib/FSEventsWatcher.ts @@ -6,6 +6,8 @@ * */ +/* eslint-disable local/ban-types-eventually */ + import * as path from 'path'; import {EventEmitter} from 'events'; import * as fs from 'graceful-fs'; diff --git a/packages/jest-jasmine2/src/errorOnPrivate.ts b/packages/jest-jasmine2/src/errorOnPrivate.ts index 0df3568af49a..6d72925f50d6 100644 --- a/packages/jest-jasmine2/src/errorOnPrivate.ts +++ b/packages/jest-jasmine2/src/errorOnPrivate.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import type {Global} from '@jest/types'; import {ErrorWithStack} from 'jest-util'; import type {Jasmine} from './types'; diff --git a/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts b/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts index 9d56d282d9ab..ad780a52db96 100644 --- a/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts +++ b/packages/jest-jasmine2/src/jasmine/SpyStrategy.ts @@ -29,6 +29,8 @@ 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 */ + export default class SpyStrategy { identity: () => string; exec: (...args: Array) => unknown; diff --git a/packages/jest-jasmine2/src/jasmine/Suite.ts b/packages/jest-jasmine2/src/jasmine/Suite.ts index d07d6aa7627e..de5b727e83b9 100644 --- a/packages/jest-jasmine2/src/jasmine/Suite.ts +++ b/packages/jest-jasmine2/src/jasmine/Suite.ts @@ -28,7 +28,8 @@ 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 local/ban-types-eventually, sort-keys */ import {convertDescriptorToString} from 'jest-util'; import type {Config} from '@jest/types'; diff --git a/packages/jest-leak-detector/src/index.ts b/packages/jest-leak-detector/src/index.ts index 6cb7dd23923c..e7bd026edc21 100644 --- a/packages/jest-leak-detector/src/index.ts +++ b/packages/jest-leak-detector/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import {setFlagsFromString} from 'v8'; import {runInNewContext} from 'vm'; import {promisify} from 'util'; diff --git a/packages/jest-matcher-utils/src/index.ts b/packages/jest-matcher-utils/src/index.ts index 46858795ea9d..1f2c80514c56 100644 --- a/packages/jest-matcher-utils/src/index.ts +++ b/packages/jest-matcher-utils/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import chalk = require('chalk'); import diffDefault, { DIFF_DELETE, diff --git a/packages/jest-mock/src/__tests__/index.test.ts b/packages/jest-mock/src/__tests__/index.test.ts index 16f5a5e1f425..7e058232bb66 100644 --- a/packages/jest-mock/src/__tests__/index.test.ts +++ b/packages/jest-mock/src/__tests__/index.test.ts @@ -6,6 +6,8 @@ * */ +/* eslint-disable local/ban-types-eventually */ + import vm, {Context} from 'vm'; import {ModuleMocker} from '../'; diff --git a/packages/jest-mock/src/index.ts b/packages/jest-mock/src/index.ts index dff0535f5b19..fac7bcf21104 100644 --- a/packages/jest-mock/src/index.ts +++ b/packages/jest-mock/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + type Global = NodeJS.Global; // | Window – add once TS improves typings; namespace JestMock { diff --git a/packages/jest-resolve/src/isBuiltinModule.ts b/packages/jest-resolve/src/isBuiltinModule.ts index 83363fb33f4a..56a89c9f593a 100644 --- a/packages/jest-resolve/src/isBuiltinModule.ts +++ b/packages/jest-resolve/src/isBuiltinModule.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import module = require('module'); // "private" api diff --git a/packages/jest-snapshot/src/index.ts b/packages/jest-snapshot/src/index.ts index d5d46c9c34e1..adb03117d871 100644 --- a/packages/jest-snapshot/src/index.ts +++ b/packages/jest-snapshot/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import * as fs from 'graceful-fs'; import type {Config} from '@jest/types'; import type {FS as HasteFS} from 'jest-haste-map'; diff --git a/packages/jest-snapshot/src/printSnapshot.ts b/packages/jest-snapshot/src/printSnapshot.ts index e5c3131f7e55..3a17abce95d6 100644 --- a/packages/jest-snapshot/src/printSnapshot.ts +++ b/packages/jest-snapshot/src/printSnapshot.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import chalk = require('chalk'); // Temporary hack because getObjectSubset has known limitations, // is not in the public interface of the expect package, diff --git a/packages/jest-snapshot/src/types.ts b/packages/jest-snapshot/src/types.ts index e5ee10395c5e..8dbd91c9c31a 100644 --- a/packages/jest-snapshot/src/types.ts +++ b/packages/jest-snapshot/src/types.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import type {MatcherState} from 'expect'; import type SnapshotState from './State'; diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 3e0354ec3403..6bcfb708b652 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import type {CoverageMapData} from 'istanbul-lib-coverage'; export type DoneFn = (reason?: string | Error) => void; diff --git a/packages/jest-util/src/ErrorWithStack.ts b/packages/jest-util/src/ErrorWithStack.ts index 871f44498c22..20508980d17f 100644 --- a/packages/jest-util/src/ErrorWithStack.ts +++ b/packages/jest-util/src/ErrorWithStack.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + export default class ErrorWithStack extends Error { constructor(message: string | undefined, callsite: Function) { super(message); diff --git a/packages/jest-util/src/convertDescriptorToString.ts b/packages/jest-util/src/convertDescriptorToString.ts index c10ea8bf7f83..fbd34948ef1d 100644 --- a/packages/jest-util/src/convertDescriptorToString.ts +++ b/packages/jest-util/src/convertDescriptorToString.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + // See: https://github.com/facebook/jest/pull/5154 export default function convertDescriptorToString< T extends number | string | Function | undefined diff --git a/packages/jest-worker/src/Farm.ts b/packages/jest-worker/src/Farm.ts index 151f2783f5a5..2c3950c7a30f 100644 --- a/packages/jest-worker/src/Farm.ts +++ b/packages/jest-worker/src/Farm.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import { CHILD_MESSAGE_CALL, ChildMessage, diff --git a/packages/jest-worker/src/index.ts b/packages/jest-worker/src/index.ts index f9f9b3bccd8a..6ae1b96b0d17 100644 --- a/packages/jest-worker/src/index.ts +++ b/packages/jest-worker/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import {cpus} from 'os'; import WorkerPool from './WorkerPool'; import Farm from './Farm'; diff --git a/packages/pretty-format/src/index.ts b/packages/pretty-format/src/index.ts index 994edc5e85b7..0c305ae23cf4 100644 --- a/packages/pretty-format/src/index.ts +++ b/packages/pretty-format/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import style = require('ansi-styles'); import type * as PrettyFormat from './types'; diff --git a/packages/pretty-format/src/plugins/DOMCollection.ts b/packages/pretty-format/src/plugins/DOMCollection.ts index f58ee48023ee..e19188afbef8 100644 --- a/packages/pretty-format/src/plugins/DOMCollection.ts +++ b/packages/pretty-format/src/plugins/DOMCollection.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +/* eslint-disable local/ban-types-eventually */ + import type {Config, NewPlugin, Printer, Refs} from '../types'; import {printListItems, printObjectProperties} from '../collections'; diff --git a/yarn.lock b/yarn.lock index a2d5faac7325..01dac351ef57 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7965,6 +7965,13 @@ __metadata: languageName: node linkType: hard +"eslint-plugin-local@npm:^1.0.0": + version: 1.0.0 + resolution: "eslint-plugin-local@npm:1.0.0" + checksum: 369263373b645b3024b974c799454cb05c283cd735abab86c25d65fe54027b3d1a8533bd895d3e8ff281ea370669e6e3d6ac700a8fe751933889868cc57de447 + languageName: node + linkType: hard + "eslint-plugin-markdown@npm:^1.0.0": version: 1.0.2 resolution: "eslint-plugin-markdown@npm:1.0.2" @@ -17053,6 +17060,7 @@ fsevents@^1.2.7: eslint-plugin-import: ^2.6.0 eslint-plugin-jest: ^24.0.0 eslint-plugin-jsx-a11y: ^6.0.2 + eslint-plugin-local: ^1.0.0 eslint-plugin-markdown: ^1.0.0 eslint-plugin-prettier: ^3.0.1 eslint-plugin-react: ^7.1.0