Skip to content

Commit

Permalink
chore: run type lint on @jest/console (#13403)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 8, 2022
1 parent 23beadc commit fb2f161
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

import * as assert from 'assert';
import {strict as assert} from 'assert';
import fc from 'fast-check';
import expect from '../';
import {
Expand Down
22 changes: 13 additions & 9 deletions packages/jest-console/src/BufferedConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import assert = require('assert');
import {AssertionError, strict as assert} from 'assert';
import {Console} from 'console';
import {InspectOptions, format, formatWithOptions, inspect} from 'util';
import chalk = require('chalk');
Expand Down Expand Up @@ -37,6 +37,7 @@ export default class BufferedConsole extends Console {
}

static write(
this: void,
buffer: ConsoleBuffer,
type: LogType,
message: LogMessage,
Expand All @@ -45,7 +46,7 @@ export default class BufferedConsole extends Console {
const stackLevel = level != null ? level : 2;
const rawStack = new ErrorWithStack(undefined, BufferedConsole.write).stack;

invariant(rawStack, 'always have a stack trace');
invariant(rawStack != null, 'always have a stack trace');

const origin = rawStack
.split('\n')
Expand Down Expand Up @@ -74,7 +75,10 @@ export default class BufferedConsole extends Console {
override assert(value: unknown, message?: string | Error): void {
try {
assert(value, message);
} catch (error: any) {
} catch (error) {
if (!(error instanceof AssertionError)) {
throw error;
}
this._log('assert', error.toString());
}
}
Expand Down Expand Up @@ -111,15 +115,15 @@ export default class BufferedConsole extends Console {
override group(title?: string, ...rest: Array<unknown>): void {
this._groupDepth++;

if (title || rest.length > 0) {
if (title != null || rest.length > 0) {
this._log('group', chalk.bold(format(title, ...rest)));
}
}

override groupCollapsed(title?: string, ...rest: Array<unknown>): void {
this._groupDepth++;

if (title || rest.length > 0) {
if (title != null || rest.length > 0) {
this._log('groupCollapsed', chalk.bold(format(title, ...rest)));
}
}
Expand All @@ -139,7 +143,7 @@ export default class BufferedConsole extends Console {
}

override time(label = 'default'): void {
if (this._timers[label]) {
if (this._timers[label] != null) {
return;
}

Expand All @@ -149,7 +153,7 @@ export default class BufferedConsole extends Console {
override timeEnd(label = 'default'): void {
const startTime = this._timers[label];

if (startTime) {
if (startTime != null) {
const endTime = new Date();
const time = endTime.getTime() - startTime.getTime();
this._log('time', format(`${label}: ${formatTime(time)}`));
Expand All @@ -160,7 +164,7 @@ export default class BufferedConsole extends Console {
override timeLog(label = 'default', ...data: Array<unknown>): void {
const startTime = this._timers[label];

if (startTime) {
if (startTime != null) {
const endTime = new Date();
const time = endTime.getTime() - startTime.getTime();
this._log('time', format(`${label}: ${formatTime(time)}`, ...data));
Expand All @@ -176,7 +180,7 @@ export default class BufferedConsole extends Console {
}
}

function invariant(condition: unknown, message?: string): asserts condition {
function invariant(condition: boolean, message?: string): asserts condition {
if (!condition) {
throw new Error(message);
}
Expand Down
17 changes: 10 additions & 7 deletions packages/jest-console/src/CustomConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import assert = require('assert');
import {AssertionError, strict as assert} from 'assert';
import {Console} from 'console';
import {InspectOptions, format, formatWithOptions, inspect} from 'util';
import chalk = require('chalk');
Expand Down Expand Up @@ -52,7 +52,10 @@ export default class CustomConsole extends Console {
override assert(value: unknown, message?: string | Error): asserts value {
try {
assert(value, message);
} catch (error: any) {
} catch (error) {
if (!(error instanceof AssertionError)) {
throw error;
}
this._logError('assert', error.toString());
}
}
Expand Down Expand Up @@ -89,15 +92,15 @@ export default class CustomConsole extends Console {
override group(title?: string, ...args: Array<unknown>): void {
this._groupDepth++;

if (title || args.length > 0) {
if (title != null || args.length > 0) {
this._log('group', chalk.bold(format(title, ...args)));
}
}

override groupCollapsed(title?: string, ...args: Array<unknown>): void {
this._groupDepth++;

if (title || args.length > 0) {
if (title != null || args.length > 0) {
this._log('groupCollapsed', chalk.bold(format(title, ...args)));
}
}
Expand All @@ -117,7 +120,7 @@ export default class CustomConsole extends Console {
}

override time(label = 'default'): void {
if (this._timers[label]) {
if (this._timers[label] != null) {
return;
}

Expand All @@ -127,7 +130,7 @@ export default class CustomConsole extends Console {
override timeEnd(label = 'default'): void {
const startTime = this._timers[label];

if (startTime) {
if (startTime != null) {
const endTime = new Date().getTime();
const time = endTime - startTime.getTime();
this._log('time', format(`${label}: ${formatTime(time)}`));
Expand All @@ -138,7 +141,7 @@ export default class CustomConsole extends Console {
override timeLog(label = 'default', ...data: Array<unknown>): void {
const startTime = this._timers[label];

if (startTime) {
if (startTime != null) {
const endTime = new Date();
const time = endTime.getTime() - startTime.getTime();
this._log('time', format(`${label}: ${formatTime(time)}`, ...data));
Expand Down
3 changes: 2 additions & 1 deletion packages/jest-console/src/getConsoleOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function getConsoleOutput(
config: StackTraceConfig,
globalConfig: Config.GlobalConfig,
): string {
const TITLE_INDENT = globalConfig.verbose ? ' '.repeat(2) : ' '.repeat(4);
const TITLE_INDENT =
globalConfig.verbose === true ? ' '.repeat(2) : ' '.repeat(4);
const CONSOLE_INDENT = TITLE_INDENT + ' '.repeat(2);

const logEntries = buffer.reduce((output, {type, message, origin}) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/watchers/WatchmanWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import * as assert from 'assert';
import {strict as assert} from 'assert';
import {EventEmitter} from 'events';
import * as path from 'path';
import watchman from 'fb-watchman';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jest.mock('graceful-fs', () => ({
existsSync: jest.fn().mockReturnValue(true),
}));

import assert = require('assert');
import {strict as assert} from 'assert';
import * as path from 'path';
import chalk = require('chalk');
import * as fs from 'graceful-fs';
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* node ./scripts/build.mjs /users/123/jest/packages/jest-111/src/111.js
*/

import * as assert from 'assert';
import {strict as assert} from 'assert';
import * as path from 'path';
import {fileURLToPath} from 'url';
import babel from '@babel/core';
Expand Down
2 changes: 1 addition & 1 deletion scripts/buildTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import * as assert from 'assert';
import {strict as assert} from 'assert';
import * as os from 'os';
import * as path from 'path';
import chalk from 'chalk';
Expand Down
2 changes: 1 addition & 1 deletion scripts/buildUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import * as assert from 'assert';
import {strict as assert} from 'assert';
import {createRequire} from 'module';
import * as path from 'path';
import {fileURLToPath} from 'url';
Expand Down
1 change: 1 addition & 0 deletions scripts/lintTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const packagesToTest = [
'babel-plugin-jest-hoist',
'diff-sequences',
'jest-changed-files',
'jest-console',
'jest-docblock',
'jest-environment',
'jest-globals',
Expand Down

0 comments on commit fb2f161

Please sign in to comment.