Skip to content

Commit

Permalink
chore: duplicate @typescript-eslint/ban-types locally to allow warn…
Browse files Browse the repository at this point in the history
…ing (#10438)
  • Loading branch information
G-Rath committed Sep 13, 2020
1 parent 0646c73 commit 1969fe0
Show file tree
Hide file tree
Showing 37 changed files with 151 additions and 10 deletions.
12 changes: 12 additions & 0 deletions .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'
],
};
68 changes: 62 additions & 6 deletions .eslintrc.js
Expand Up @@ -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: '^_'},
Expand All @@ -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'],
Expand Down
2 changes: 2 additions & 0 deletions e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts
Expand Up @@ -6,6 +6,8 @@
*
*/

/* eslint-disable local/ban-types-eventually */

import type {Color} from '../types';
import {color} from '../entry';

Expand Down
2 changes: 1 addition & 1 deletion e2e/coverage-remapping/covered.ts
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/expect/src/matchers.ts
Expand Up @@ -6,6 +6,8 @@
*
*/

/* eslint-disable local/ban-types-eventually */

import getType = require('jest-get-type');
import {
DIM_COLOR,
Expand Down
2 changes: 2 additions & 0 deletions packages/expect/src/print.ts
Expand Up @@ -6,6 +6,8 @@
*
*/

/* eslint-disable local/ban-types-eventually */

import {
EXPECTED_COLOR,
INVERTED_COLOR,
Expand Down
2 changes: 2 additions & 0 deletions packages/expect/src/toThrowMatchers.ts
Expand Up @@ -6,6 +6,8 @@
*
*/

/* eslint-disable local/ban-types-eventually */

import {formatStackTrace, separateMessageFromStack} from 'jest-message-util';
import {
EXPECTED_COLOR,
Expand Down
3 changes: 3 additions & 0 deletions packages/expect/src/types.ts
Expand Up @@ -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';
Expand Down
6 changes: 4 additions & 2 deletions packages/expect/src/utils.ts
Expand Up @@ -6,6 +6,8 @@
*
*/

/* eslint-disable local/ban-types-eventually */

import {isPrimitive} from 'jest-get-type';
import {
equals,
Expand Down Expand Up @@ -100,7 +102,7 @@ export const getObjectSubset = (
subset: any,
seenReferences: WeakMap<object, boolean> = 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.
Expand Down Expand Up @@ -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<any> = [],
bStack: Array<any> = [],
): boolean | undefined => {
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-core/src/ReporterDispatcher.ts
Expand Up @@ -5,6 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

/* eslint-disable local/ban-types-eventually */

import type {
AggregatedResult,
TestCaseResult,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-core/src/TestScheduler.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-core/src/collectHandles.ts
Expand Up @@ -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';
Expand Down
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-environment/src/index.ts
Expand Up @@ -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');
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-fake-timers/src/legacyFakeTimers.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-haste-map/src/index.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-haste-map/src/lib/FSEventsWatcher.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-jasmine2/src/errorOnPrivate.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-jasmine2/src/jasmine/SpyStrategy.ts
Expand Up @@ -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<any>) => unknown;
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-jasmine2/src/jasmine/Suite.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-leak-detector/src/index.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-matcher-utils/src/index.ts
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-mock/src/__tests__/index.test.ts
Expand Up @@ -6,6 +6,8 @@
*
*/

/* eslint-disable local/ban-types-eventually */

import vm, {Context} from 'vm';
import {ModuleMocker} from '../';

Expand Down
2 changes: 2 additions & 0 deletions packages/jest-mock/src/index.ts
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-resolve/src/isBuiltinModule.ts
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-snapshot/src/index.ts
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-snapshot/src/printSnapshot.ts
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-snapshot/src/types.ts
Expand Up @@ -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';

Expand Down
2 changes: 2 additions & 0 deletions packages/jest-types/src/Global.ts
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-util/src/ErrorWithStack.ts
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-util/src/convertDescriptorToString.ts
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-worker/src/Farm.ts
Expand Up @@ -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,
Expand Down

0 comments on commit 1969fe0

Please sign in to comment.