Skip to content

Commit

Permalink
chore: use ban-types eslint rule (#8041)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Mar 4, 2019
1 parent 5ba35be commit 4a5d5d7
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 31 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -21,6 +21,7 @@ module.exports = {
plugins: ['@typescript-eslint/eslint-plugin'],
rules: {
'@typescript-eslint/array-type': ['error', 'generic'],
'@typescript-eslint/ban-types': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{argsIgnorePattern: '^_'},
Expand Down
10 changes: 5 additions & 5 deletions packages/expect/src/asymmetricMatchers.ts
Expand Up @@ -12,7 +12,7 @@ import {emptyObject} from './utils';

export class AsymmetricMatcher<T> {
protected sample: T;
$$typeof: Symbol;
$$typeof: symbol;
inverse?: boolean;

constructor(sample: T) {
Expand Down Expand Up @@ -139,8 +139,8 @@ class ArrayContaining extends AsymmetricMatcher<Array<unknown>> {
}
}

class ObjectContaining extends AsymmetricMatcher<Object> {
constructor(sample: Object, inverse: boolean = false) {
class ObjectContaining extends AsymmetricMatcher<Record<string, any>> {
constructor(sample: Record<string, any>, inverse: boolean = false) {
super(sample);
this.inverse = inverse;
}
Expand Down Expand Up @@ -245,9 +245,9 @@ export const arrayContaining = (sample: Array<unknown>) =>
new ArrayContaining(sample);
export const arrayNotContaining = (sample: Array<unknown>) =>
new ArrayContaining(sample, true);
export const objectContaining = (sample: Object) =>
export const objectContaining = (sample: Record<string, any>) =>
new ObjectContaining(sample);
export const objectNotContaining = (sample: Object) =>
export const objectNotContaining = (sample: Record<string, any>) =>
new ObjectContaining(sample, true);
export const stringContaining = (expected: string) =>
new StringContaining(expected);
Expand Down
4 changes: 2 additions & 2 deletions packages/expect/src/types.ts
Expand Up @@ -52,7 +52,7 @@ export type MatcherState = {
};
};

export type AsymmetricMatcher = Object;
export type AsymmetricMatcher = Record<string, any>;
export type MatchersObject = {[id: string]: RawMatcherFn};
export type Expect = {
(expected: any): ExpectationObject;
Expand All @@ -71,7 +71,7 @@ export type Expect = {
any(expectedObject: any): AsymmetricMatcher;
anything(): AsymmetricMatcher;
arrayContaining(sample: Array<any>): AsymmetricMatcher;
objectContaining(sample: Object): AsymmetricMatcher;
objectContaining(sample: Record<string, any>): AsymmetricMatcher;
stringContaining(expected: string): AsymmetricMatcher;
stringMatching(expected: string | RegExp): AsymmetricMatcher;
[id: string]: AsymmetricMatcher;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/types.ts
Expand Up @@ -23,7 +23,7 @@ export type HookFn = (done?: DoneFn) => Promise<any> | null | undefined;
export type AsyncFn = TestFn | HookFn;
export type SharedHookType = 'afterAll' | 'beforeAll';
export type HookType = SharedHookType | 'afterEach' | 'beforeEach';
export type TestContext = Object;
export type TestContext = Record<string, any>;
export type Exception = any; // Since in JS anything can be thrown as an error.
export type FormattedError = string; // String representation of error.
export type Hook = {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/ReporterValidationErrors.ts
Expand Up @@ -40,7 +40,7 @@ export function createArrayReporterError(
arrayReporter: Config.ReporterConfig,
reporterIndex: number,
valueIndex: number,
value: string | Object,
value: string | Record<string, any>,
expectedType: string,
valueName: string,
) {
Expand Down
6 changes: 5 additions & 1 deletion packages/jest-diff/src/index.ts
Expand Up @@ -112,7 +112,11 @@ function sortSet(set: Set<unknown>) {
return new Set(Array.from(set.values()).sort());
}

function compareObjects(a: Object, b: Object, options?: JestDiffOptions) {
function compareObjects(
a: Record<string, any>,
b: Record<string, any>,
options?: JestDiffOptions,
) {
let diffMessage;
let hasThrown = false;

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-environment/src/index.ts
Expand Up @@ -49,7 +49,7 @@ export interface Jest {
*
* @deprecated Use `expect.extend` instead
*/
addMatchers(matchers: Object): void;
addMatchers(matchers: Record<string, any>): void;
/**
* Disables automatic mocking in the module loader.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/index.ts
Expand Up @@ -1108,7 +1108,7 @@ class DuplicateError extends Error {
}
}

function copy<T extends Object>(object: T): T {
function copy<T extends Record<string, any>>(object: T): T {
return Object.assign(Object.create(null), object);
}

Expand Down
14 changes: 10 additions & 4 deletions packages/jest-mock/src/index.ts
Expand Up @@ -385,7 +385,7 @@ class ModuleMockerClass {
this._invocationCallCounter = 1;
}

private _getSlots(object?: Object): Array<string> {
private _getSlots(object?: Record<string, any>): Array<string> {
if (!object) {
return [];
}
Expand Down Expand Up @@ -480,7 +480,7 @@ class ModuleMockerClass {
private _makeComponent<T, Y extends Array<unknown>>(
metadata: JestMock.MockFunctionMetadata<T, Y, 'object'>,
restore?: () => void,
): Object;
): Record<string, any>;
private _makeComponent<T, Y extends Array<unknown>>(
metadata: JestMock.MockFunctionMetadata<T, Y, 'array'>,
restore?: () => void,
Expand All @@ -504,7 +504,13 @@ class ModuleMockerClass {
private _makeComponent<T, Y extends Array<unknown>>(
metadata: JestMock.MockFunctionMetadata<T, Y>,
restore?: () => void,
): Object | Array<unknown> | RegExp | T | undefined | Mock<T, Y> {
):
| Record<string, any>
| Array<unknown>
| RegExp
| T
| undefined
| Mock<T, Y> {
if (metadata.type === 'object') {
return new this._environmentGlobal.Object();
} else if (metadata.type === 'array') {
Expand Down Expand Up @@ -812,7 +818,7 @@ class ModuleMockerClass {
callbacks: Array<Function>,
refs: {
[key: string]:
| Object
| Record<string, any>
| Array<unknown>
| RegExp
| T
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -988,7 +988,7 @@ class Runtime {
};

const jestObject: Jest = {
addMatchers: (matchers: Object) =>
addMatchers: (matchers: Record<string, any>) =>
this._environment.global.jasmine.addMatchers(matchers),
advanceTimersByTime: (msToRun: number) =>
_getFakeTimers().advanceTimersByTime(msToRun),
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-source-map/src/__tests__/getCallsite.test.ts
Expand Up @@ -41,7 +41,7 @@ describe('getCallsite', () => {
const sourceMapLine = 2;
// @ts-ignore
SourceMap.SourceMapConsumer = class {
originalPositionFor(params: Object) {
originalPositionFor(params: Record<string, any>) {
expect(params).toMatchObject({
column: expect.any(Number),
line: expect.any(Number),
Expand Down
12 changes: 6 additions & 6 deletions packages/jest-types/src/Config.ts
Expand Up @@ -21,7 +21,7 @@ export type HasteConfig = {

export type ReporterConfig = [string, {[key: string]: unknown}];

export type ConfigGlobals = Object;
export type ConfigGlobals = Record<string, any>;

export type DefaultOptions = {
automock: boolean;
Expand Down Expand Up @@ -80,7 +80,7 @@ export type DefaultOptions = {
skipFilter: boolean;
snapshotSerializers: Array<Path>;
testEnvironment: string;
testEnvironmentOptions: Object;
testEnvironmentOptions: Record<string, any>;
testFailureExitCode: string | number;
testLocationInResults: boolean;
testMatch: Array<Glob>;
Expand Down Expand Up @@ -186,7 +186,7 @@ export type InitialOptions = {
snapshotSerializers?: Array<Path>;
errorOnDeprecated?: boolean;
testEnvironment?: string;
testEnvironmentOptions?: Object;
testEnvironmentOptions?: Record<string, any>;
testFailureExitCode?: string | number;
testLocationInResults?: boolean;
testMatch?: Array<Glob>;
Expand All @@ -210,7 +210,7 @@ export type InitialOptions = {
watch?: boolean;
watchAll?: boolean;
watchman?: boolean;
watchPlugins?: Array<string | [string, Object]>;
watchPlugins?: Array<string | [string, Record<string, any>]>;
};

export type SnapshotUpdateState = 'all' | 'new' | 'none';
Expand Down Expand Up @@ -301,7 +301,7 @@ export type GlobalConfig = {
watchPlugins:
| Array<{
path: string;
config: Object;
config: Record<string, any>;
}>
| null
| undefined;
Expand Down Expand Up @@ -349,7 +349,7 @@ export type ProjectConfig = {
snapshotResolver: Path | null | undefined;
snapshotSerializers: Array<Path>;
testEnvironment: string;
testEnvironmentOptions: Object;
testEnvironmentOptions: Record<string, any>;
testMatch: Array<Glob>;
testLocationInResults: boolean;
testPathIgnorePatterns: Array<string>;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-types/src/TestResult.ts
Expand Up @@ -164,7 +164,7 @@ export type CodeCoverageReporter = any;
export type CodeCoverageFormatter = (
coverage: CoverageMapData | null | undefined,
reporter: CodeCoverageReporter,
) => Object | null | undefined;
) => Record<string, any> | null | undefined;

export type UncheckedSnapshot = {
filePath: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/createProcessObject.ts
Expand Up @@ -19,7 +19,7 @@ function createProcessEnv(): NodeJS.ProcessEnv {
return deepCyclicCopy(process.env);
}

const proto: Object = Object.getPrototypeOf(process.env);
const proto: Record<string, any> = Object.getPrototypeOf(process.env);
const real = Object.create(proto);
const lookup: typeof process.env = {};

Expand Down
2 changes: 1 addition & 1 deletion packages/jest-worker/src/index.ts
Expand Up @@ -18,7 +18,7 @@ function getExposedMethods(

// If no methods list is given, try getting it by auto-requiring the module.
if (!exposedMethods) {
const module: Function | Object = require(workerPath);
const module: Function | Record<string, any> = require(workerPath);

exposedMethods = Object.keys(module).filter(
// @ts-ignore: no index
Expand Down
4 changes: 2 additions & 2 deletions packages/pretty-format/src/collections.ts
Expand Up @@ -8,7 +8,7 @@

import {Config, Printer, Refs} from './types';

const getKeysOfEnumerableProperties = (object: Object) => {
const getKeysOfEnumerableProperties = (object: Record<string, any>) => {
const keys: Array<string | symbol> = Object.keys(object).sort();

if (Object.getOwnPropertySymbols) {
Expand Down Expand Up @@ -168,7 +168,7 @@ export function printListItems(
* without surrounding punctuation (for example, braces)
*/
export function printObjectProperties(
val: Object,
val: Record<string, any>,
config: Config,
indentation: string,
depth: number,
Expand Down
4 changes: 2 additions & 2 deletions packages/pretty-format/src/plugins/ReactTestComponent.ts
Expand Up @@ -8,9 +8,9 @@
import {Config, Printer, NewPlugin, Refs} from '../types';

export type ReactTestObject = {
$$typeof: Symbol;
$$typeof: symbol;
type: string;
props?: Object;
props?: Record<string, any>;
children?: null | Array<ReactTestChild>;
};

Expand Down

0 comments on commit 4a5d5d7

Please sign in to comment.