Skip to content

Commit b5e896d

Browse files
authored
Merge branch 'master' into update-format-lint-config
2 parents 83a6455 + 0a227ea commit b5e896d

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

src/api/github/checkRun.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Endpoints } from '@octokit/types';
33
import fs from 'fs-extra';
44
import git from 'isomorphic-git';
55

6+
import { pluralise } from '../../utils/logging';
7+
68
type Output = NonNullable<
79
Endpoints['POST /repos/{owner}/{repo}/check-runs']['parameters']['output']
810
>;
@@ -66,9 +68,7 @@ const suffixTitle = (title: string, inputAnnotations: number): string => {
6668
? GITHUB_MAX_ANNOTATIONS
6769
: inputAnnotations;
6870

69-
const plural = addedAnnotations === 1 ? '' : 's';
70-
71-
return `${title} (${addedAnnotations} annotation${plural} added)`;
71+
return `${title} (${pluralise(addedAnnotations, 'annotation')} added)`;
7272
};
7373

7474
/**

src/cli/adapter/eslint.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
import chalk from 'chalk';
44
import { ESLint, Linter } from 'eslint';
55

6-
import { Logger } from '../../utils/logging';
6+
import { Logger, pluralise } from '../../utils/logging';
77

88
const symbolForResult = (result: ESLint.LintResult) => {
99
if (result.errorCount) {
@@ -52,7 +52,7 @@ export const runESLint = async (
5252
const end = process.hrtime.bigint();
5353

5454
logger.plain(
55-
`Processed ${logger.pluralise(results.length, 'file')} in ${logger.timing(
55+
`Processed ${pluralise(results.length, 'file')} in ${logger.timing(
5656
start,
5757
end,
5858
)}.`,

src/cli/adapter/prettier.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from 'fs-extra';
44
import { Options, check, format, getFileInfo, resolveConfig } from 'prettier';
55

66
import { crawlDirectory } from '../../utils/dir';
7-
import { Logger } from '../../utils/logging';
7+
import { Logger, pluralise } from '../../utils/logging';
88
import { getConsumerManifest } from '../../utils/manifest';
99

1010
interface File {
@@ -108,7 +108,7 @@ export const runPrettier = async (
108108
// and the headache of conflicting `.gitignore` and `.prettierignore` rules.
109109
const filepaths = await crawlDirectory(directory, '.prettierignore');
110110

111-
logger.debug(`Discovered ${logger.pluralise(filepaths.length, 'file')}.`);
111+
logger.debug(`Discovered ${pluralise(filepaths.length, 'file')}.`);
112112

113113
const result: Result = {
114114
count: filepaths.length,
@@ -144,23 +144,21 @@ export const runPrettier = async (
144144
const end = process.hrtime.bigint();
145145

146146
logger.plain(
147-
`Processed ${logger.pluralise(
147+
`Processed ${pluralise(
148148
result.count - result.unparsed.length,
149149
'file',
150150
)} in ${logger.timing(start, end)}.`,
151151
);
152152

153153
if (result.touched.length) {
154-
logger.plain(
155-
`Formatted ${logger.pluralise(result.touched.length, 'file')}:`,
156-
);
154+
logger.plain(`Formatted ${pluralise(result.touched.length, 'file')}:`);
157155
for (const filepath of result.touched) {
158156
logger.warn(filepath);
159157
}
160158
}
161159

162160
if (result.errored.length) {
163-
logger.plain(`Flagged ${logger.pluralise(result.errored.length, 'file')}:`);
161+
logger.plain(`Flagged ${pluralise(result.errored.length, 'file')}:`);
164162
for (const { err, filepath } of result.errored) {
165163
logger.warn(filepath, ...(err ? [String(err)] : []));
166164
}

src/cli/lint/external.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,12 @@ export const externalLint = async (input: Input) => {
8383

8484
const { eslint, prettier, tscOk } = await lint({ ...input, tscOutputStream });
8585

86-
await createAnnotations(eslint, prettier, tscOk, tscOutputStream);
86+
try {
87+
await createAnnotations(eslint, prettier, tscOk, tscOutputStream);
88+
} catch (err) {
89+
log.warn('Failed to annotate results.');
90+
log.warn(err);
91+
}
8792

8893
if (eslint.ok && prettier.ok && tscOk) {
8994
return;

src/utils/logging.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export const createLogger = (debug: boolean, ...prefixes: unknown[]) => {
1111
bold: chalk.bold,
1212
formatSubtle: chalk.grey,
1313

14-
pluralise: (count: number, subject: string) =>
15-
`${count} ${subject}${count === 1 ? '' : 's'}`,
1614
timing: (start: bigint, end: bigint) =>
1715
`${Number((end - start) / BigInt(10_000_000)) / 100}s`,
1816

@@ -28,3 +26,6 @@ export const createLogger = (debug: boolean, ...prefixes: unknown[]) => {
2826
};
2927

3028
export const log = createLogger(false);
29+
30+
export const pluralise = (count: number, subject: string) =>
31+
`${count} ${subject}${count === 1 ? '' : 's'}`;

0 commit comments

Comments
 (0)