Skip to content

Commit

Permalink
chore: update ts-eslint (#9953)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed May 2, 2020
1 parent 3078172 commit 42f920c
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 59 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -18,8 +18,8 @@
"@types/jest": "24.0.2",
"@types/node": "*",
"@types/which": "^1.3.2",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"ansi-regex": "^5.0.0",
"ansi-styles": "^4.2.0",
"babel-eslint": "^10.0.3",
Expand Down
10 changes: 8 additions & 2 deletions packages/expect/src/extractExpectedAssertionsErrors.ts
Expand Up @@ -23,10 +23,16 @@ const resetAssertionsLocalState = () => {
});
};

type AssertionsErrors = Array<{
actual: string;
error: string;
expected: string | number;
}>;

// Create and format all errors related to the mismatched number of `expect`
// calls and reset the matcher's state.
const extractExpectedAssertionsErrors = () => {
const result = [];
const extractExpectedAssertionsErrors: () => AssertionsErrors = () => {
const result: AssertionsErrors = [];
const {
assertionCalls,
expectedAssertionsNumber,
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-circus/src/formatNodeAssertErrors.ts
Expand Up @@ -38,7 +38,10 @@ const humanReadableOperators: Record<string, string> = {
strictEqual: 'to strictly be equal',
};

const formatNodeAssertErrors = (event: Circus.Event, state: Circus.State) => {
const formatNodeAssertErrors = (
event: Circus.Event,
state: Circus.State,
): void => {
if (event.name === 'test_done') {
event.test.errors = event.test.errors.map((errors: Circus.TestError) => {
let error;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/lib/active_filters_message.ts
Expand Up @@ -11,7 +11,7 @@ import type {Config} from '@jest/types';
const activeFilters = (
globalConfig: Config.GlobalConfig,
delimiter: string = '\n',
) => {
): string => {
const {testNamePattern, testPathPattern} = globalConfig;
if (testNamePattern || testPathPattern) {
const filters = [
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-core/src/plugins/quit.ts
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import {BaseWatchPlugin} from 'jest-watcher';
import {BaseWatchPlugin, UsageData} from 'jest-watcher';

class QuitPlugin extends BaseWatchPlugin {
isInternal: true;
Expand All @@ -15,15 +15,15 @@ class QuitPlugin extends BaseWatchPlugin {
this.isInternal = true;
}

async run() {
async run(): Promise<void> {
if (typeof this._stdin.setRawMode === 'function') {
this._stdin.setRawMode(false);
}
this._stdout.write('\n');
process.exit(0);
}

getUsageInfo() {
getUsageInfo(): UsageData {
return {
key: 'q',
prompt: 'quit watch mode',
Expand Down
11 changes: 8 additions & 3 deletions packages/jest-core/src/plugins/test_name_pattern.ts
Expand Up @@ -6,7 +6,12 @@
*/

import type {Config} from '@jest/types';
import {BaseWatchPlugin, Prompt, UpdateConfigCallback} from 'jest-watcher';
import {
BaseWatchPlugin,
Prompt,
UpdateConfigCallback,
UsageData,
} from 'jest-watcher';
import TestNamePatternPrompt from '../TestNamePatternPrompt';
import activeFilters from '../lib/active_filters_message';

Expand All @@ -20,14 +25,14 @@ class TestNamePatternPlugin extends BaseWatchPlugin {
this.isInternal = true;
}

getUsageInfo() {
getUsageInfo(): UsageData {
return {
key: 't',
prompt: 'filter by a test name regex pattern',
};
}

onKey(key: string) {
onKey(key: string): void {
this._prompt.put(key);
}

Expand Down
11 changes: 8 additions & 3 deletions packages/jest-core/src/plugins/test_path_pattern.ts
Expand Up @@ -6,7 +6,12 @@
*/

import type {Config} from '@jest/types';
import {BaseWatchPlugin, Prompt, UpdateConfigCallback} from 'jest-watcher';
import {
BaseWatchPlugin,
Prompt,
UpdateConfigCallback,
UsageData,
} from 'jest-watcher';
import TestPathPatternPrompt from '../TestPathPatternPrompt';
import activeFilters from '../lib/active_filters_message';

Expand All @@ -20,14 +25,14 @@ class TestPathPatternPlugin extends BaseWatchPlugin {
this.isInternal = true;
}

getUsageInfo() {
getUsageInfo(): UsageData {
return {
key: 'p',
prompt: 'filter by a filename regex pattern',
};
}

onKey(key: string) {
onKey(key: string): void {
this._prompt.put(key);
}

Expand Down
5 changes: 3 additions & 2 deletions packages/jest-core/src/plugins/update_snapshots.ts
Expand Up @@ -10,6 +10,7 @@ import {
BaseWatchPlugin,
JestHookSubscriber,
UpdateConfigCallback,
UsageData,
} from 'jest-watcher';

class UpdateSnapshotsPlugin extends BaseWatchPlugin {
Expand All @@ -30,13 +31,13 @@ class UpdateSnapshotsPlugin extends BaseWatchPlugin {
return Promise.resolve(false);
}

apply(hooks: JestHookSubscriber) {
apply(hooks: JestHookSubscriber): void {
hooks.onTestRunComplete(results => {
this._hasSnapshotFailure = results.snapshot.failure;
});
}

getUsageInfo() {
getUsageInfo(): UsageData | null {
if (this._hasSnapshotFailure) {
return {
key: 'u',
Expand Down
13 changes: 5 additions & 8 deletions packages/jest-core/src/plugins/update_snapshots_interactive.ts
Expand Up @@ -7,7 +7,7 @@

import type {Config} from '@jest/types';
import type {AggregatedResult, AssertionLocation} from '@jest/test-result';
import {BaseWatchPlugin, JestHookSubscriber} from 'jest-watcher';
import {BaseWatchPlugin, JestHookSubscriber, UsageData} from 'jest-watcher';
import SnapshotInteractiveMode from '../SnapshotInteractiveMode';

class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
Expand Down Expand Up @@ -41,7 +41,7 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
return failedTestPaths;
}

apply(hooks: JestHookSubscriber) {
apply(hooks: JestHookSubscriber): void {
hooks.onTestRunComplete(results => {
this._failedSnapshotTestAssertions = this.getFailedSnapshotTestAssertions(
results,
Expand All @@ -52,7 +52,7 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
});
}

onKey(key: string) {
onKey(key: string): void {
if (this._snapshotInteractiveMode.isActive()) {
this._snapshotInteractiveMode.put(key);
}
Expand Down Expand Up @@ -85,11 +85,8 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin {
}
}

getUsageInfo() {
if (
this._failedSnapshotTestAssertions &&
this._failedSnapshotTestAssertions.length > 0
) {
getUsageInfo(): UsageData | null {
if (this._failedSnapshotTestAssertions?.length > 0) {
return {
key: 'i',
prompt: 'update failing snapshots interactively',
Expand Down
1 change: 1 addition & 0 deletions packages/jest-diff/src/index.ts
Expand Up @@ -50,6 +50,7 @@ const FALLBACK_FORMAT_OPTIONS_0 = {...FALLBACK_FORMAT_OPTIONS, indent: 0};

// Generate a string that will highlight the difference between two values
// with green and red. (similar to how github does code diffing)
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
function diff(a: any, b: any, options?: DiffOptions): string | null {
if (Object.is(a, b)) {
return NO_DIFF_MESSAGE;
Expand Down
6 changes: 4 additions & 2 deletions packages/jest-each/src/index.ts
Expand Up @@ -49,8 +49,10 @@ const install = (
return {describe, fdescribe, fit, it, test, xdescribe, xit, xtest};
};

const each = (table: Global.EachTable, ...data: Global.TemplateData) =>
install(global as Global, table, ...data);
const each = (
table: Global.EachTable,
...data: Global.TemplateData
): ReturnType<typeof install> => install(global as Global, table, ...data);

each.withGlobal = (g: Global) => (
table: Global.EachTable,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-environment-jsdom/src/index.ts
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import type {Script} from 'vm';
import type {Context, Script} from 'vm';
import type {Config, Global} from '@jest/types';
import {installCommonGlobals} from 'jest-util';
import {ModuleMocker} from 'jest-mock';
Expand Down Expand Up @@ -135,7 +135,7 @@ class JSDOMEnvironment implements JestEnvironment {
return null;
}

getVmContext() {
getVmContext(): Context | null {
if (this.dom) {
return this.dom.getInternalVMContext();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/getMockName.ts
Expand Up @@ -9,7 +9,7 @@ import * as path from 'path';

const MOCKS_PATTERN = path.sep + '__mocks__' + path.sep;

const getMockName = (filePath: string) => {
const getMockName = (filePath: string): string => {
const mockPath = filePath.split(MOCKS_PATTERN)[1];
return mockPath
.substring(0, mockPath.lastIndexOf(path.extname(mockPath)))
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-haste-map/src/lib/normalizePathSep.ts
Expand Up @@ -9,9 +9,10 @@ import * as path from 'path';

let normalizePathSep: (string: string) => string;
if (path.sep === '/') {
normalizePathSep = (filePath: string) => filePath;
normalizePathSep = (filePath: string): string => filePath;
} else {
normalizePathSep = (filePath: string) => filePath.replace(/\//g, path.sep);
normalizePathSep = (filePath: string): string =>
filePath.replace(/\//g, path.sep);
}

export default normalizePathSep;
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/assertionErrorMessage.ts
Expand Up @@ -95,7 +95,7 @@ const assertMatcherHint = (
function assertionErrorMessage(
error: AssertionErrorWithStack,
options: DiffOptions,
) {
): string {
const {expected, actual, generatedMessage, message, operator, stack} = error;
const diffString = diff(expected, actual, options);
const hasCustomMessage = !generatedMessage;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-types/src/Circus.ts
Expand Up @@ -208,7 +208,7 @@ export type DescribeBlock = {
tests: Array<TestEntry>;
};

export type TestError = Exception | Array<[Exception | undefined, Exception]>; // the error from the test, as well as a backup error for async
export type TestError = Exception | [Exception | undefined, Exception]; // the error from the test, as well as a backup error for async

export type TestEntry = {
asyncError: Exception; // Used if the test failure contains no usable stack trace
Expand Down
5 changes: 4 additions & 1 deletion packages/jest-validate/src/validate.ts
Expand Up @@ -95,7 +95,10 @@ const allowsMultipleTypes = (key: string): boolean => key === 'maxWorkers';
const isOfTypeStringOrNumber = (value: any): boolean =>
typeof value === 'number' || typeof value === 'string';

const validate = (config: Record<string, any>, options: ValidationOptions) => {
const validate = (
config: Record<string, any>,
options: ValidationOptions,
): {hasDeprecationWarnings: boolean; isValid: boolean} => {
hasDeprecationWarnings = false;

// Preserve default blacklist entries even with user-supplied blacklist
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-watcher/src/BaseWatchPlugin.ts
Expand Up @@ -28,13 +28,13 @@ class BaseWatchPlugin implements WatchPlugin {
this._stdout = stdout;
}

apply(_hooks: JestHookSubscriber) {}
apply(_hooks: JestHookSubscriber): void {}

getUsageInfo(_globalConfig: Config.GlobalConfig): UsageData | null {
return null;
}

onKey(_key: string) {}
onKey(_key: string): void {}

run(
_globalConfig: Config.GlobalConfig,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-watcher/src/JestHooks.ts
Expand Up @@ -66,8 +66,8 @@ class JestHooks {
};
}

isUsed(hook: AvailableHooks) {
return this._listeners[hook] && this._listeners[hook].length;
isUsed(hook: AvailableHooks): boolean {
return this._listeners[hook]?.length > 0;
}

getSubscriber(): Readonly<JestHookSubscriber> {
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Expand Up @@ -2779,40 +2779,40 @@
dependencies:
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^2.19.0":
version "2.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.27.0.tgz#e479cdc4c9cf46f96b4c287755733311b0d0ba4b"
integrity sha512-/my+vVHRN7zYgcp0n4z5A6HAK7bvKGBiswaM5zIlOQczsxj/aiD7RcgD+dvVFuwFaGh5+kM7XA6Q6PN0bvb1tw==
"@typescript-eslint/eslint-plugin@^2.30.0":
version "2.30.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.30.0.tgz#312a37e80542a764d96e8ad88a105316cdcd7b05"
integrity sha512-PGejii0qIZ9Q40RB2jIHyUpRWs1GJuHP1pkoCiaeicfwO9z7Fx03NQzupuyzAmv+q9/gFNHu7lo1ByMXe8PNyg==
dependencies:
"@typescript-eslint/experimental-utils" "2.27.0"
"@typescript-eslint/experimental-utils" "2.30.0"
functional-red-black-tree "^1.0.1"
regexpp "^3.0.0"
tsutils "^3.17.1"

"@typescript-eslint/experimental-utils@2.27.0", "@typescript-eslint/experimental-utils@^2.5.0":
version "2.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.27.0.tgz#801a952c10b58e486c9a0b36cf21e2aab1e9e01a"
integrity sha512-vOsYzjwJlY6E0NJRXPTeCGqjv5OHgRU1kzxHKWJVPjDYGbPgLudBXjIlc+OD1hDBZ4l1DLbOc5VjofKahsu9Jw==
"@typescript-eslint/experimental-utils@2.30.0", "@typescript-eslint/experimental-utils@^2.5.0":
version "2.30.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-2.30.0.tgz#9845e868c01f3aed66472c561d4b6bac44809dd0"
integrity sha512-L3/tS9t+hAHksy8xuorhOzhdefN0ERPDWmR9CclsIGOUqGKy6tqc/P+SoXeJRye5gazkuPO0cK9MQRnolykzkA==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/typescript-estree" "2.27.0"
"@typescript-eslint/typescript-estree" "2.30.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"

"@typescript-eslint/parser@^2.19.0":
version "2.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.27.0.tgz#d91664335b2c46584294e42eb4ff35838c427287"
integrity sha512-HFUXZY+EdwrJXZo31DW4IS1ujQW3krzlRjBrFRrJcMDh0zCu107/nRfhk/uBasO8m0NVDbBF5WZKcIUMRO7vPg==
"@typescript-eslint/parser@^2.30.0":
version "2.30.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-2.30.0.tgz#7681c305a6f4341ae2579f5e3a75846c29eee9ce"
integrity sha512-9kDOxzp0K85UnpmPJqUzdWaCNorYYgk1yZmf4IKzpeTlSAclnFsrLjfwD9mQExctLoLoGAUXq1co+fbr+3HeFw==
dependencies:
"@types/eslint-visitor-keys" "^1.0.0"
"@typescript-eslint/experimental-utils" "2.27.0"
"@typescript-eslint/typescript-estree" "2.27.0"
"@typescript-eslint/experimental-utils" "2.30.0"
"@typescript-eslint/typescript-estree" "2.30.0"
eslint-visitor-keys "^1.1.0"

"@typescript-eslint/typescript-estree@2.27.0":
version "2.27.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.27.0.tgz#a288e54605412da8b81f1660b56c8b2e42966ce8"
integrity sha512-t2miCCJIb/FU8yArjAvxllxbTiyNqaXJag7UOpB5DVoM3+xnjeOngtqlJkLRnMtzaRcJhe3CIR9RmL40omubhg==
"@typescript-eslint/typescript-estree@2.30.0":
version "2.30.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-2.30.0.tgz#1b8e848b55144270255ffbfe4c63291f8f766615"
integrity sha512-nI5WOechrA0qAhnr+DzqwmqHsx7Ulr/+0H7bWCcClDhhWkSyZR5BmTvnBEyONwJCTWHfc5PAQExX24VD26IAVw==
dependencies:
debug "^4.1.1"
eslint-visitor-keys "^1.1.0"
Expand Down

0 comments on commit 42f920c

Please sign in to comment.