Skip to content

fix(plugin-typescript): use consistent formatting #988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
},
],
},
"displayValue": "1 issue",
"displayValue": "1 error",
"score": 0,
"slug": "syntax-errors",
"title": "Syntax errors",
Expand Down Expand Up @@ -80,7 +80,7 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
},
],
},
"displayValue": "2 issues",
"displayValue": "2 errors",
"score": 0,
"slug": "semantic-errors",
"title": "Semantic errors",
Expand All @@ -102,15 +102,15 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
},
],
},
"displayValue": "1 issue",
"displayValue": "1 error",
"score": 0,
"slug": "declaration-and-language-service-errors",
"title": "Declaration and language service errors",
"value": 1,
},
{
"description": "Errors that occur during TypeScript internal operations",
"displayValue": "0 issues",
"displayValue": "passed",
"score": 1,
"slug": "internal-errors",
"title": "Internal errors",
Expand All @@ -132,30 +132,30 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
},
],
},
"displayValue": "1 issue",
"displayValue": "1 error",
"score": 0,
"slug": "configuration-errors",
"title": "Configuration errors",
"value": 1,
},
{
"description": "Errors related to no implicit any compiler option",
"displayValue": "0 issues",
"displayValue": "passed",
"score": 1,
"slug": "no-implicit-any-errors",
"title": "No implicit any errors",
"value": 0,
},
{
"description": "Errors that do not match any known TypeScript error code",
"displayValue": "0 issues",
"displayValue": "passed",
"score": 1,
"slug": "unknown-codes",
"title": "Unknown codes",
"value": 0,
},
],
"description": "Official Code PushUp Typescript plugin.",
"description": "Official Code PushUp TypeScript plugin.",
"docsUrl": "https://www.npmjs.com/package/@code-pushup/typescript-plugin/",
"groups": [
{
Expand Down Expand Up @@ -211,7 +211,7 @@ exports[`PLUGIN collect report with typescript-plugin NPM package > should run p
"icon": "typescript",
"packageName": "@code-pushup/typescript-plugin",
"slug": "typescript",
"title": "Typescript",
"title": "TypeScript",
},
],
}
Expand Down
13 changes: 1 addition & 12 deletions e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
E2E_ENVIRONMENTS_DIR,
TEST_OUTPUT_DIR,
omitVariableReportData,
removeColorCodes,
teardownTestFolder,
} from '@code-pushup/test-utils';
import { executeProcess, readJsonFile } from '@code-pushup/utils';
Expand Down Expand Up @@ -39,7 +38,7 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => {
'.code-pushup',
);

const { code, stdout } = await executeProcess({
const { code } = await executeProcess({
command: 'npx',
// verbose exposes audits with perfect scores that are hidden in the default stdout
args: [
Expand All @@ -53,16 +52,6 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => {
});

expect(code).toBe(0);
const cleanStdout = removeColorCodes(stdout);

expect(cleanStdout).toMatch(/● Semantic errors\s+\d+ issue/);
expect(cleanStdout).toMatch(/● Configuration errors\s+\d+ issue/);
expect(cleanStdout).toMatch(
/● Declaration and language service errors\s+\d+ issue/,
);
expect(cleanStdout).toMatch(/● Syntax errors\s+\d+ issue/);
expect(cleanStdout).toMatch(/● Internal errors\s+\d+ issue/);
expect(cleanStdout).toMatch(/● No implicit any errors\s+\d+ issue/);

const reportJson = await readJsonFile<Report>(
path.join(envRoot, outputDir, 'report.json'),
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ categories: [
title: 'TypeScript',
refs: [
{
slug: 'language-and-environment',
slug: 'problems',
weight: 1,
type: 'group',
plugin: 'typescript',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`createRunnerFunction > should create valid audit outputs when called 1`] = `
[
{
"details": {
Expand All @@ -14,7 +17,7 @@
},
],
},
"displayValue": "1 issue",
"displayValue": "1 error",
"score": 0,
"slug": "syntax-errors",
"value": 1,
Expand Down Expand Up @@ -75,7 +78,7 @@
},
],
},
"displayValue": "5 issues",
"displayValue": "5 errors",
"score": 0,
"slug": "semantic-errors",
"value": 5,
Expand All @@ -95,33 +98,34 @@
},
],
},
"displayValue": "1 issue",
"displayValue": "1 error",
"score": 0,
"slug": "declaration-and-language-service-errors",
"value": 1,
},
{
"displayValue": "0 issues",
"displayValue": "passed",
"score": 1,
"slug": "internal-errors",
"value": 0,
},
{
"displayValue": "0 issues",
"displayValue": "passed",
"score": 1,
"slug": "configuration-errors",
"value": 0,
},
{
"displayValue": "0 issues",
"displayValue": "passed",
"score": 1,
"slug": "no-implicit-any-errors",
"value": 0,
},
{
"displayValue": "0 issues",
"displayValue": "passed",
"score": 1,
"slug": "unknown-codes",
"value": 0,
},
]
]
`;
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ describe('createRunnerFunction', () => {
'packages/plugin-typescript/mocks/fixtures/basic-setup/tsconfig.all-audits.json',
expectedAudits: getAudits(),
})(() => void 0),
).resolves.toMatchFileSnapshot(
'__snapshots__/runner-function-all-audits.json',
);
).resolves.toMatchSnapshot();
}, 35_000);
});
11 changes: 7 additions & 4 deletions packages/plugin-typescript/src/lib/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
Issue,
RunnerFunction,
} from '@code-pushup/models';
import { pluralize } from '@code-pushup/utils';
import { pluralizeToken } from '@code-pushup/utils';
import type { AuditSlug } from '../types.js';
import {
type DiagnosticsOptions,
Expand Down Expand Up @@ -37,17 +37,20 @@ export function createRunnerFunction(options: RunnerOptions): RunnerFunction {
};
}, {});

return expectedAudits.map(({ slug }) => {
return expectedAudits.map(({ slug }): AuditOutput => {
const { details } = result[slug] ?? {};

const issues = details?.issues ?? [];
return {
slug,
score: issues.length === 0 ? 1 : 0,
value: issues.length,
displayValue: `${issues.length} ${pluralize('issue', issues.length)}`,
displayValue:
issues.length === 0
? 'passed'
: pluralizeToken('error', issues.length),
...(issues.length > 0 ? { details } : {}),
} satisfies AuditOutput;
};
});
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('createRunnerFunction', () => {
slug: 'semantic-errors',
score: 0,
value: 2,
displayValue: '2 issues',
displayValue: '2 errors',
details: {
issues: [
expect.objectContaining({
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-typescript/src/lib/typescript-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export async function typescriptPlugin(
slug: TYPESCRIPT_PLUGIN_SLUG,
packageName: packageJson.name,
version: packageJson.version,
title: 'Typescript',
description: 'Official Code PushUp Typescript plugin.',
title: 'TypeScript',
description: 'Official Code PushUp TypeScript plugin.',
docsUrl: 'https://www.npmjs.com/package/@code-pushup/typescript-plugin/',
icon: 'typescript',
audits: filteredAudits,
Expand Down