Skip to content

Commit

Permalink
chore: set ESLint’s 'no-inferrable-types' rule to 'error' (jestjs#12785)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas authored and F3n67u committed May 2, 2022
1 parent aa35932 commit 006d9f4
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 21 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
rules: {
'@typescript-eslint/array-type': ['error', {default: 'generic'}],
'@typescript-eslint/ban-types': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{argsIgnorePattern: '^_'},
Expand Down
5 changes: 3 additions & 2 deletions packages/expect/src/asymmetricMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,10 @@ class StringMatching extends AsymmetricMatcher<RegExp> {
return 'string';
}
}

class CloseTo extends AsymmetricMatcher<number> {
private precision: number;
constructor(sample: number, precision: number = 2, inverse: boolean = false) {
constructor(sample: number, precision = 2, inverse = false) {
if (!isA('Number', sample)) {
throw new Error('Expected is not a Number');
}
Expand All @@ -311,7 +312,7 @@ class CloseTo extends AsymmetricMatcher<number> {
if (!isA('Number', other)) {
return false;
}
let result: boolean = false;
let result = false;
if (other === Infinity && this.sample === Infinity) {
result = true; // Infinity - Infinity is NaN
} else if (other === -Infinity && this.sample === -Infinity) {
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-console/src/BufferedConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ export default class BufferedConsole extends Console {
}
}

override count(label: string = 'default'): void {
override count(label = 'default'): void {
if (!this._counters[label]) {
this._counters[label] = 0;
}

this._log('count', format(`${label}: ${++this._counters[label]}`));
}

override countReset(label: string = 'default'): void {
override countReset(label = 'default'): void {
this._counters[label] = 0;
}

Expand Down Expand Up @@ -138,15 +138,15 @@ export default class BufferedConsole extends Console {
this._log('log', format(firstArg, ...rest));
}

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

this._timers[label] = new Date();
}

override timeEnd(label: string = 'default'): void {
override timeEnd(label = 'default'): void {
const startTime = this._timers[label];

if (startTime) {
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-console/src/CustomConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export default class CustomConsole extends Console {
}
}

override count(label: string = 'default'): void {
override count(label = 'default'): void {
if (!this._counters[label]) {
this._counters[label] = 0;
}

this._log('count', format(`${label}: ${++this._counters[label]}`));
}

override countReset(label: string = 'default'): void {
override countReset(label = 'default'): void {
this._counters[label] = 0;
}

Expand Down Expand Up @@ -116,15 +116,15 @@ export default class CustomConsole extends Console {
this._log('log', format(firstArg, ...args));
}

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

this._timers[label] = new Date();
}

override timeEnd(label: string = 'default'): void {
override timeEnd(label = 'default'): void {
const startTime = this._timers[label];

if (startTime) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/lib/activeFiltersMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {Config} from '@jest/types';

const activeFilters = (
globalConfig: Config.GlobalConfig,
delimiter: string = '\n',
delimiter = '\n',
): string => {
const {testNamePattern, testPathPattern} = globalConfig;
if (testNamePattern || testPathPattern) {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-each/src/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type GlobalCallback = (

export default function bind<EachCallback extends Global.TestCallback>(
cb: GlobalCallback,
supportsDone: boolean = true,
supportsDone = true,
) {
return (
table: Global.EachTable,
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-matcher-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export const SUGGEST_TO_CONTAIN_EQUAL = chalk.dim(

export const stringify = (
object: unknown,
maxDepth: number = 10,
maxWidth: number = 10,
maxDepth = 10,
maxWidth = 10,
): string => {
const MAX_LENGTH = 10000;
let result;
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ class ScriptTransformer {
const {transformer, transformerConfig = {}} =
this._getTransformer(filename) || {};
const cacheFilePath = this._getFileCachePath(filename, content, options);
const sourceMapPath: string = `${cacheFilePath}.map`;
const sourceMapPath = `${cacheFilePath}.map`;
// Ignore cache if `config.cache` is set (--no-cache)
const code = this._config.cache ? readCodeCacheFile(cacheFilePath) : null;

Expand Down Expand Up @@ -528,7 +528,7 @@ class ScriptTransformer {
content,
options,
);
const sourceMapPath: string = `${cacheFilePath}.map`;
const sourceMapPath = `${cacheFilePath}.map`;
// Ignore cache if `config.cache` is set (--no-cache)
const code = this._config.cache ? readCodeCacheFile(cacheFilePath) : null;

Expand Down Expand Up @@ -829,7 +829,7 @@ export async function createTranspilingRequire(

return async function requireAndTranspileModule<TModuleType = unknown>(
resolverPath: string,
applyInteropRequireDefault: boolean = false,
applyInteropRequireDefault = false,
) {
const transpiledModule =
await transformer.requireAndTranspileModule<TModuleType>(
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-util/src/formatTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

export default function formatTime(
time: number,
prefixPower: number = -3,
padLeftLength: number = 0,
prefixPower = -3,
padLeftLength = 0,
): string {
const prefixes = ['n', 'μ', 'm', ''];
const prefixIndex = Math.max(
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/isPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// capture globalThis.Promise before it may potentially be overwritten
const Promise: any = globalThis.Promise;
const Promise = globalThis.Promise;

// see ES2015 spec 25.4.4.5, https://stackoverflow.com/a/38339199
const isPromise = (candidate: unknown): candidate is Promise<unknown> =>
Expand Down
2 changes: 1 addition & 1 deletion packages/pretty-format/src/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function printIteratorEntries(
// Too bad, so sad that separator for ECMAScript Map has been ' => '
// What a distracting diff if you change a data structure to/from
// ECMAScript Object or Immutable.Map/OrderedMap which use the default.
separator: string = ': ',
separator = ': ',
): string {
let result = '';
let width = 0;
Expand Down

0 comments on commit 006d9f4

Please sign in to comment.