Skip to content

Commit ecff79f

Browse files
committed
refactor: use default ansis import for consistency
1 parent 9293a18 commit ecff79f

File tree

9 files changed

+51
-51
lines changed

9 files changed

+51
-51
lines changed

packages/cli/src/lib/implementation/formatting.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { bold, dim, green } from 'ansis';
1+
import ansis from 'ansis';
22

33
export function titleStyle(title: string) {
4-
return `${bold(title)}`;
4+
return `${ansis.bold(title)}`;
55
}
66

77
export function headerStyle(title: string) {
8-
return `${green(title)}`;
8+
return `${ansis.green(title)}`;
99
}
1010

1111
export function descriptionStyle(title: string) {
12-
return `${dim(title)}`;
12+
return `${ansis.dim(title)}`;
1313
}
1414

1515
export function formatObjectValue<T>(opts: T, propName: keyof T) {

packages/cli/src/lib/implementation/formatting.unit.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold, dim, green } from 'ansis';
1+
import ansis from 'ansis';
22
import { describe, expect } from 'vitest';
33
import {
44
descriptionStyle,
@@ -10,13 +10,13 @@ import {
1010

1111
describe('titleStyle', () => {
1212
it('should return a string with green color', () => {
13-
expect(titleStyle('Code Pushup CLI')).toBe(bold('Code Pushup CLI'));
13+
expect(titleStyle('Code Pushup CLI')).toBe(ansis.bold('Code Pushup CLI'));
1414
});
1515
});
1616

1717
describe('headerStyle', () => {
1818
it('should return a string with green color', () => {
19-
expect(headerStyle('Options')).toBe(green('Options'));
19+
expect(headerStyle('Options')).toBe(ansis.green('Options'));
2020
});
2121
});
2222

@@ -27,7 +27,7 @@ describe('descriptionStyle', () => {
2727
'Run collect using custom tsconfig to parse code-pushup.config.ts file.',
2828
),
2929
).toBe(
30-
dim(
30+
ansis.dim(
3131
'Run collect using custom tsconfig to parse code-pushup.config.ts file.',
3232
),
3333
);
@@ -44,7 +44,7 @@ describe('formatObjectValue', () => {
4444
'describe',
4545
),
4646
).toEqual({
47-
describe: dim('Directory for the produced reports'),
47+
describe: ansis.dim('Directory for the produced reports'),
4848
});
4949
});
5050
});
@@ -62,7 +62,7 @@ describe('formatNestedValues', () => {
6262
),
6363
).toEqual({
6464
outputDir: {
65-
describe: dim('Directory for the produced reports'),
65+
describe: ansis.dim('Directory for the produced reports'),
6666
},
6767
});
6868
});

