From 42f920c1d117718d5ea6f34a5fe0cf1560bb6acc Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sat, 2 May 2020 20:25:30 +0200 Subject: [PATCH] chore: update ts-eslint (#9953) --- package.json | 4 +- .../src/extractExpectedAssertionsErrors.ts | 10 ++++- .../jest-circus/src/formatNodeAssertErrors.ts | 5 ++- .../src/lib/active_filters_message.ts | 2 +- packages/jest-core/src/plugins/quit.ts | 6 +-- .../src/plugins/test_name_pattern.ts | 11 +++-- .../src/plugins/test_path_pattern.ts | 11 +++-- .../jest-core/src/plugins/update_snapshots.ts | 5 ++- .../plugins/update_snapshots_interactive.ts | 13 +++--- packages/jest-diff/src/index.ts | 1 + packages/jest-each/src/index.ts | 6 ++- packages/jest-environment-jsdom/src/index.ts | 4 +- packages/jest-haste-map/src/getMockName.ts | 2 +- .../src/lib/normalizePathSep.ts | 5 ++- .../src/assertionErrorMessage.ts | 2 +- packages/jest-types/src/Circus.ts | 2 +- packages/jest-validate/src/validate.ts | 5 ++- packages/jest-watcher/src/BaseWatchPlugin.ts | 4 +- packages/jest-watcher/src/JestHooks.ts | 4 +- yarn.lock | 40 +++++++++---------- 20 files changed, 83 insertions(+), 59 deletions(-) diff --git a/package.json b/package.json index 2a7707c2a31d..0f268394eaa3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/expect/src/extractExpectedAssertionsErrors.ts b/packages/expect/src/extractExpectedAssertionsErrors.ts index de97acc2dc4d..44aa5ba95b2a 100644 --- a/packages/expect/src/extractExpectedAssertionsErrors.ts +++ b/packages/expect/src/extractExpectedAssertionsErrors.ts @@ -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, diff --git a/packages/jest-circus/src/formatNodeAssertErrors.ts b/packages/jest-circus/src/formatNodeAssertErrors.ts index 69a3c144fd26..d9dbdee0bb8e 100644 --- a/packages/jest-circus/src/formatNodeAssertErrors.ts +++ b/packages/jest-circus/src/formatNodeAssertErrors.ts @@ -38,7 +38,10 @@ const humanReadableOperators: Record = { 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; diff --git a/packages/jest-core/src/lib/active_filters_message.ts b/packages/jest-core/src/lib/active_filters_message.ts index 9f7d40801743..7d2a29780487 100644 --- a/packages/jest-core/src/lib/active_filters_message.ts +++ b/packages/jest-core/src/lib/active_filters_message.ts @@ -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 = [ diff --git a/packages/jest-core/src/plugins/quit.ts b/packages/jest-core/src/plugins/quit.ts index 462de025729c..ac4c0646351e 100644 --- a/packages/jest-core/src/plugins/quit.ts +++ b/packages/jest-core/src/plugins/quit.ts @@ -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; @@ -15,7 +15,7 @@ class QuitPlugin extends BaseWatchPlugin { this.isInternal = true; } - async run() { + async run(): Promise { if (typeof this._stdin.setRawMode === 'function') { this._stdin.setRawMode(false); } @@ -23,7 +23,7 @@ class QuitPlugin extends BaseWatchPlugin { process.exit(0); } - getUsageInfo() { + getUsageInfo(): UsageData { return { key: 'q', prompt: 'quit watch mode', diff --git a/packages/jest-core/src/plugins/test_name_pattern.ts b/packages/jest-core/src/plugins/test_name_pattern.ts index 5c76866ef9ff..64391e1dc18a 100644 --- a/packages/jest-core/src/plugins/test_name_pattern.ts +++ b/packages/jest-core/src/plugins/test_name_pattern.ts @@ -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'; @@ -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); } diff --git a/packages/jest-core/src/plugins/test_path_pattern.ts b/packages/jest-core/src/plugins/test_path_pattern.ts index 5abe1e1e9279..05b4e3d67c0c 100644 --- a/packages/jest-core/src/plugins/test_path_pattern.ts +++ b/packages/jest-core/src/plugins/test_path_pattern.ts @@ -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'; @@ -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); } diff --git a/packages/jest-core/src/plugins/update_snapshots.ts b/packages/jest-core/src/plugins/update_snapshots.ts index 9c07e919018d..1a637895d500 100644 --- a/packages/jest-core/src/plugins/update_snapshots.ts +++ b/packages/jest-core/src/plugins/update_snapshots.ts @@ -10,6 +10,7 @@ import { BaseWatchPlugin, JestHookSubscriber, UpdateConfigCallback, + UsageData, } from 'jest-watcher'; class UpdateSnapshotsPlugin extends BaseWatchPlugin { @@ -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', diff --git a/packages/jest-core/src/plugins/update_snapshots_interactive.ts b/packages/jest-core/src/plugins/update_snapshots_interactive.ts index 31414365672d..7a73d62b27c9 100644 --- a/packages/jest-core/src/plugins/update_snapshots_interactive.ts +++ b/packages/jest-core/src/plugins/update_snapshots_interactive.ts @@ -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 { @@ -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, @@ -52,7 +52,7 @@ class UpdateSnapshotInteractivePlugin extends BaseWatchPlugin { }); } - onKey(key: string) { + onKey(key: string): void { if (this._snapshotInteractiveMode.isActive()) { this._snapshotInteractiveMode.put(key); } @@ -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', diff --git a/packages/jest-diff/src/index.ts b/packages/jest-diff/src/index.ts index 9c9b7f7be867..75957a113d88 100644 --- a/packages/jest-diff/src/index.ts +++ b/packages/jest-diff/src/index.ts @@ -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; diff --git a/packages/jest-each/src/index.ts b/packages/jest-each/src/index.ts index 9836bd2136cb..b22d4e305ef6 100644 --- a/packages/jest-each/src/index.ts +++ b/packages/jest-each/src/index.ts @@ -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 => install(global as Global, table, ...data); each.withGlobal = (g: Global) => ( table: Global.EachTable, diff --git a/packages/jest-environment-jsdom/src/index.ts b/packages/jest-environment-jsdom/src/index.ts index 9b887a7a1ed5..595ba752c56b 100644 --- a/packages/jest-environment-jsdom/src/index.ts +++ b/packages/jest-environment-jsdom/src/index.ts @@ -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'; @@ -135,7 +135,7 @@ class JSDOMEnvironment implements JestEnvironment { return null; } - getVmContext() { + getVmContext(): Context | null { if (this.dom) { return this.dom.getInternalVMContext(); } diff --git a/packages/jest-haste-map/src/getMockName.ts b/packages/jest-haste-map/src/getMockName.ts index a30db82f1c73..428456985d7a 100644 --- a/packages/jest-haste-map/src/getMockName.ts +++ b/packages/jest-haste-map/src/getMockName.ts @@ -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))) diff --git a/packages/jest-haste-map/src/lib/normalizePathSep.ts b/packages/jest-haste-map/src/lib/normalizePathSep.ts index 9e89d0c87e11..2dc7ea57e503 100644 --- a/packages/jest-haste-map/src/lib/normalizePathSep.ts +++ b/packages/jest-haste-map/src/lib/normalizePathSep.ts @@ -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; diff --git a/packages/jest-jasmine2/src/assertionErrorMessage.ts b/packages/jest-jasmine2/src/assertionErrorMessage.ts index 98433f477fb8..9f252eec604c 100644 --- a/packages/jest-jasmine2/src/assertionErrorMessage.ts +++ b/packages/jest-jasmine2/src/assertionErrorMessage.ts @@ -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; diff --git a/packages/jest-types/src/Circus.ts b/packages/jest-types/src/Circus.ts index 1ffc9cf4673c..bd82d0e0082a 100644 --- a/packages/jest-types/src/Circus.ts +++ b/packages/jest-types/src/Circus.ts @@ -208,7 +208,7 @@ export type DescribeBlock = { tests: Array; }; -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 diff --git a/packages/jest-validate/src/validate.ts b/packages/jest-validate/src/validate.ts index 11713a4360ed..4e63da9eaed9 100644 --- a/packages/jest-validate/src/validate.ts +++ b/packages/jest-validate/src/validate.ts @@ -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, options: ValidationOptions) => { +const validate = ( + config: Record, + options: ValidationOptions, +): {hasDeprecationWarnings: boolean; isValid: boolean} => { hasDeprecationWarnings = false; // Preserve default blacklist entries even with user-supplied blacklist diff --git a/packages/jest-watcher/src/BaseWatchPlugin.ts b/packages/jest-watcher/src/BaseWatchPlugin.ts index 17ed0d7c21e8..5f59a98a249e 100644 --- a/packages/jest-watcher/src/BaseWatchPlugin.ts +++ b/packages/jest-watcher/src/BaseWatchPlugin.ts @@ -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, diff --git a/packages/jest-watcher/src/JestHooks.ts b/packages/jest-watcher/src/JestHooks.ts index 6f7f5fc4d03e..0e49c7681ca7 100644 --- a/packages/jest-watcher/src/JestHooks.ts +++ b/packages/jest-watcher/src/JestHooks.ts @@ -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 { diff --git a/yarn.lock b/yarn.lock index 471aa0cdd4b6..abaad9b68bd8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"