From b694e44aafea2bb96cce539d77595f09afff4268 Mon Sep 17 00:00:00 2001 From: Brian Basor Date: Wed, 5 Jun 2024 16:04:55 -0400 Subject: [PATCH 1/5] Use Array.from instead of the spread operator This should fix the bug reported in https://github.com/TimMikeladze/tsc-baseline/issues/21 --- src/util.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.ts b/src/util.ts index fd72850..47469de 100644 --- a/src/util.ts +++ b/src/util.ts @@ -88,7 +88,7 @@ export const getNewErrors = ( } export const getTotalErrorsCount = (errorMap: Map): number => - [...errorMap.values()].reduce((sum, info) => sum + info.count, 0) + Array.from(errorMap.values()).reduce((sum, info) => sum + info.count, 0) export const toHumanReadableText = ( errorMap: Map From 1d018d749365f3637e2750338a1dc24a614a0f59 Mon Sep 17 00:00:00 2001 From: Brian Basor Date: Wed, 5 Jun 2024 16:08:00 -0400 Subject: [PATCH 2/5] Fix up the pluralization logic for the situation where there are zero errors The only number to report as a singular is when there is one item. Zero should be reported as a plural. Was: `0 error already in baseline.` Now: `0 errors already in baseline.` --- src/cli.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 3003b44..b4b5cbe 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -69,15 +69,13 @@ import { rmSync } from 'fs' const oldErrorsCount = getTotalErrorsCount(oldErrors) const newErrorsCountMessage = - newErrorsCount === 0 - ? '0 errors found' - : `${newErrorsCount} error${newErrorsCount > 1 ? 's' : ''} found` + `${newErrorsCount} error${newErrorsCount == 1 ? '' : 's'} found` console.error(`${newErrorsCount > 0 ? '\nNew errors found:' : ''} ${toHumanReadableText(newErrors)} ${newErrorsCountMessage}. ${oldErrorsCount} error${ - oldErrorsCount > 1 ? 's' : '' + oldErrorsCount == 1 ? '' : 's' } already in baseline.`) if (newErrorsCount > 0) { From 73eef5660e004920ec3178334e7e9cce1dea79ab Mon Sep 17 00:00:00 2001 From: Brian Basor Date: Thu, 6 Jun 2024 12:13:10 -0400 Subject: [PATCH 3/5] Minor changes from code review - Use strict equality - Specify that these are new errors Co-authored-by: Will Douglas --- src/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index b4b5cbe..2132e4e 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -69,7 +69,7 @@ import { rmSync } from 'fs' const oldErrorsCount = getTotalErrorsCount(oldErrors) const newErrorsCountMessage = - `${newErrorsCount} error${newErrorsCount == 1 ? '' : 's'} found` + `${newErrorsCount} new error${newErrorsCount === 1 ? '' : 's'} found` console.error(`${newErrorsCount > 0 ? '\nNew errors found:' : ''} ${toHumanReadableText(newErrors)} From f24205efc7590b1b642d349f31fe25cd0c8482c7 Mon Sep 17 00:00:00 2001 From: Brian Basor Date: Thu, 6 Jun 2024 12:13:48 -0400 Subject: [PATCH 4/5] Explain why we used Array.from Co-authored-by: Will Douglas --- src/util.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util.ts b/src/util.ts index 47469de..6b75ce0 100644 --- a/src/util.ts +++ b/src/util.ts @@ -88,6 +88,10 @@ export const getNewErrors = ( } export const getTotalErrorsCount = (errorMap: Map): number => + // NOTE: Previously, this was written with an array spread, but there was a bug + // with microbundle that was incorrectly compiling that (see: https://github.com/TimMikeladze/tsc-baseline/issues/21). + // Until that is resolved or the bundler is switched for this repo, this has been + // rewritten with Array.from Array.from(errorMap.values()).reduce((sum, info) => sum + info.count, 0) export const toHumanReadableText = ( From 6c8fe768a3430d5772fa53b5401a40e160f8d71a Mon Sep 17 00:00:00 2001 From: Brian Basor Date: Thu, 6 Jun 2024 12:17:41 -0400 Subject: [PATCH 5/5] Use strict equality in all the revised ternaries --- src/cli.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index 2132e4e..8213c56 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -75,7 +75,7 @@ import { rmSync } from 'fs' ${toHumanReadableText(newErrors)} ${newErrorsCountMessage}. ${oldErrorsCount} error${ - oldErrorsCount == 1 ? '' : 's' + oldErrorsCount === 1 ? '' : 's' } already in baseline.`) if (newErrorsCount > 0) {