packages/cli/src/lib/yargs-cli.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable max-lines-per-function */
2-
import { blue, dim, green } from 'ansis';
2+
import ansis from 'ansis';
33
import { createRequire } from 'node:module';
44
import yargs, {
55
type Argv,
@@ -24,17 +24,17 @@ import {
2424
import { logErrorBeforeThrow } from './implementation/global.utils.js';
2525

2626
export const yargsDecorator = {
27-
'Commands:': `${green('Commands')}:`,
28-
'Options:': `${green('Options')}:`,
29-
'Examples:': `${green('Examples')}:`,
30-
boolean: blue('boolean'),
31-
count: blue('count'),
32-
string: blue('string'),
33-
array: blue('array'),
34-
required: blue('required'),
35-
'default:': `${blue('default')}:`,
36-
'choices:': `${blue('choices')}:`,
37-
'aliases:': `${blue('aliases')}:`,
27+
'Commands:': `${ansis.green('Commands')}:`,
28+
'Options:': `${ansis.green('Options')}:`,
29+
'Examples:': `${ansis.green('Examples')}:`,
30+
boolean: ansis.blue('boolean'),
31+
count: ansis.blue('count'),
32+
string: ansis.blue('string'),
33+
array: ansis.blue('array'),
34+
required: ansis.blue('required'),
35+
'default:': `${ansis.blue('default')}:`,
36+
'choices:': `${ansis.blue('choices')}:`,
37+
'aliases:': `${ansis.blue('aliases')}:`,
3838
};
3939

4040
/**
@@ -80,7 +80,7 @@ export function yargsCli<T = unknown>(
8080
.help('help', descriptionStyle('Show help'))
8181
.alias('h', 'help')
8282
.showHelpOnFail(false)
83-
.version('version', dim`Show version`, packageJson.version)
83+
.version('version', ansis.dim('Show version'), packageJson.version)
8484
.check(args => {
8585
const persist = args['persist'] as PersistConfig | undefined;
8686
return persist == null || validatePersistFormat(persist);

packages/core/src/lib/implementation/execute-plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold } from 'ansis';
1+
import ansis from 'ansis';
22
import {
33
type AuditOutput,
44
type AuditReport,
@@ -120,15 +120,15 @@ const wrapProgress = async (
120120
progressBar: ProgressBar | null,
121121
) => {
122122
const { plugin: pluginCfg, ...rest } = cfg;
123-
progressBar?.updateTitle(`Executing ${bold(pluginCfg.title)}`);
123+
progressBar?.updateTitle(`Executing ${ansis.bold(pluginCfg.title)}`);
124124
try {
125125
const pluginReport = await executePlugin(pluginCfg, rest);
126126
progressBar?.incrementInSteps(steps);
127127
return pluginReport;
128128
} catch (error) {
129129
progressBar?.incrementInSteps(steps);
130130
throw new Error(
131-
`- Plugin ${bold(pluginCfg.title)} (${bold(
131+
`- Plugin ${ansis.bold(pluginCfg.title)} (${ansis.bold(
132132
pluginCfg.slug,
133133
)}) produced the following error:\n - ${stringifyError(error)}`,
134134
);

packages/core/src/lib/implementation/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold } from 'ansis';
1+
import ansis from 'ansis';
22
import { writeFile } from 'node:fs/promises';
33
import path from 'node:path';
44
import {
@@ -64,7 +64,7 @@ export async function executeRunnerFunction(
6464
export class AuditOutputsMissingAuditError extends Error {
6565
constructor(auditSlug: string) {
6666
super(
67-
`Audit metadata not present in plugin config. Missing slug: ${bold(
67+
`Audit metadata not present in plugin config. Missing slug: ${ansis.bold(
6868
auditSlug,
6969
)}`,
7070
);

packages/utils/mocks/fixtures/execute-progress.mock.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold, gray } from 'ansis';
1+
import ansis from 'ansis';
22
import { getProgressBar } from '../../../../dist/packages/utils';
33

44
const _arg = (name, fallback = '') =>
@@ -27,8 +27,8 @@ const verbose = Boolean(_arg('verbose', false));
2727
(async () => {
2828
verbose &&
2929
console.info(
30-
gray(
31-
`Start progress with duration: ${bold(duration)}, steps: ${bold(
30+
ansis.gray(
31+
`Start progress with duration: ${ansis.bold(duration)}, steps: ${ansis.bold(
3232
steps,
3333
)}`,
3434
),

packages/utils/src/lib/progress.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { black, bold, gray, green } from 'ansis';
1+
import ansis from 'ansis';
22
import { type CtorOptions, MultiProgressBars } from 'multi-progress-bars';
33
import { TERMINAL_WIDTH } from './reports/constants.js';
44

55
type BarStyles = 'active' | 'done' | 'idle';
66
type StatusStyles = Record<BarStyles, (s: string) => string>;
77
export const barStyles: StatusStyles = {
8-
active: (s: string) => green(s),
9-
done: (s: string) => gray(s),
10-
idle: (s: string) => gray(s),
8+
active: (s: string) => ansis.green(s),
9+
done: (s: string) => ansis.gray(s),
10+
idle: (s: string) => ansis.gray(s),
1111
};
1212

1313
export const messageStyles: StatusStyles = {
14-
active: (s: string) => black(s),
15-
done: (s: string) => bold.green(s),
16-
idle: (s: string) => gray(s),
14+
active: (s: string) => ansis.black(s),
15+
done: (s: string) => ansis.bold.green(s),
16+
idle: (s: string) => ansis.gray(s),
1717
};
1818

1919
export type ProgressBar = {

testing/test-utils/src/lib/utils/test-folder-setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bold } from 'ansis';
1+
import ansis from 'ansis';
22
import { mkdir, readdir, rename, rm, stat } from 'node:fs/promises';
33
import path from 'node:path';
44

@@ -12,7 +12,7 @@ export async function teardownTestFolder(dirName: string) {
1212
const stats = await stat(dirName);
1313
if (!stats.isDirectory()) {
1414
console.warn(
15-
`⚠️ You are trying to delete a file instead of a directory - ${bold(
15+
`⚠️ You are trying to delete a file instead of a directory - ${ansis.bold(
1616
dirName,
1717
)}.`,
1818
);
@@ -31,7 +31,7 @@ export async function teardownTestFolder(dirName: string) {
3131
});
3232
} catch {
3333
console.warn(
34-
`⚠️ Failed to delete test artefact ${bold(
34+
`⚠️ Failed to delete test artefact ${ansis.bold(
3535
dirName,
3636
)} so the folder is still in the file system!\nIt may require a deletion before running e2e tests again.`,
3737
);

tools/eslint-formatter-multi/src/lib/stylish.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @fileoverview Stylish reporter
55
* @author Sindre Sorhus
66
*/
7-
import { bold, dim, red, reset, underline, yellow } from 'ansis';
7+
import ansis from 'ansis';
88
import type { ESLint } from 'eslint';
99
import { stripVTControlCharacters } from 'node:util';
1010
import { textTable } from './text-table.js';
@@ -49,18 +49,18 @@ export function stylishFormatter(results: ESLint.LintResult[]): string {
4949
fixableErrorCount += result.fixableErrorCount;
5050
fixableWarningCount += result.fixableWarningCount;
5151

52-
output += `${underline(result.filePath)}\n`;
52+
output += `${ansis.underline(result.filePath)}\n`;
5353

5454
output += `${textTable(
5555
messages.map(message => {
5656
// eslint-disable-next-line functional/no-let
5757
let messageType;
5858
5959
if (message.fatal || message.severity === 2) {
60-
messageType = red('error');
60+
messageType = ansis.red('error');
6161
summaryColor = 'red';
6262
} else {
63-
messageType = yellow('warning');
63+
messageType = ansis.yellow('warning');
6464
}
6565
6666
return [
@@ -69,7 +69,7 @@ export function stylishFormatter(results: ESLint.LintResult[]): string {
6969
String(message.column || 0),
7070
messageType,
7171
message.message.replace(/([^ ])\.$/u, '$1'),
72-
dim(message.ruleId || ''),
72+
ansis.dim(message.ruleId || ''),
7373
];
7474
}),
7575
{
@@ -81,16 +81,16 @@ export function stylishFormatter(results: ESLint.LintResult[]): string {
8181
)
8282
.split('\n')
8383
.map(el =>
84-
el.replace(/(\d+)\s+(\d+)/u, (m, p1, p2) => dim(`${p1}:${p2}`)),
84+
el.replace(/(\d+)\s+(\d+)/u, (m, p1, p2) => ansis.dim(`${p1}:${p2}`)),
8585
)
8686
.join('\n')}\n\n`;
8787
});
8888

8989
const total = errorCount + warningCount;
9090

9191
if (total > 0) {
92-
const colorFn = summaryColor === 'red' ? red : yellow;
93-
output += bold(
92+
const colorFn = summaryColor === 'red' ? ansis.red : ansis.yellow;
93+
output += ansis.bold(
9494
colorFn(
9595
[
9696
'\u2716 ',
@@ -108,7 +108,7 @@ export function stylishFormatter(results: ESLint.LintResult[]): string {
108108
);
109109

110110
if (fixableErrorCount > 0 || fixableWarningCount > 0) {
111-
output += bold(
111+
output += ansis.bold(
112112
colorFn(
113113
[
114114
' ',
@@ -125,5 +125,5 @@ export function stylishFormatter(results: ESLint.LintResult[]): string {
125125
}
126126

127127
// Resets output color, for prevent change on top level
128-
return total > 0 ? reset(output) : '';
128+
return total > 0 ? ansis.reset(output) : '';
129129
}

0 commit comments

Comments
 (0)