Skip to content

Commit 2d57696

Browse files
author
Michael Hladky
committed
refactor: fix lint
1 parent edad4c9 commit 2d57696

29 files changed

+393
-315
lines changed

packages/plugin-bundle-stats/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
},
2424
"type": "module",
2525
"dependencies": {
26-
"@code-pushup/models": "0.69.2",
27-
"@code-pushup/utils": "0.69.2",
28-
"zod": "^3.23.8"
29-
},
30-
"peerDependencies": {
31-
"typescript": ">=4.0.0"
26+
"@code-pushup/models": "0.92.1",
27+
"@code-pushup/utils": "0.92.1",
28+
"minimatch": "^10.0.1",
29+
"vite": "6.3.5"
3230
},
31+
"peerDependencies": {},
3332
"scripts": {},
3433
"devDependencies": {
3534
"@angular/cli": "^20.0.3",

packages/plugin-bundle-stats/project.json

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,10 @@
8181
}
8282
}
8383
},
84-
"build": {
85-
"executor": "@nx/js:tsc",
86-
"outputs": ["{options.outputPath}"],
87-
"options": {
88-
"outputPath": "dist/packages/plugin-bundle-stats",
89-
"main": "packages/plugin-bundle-stats/src/index.ts",
90-
"tsConfig": "packages/plugin-bundle-stats/tsconfig.lib.json",
91-
"assets": ["packages/plugin-bundle-stats/*.md"]
92-
}
93-
},
94-
"lint": {
95-
"executor": "@nx/linter:eslint",
96-
"outputs": ["{options.outputFile}"],
97-
"options": {
98-
"lintFilePatterns": [
99-
"packages/plugin-bundle-stats/**/*.ts",
100-
"packages/plugin-bundle-stats/package.json"
101-
]
102-
}
103-
},
104-
"unit-test": {
105-
"executor": "@nx/vite:test",
106-
"options": {
107-
"configFile": "packages/plugin-bundle-stats/vite.config.unit.ts"
108-
}
109-
},
110-
"integration-test": {
111-
"executor": "@nx/vite:test",
112-
"options": {
113-
"configFile": "packages/plugin-bundle-stats/vite.config.integration.ts"
114-
}
115-
}
84+
"build": {},
85+
"lint": {},
86+
"unit-test": {},
87+
"int-test": {}
11688
},
11789
"tags": ["scope:plugin", "type:feature", "publishable"]
11890
}

packages/plugin-bundle-stats/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { bundleStatsPlugin } from './lib/bundle-stats-plugin';
1+
import { bundleStatsPlugin } from './lib/bundle-stats-plugin.js';
22

33
export type {
44
BundleStatsAuditOptions as BundleStatsOptions,
@@ -7,7 +7,7 @@ export type {
77
export type {
88
GroupingRule,
99
PatternList,
10-
BundleStatsConfig as BundleStatsConfig,
10+
BundleStatsConfig,
1111
} from './lib/runner/types.js';
1212
export type { BlacklistEntry } from './lib/runner/audits/scoring.js';
1313

packages/plugin-bundle-stats/src/lib/normalize.ts

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import type { Audit } from '@code-pushup/models';
2-
import { slugify } from '@code-pushup/utils';
3-
import { formatBytes } from '@code-pushup/utils';
2+
import { formatBytes, slugify } from '@code-pushup/utils';
43
import type { BundleStatsConfig as ExportedBundleStatsConfig } from '../index.js';
54
import type { InsightsTableConfig } from './runner/audits/details/table.js';
6-
import { type DependencyTreeConfig } from './runner/audits/details/tree.js';
5+
import type { DependencyTreeConfig } from './runner/audits/details/tree.js';
76
import type { PenaltyConfig, ScoringConfig } from './runner/audits/scoring.js';
87
import { DEFAULT_PENALTY } from './runner/audits/scoring.js';
98
import type { SelectionConfig } from './runner/audits/selection.js';
@@ -55,8 +54,8 @@ function formatStandardizedIssuesSection(scoring: ScoringConfig): string {
5554
if (penalty.blacklist && penalty.blacklist.length > 0) {
5655
items.push(
5756
` - Error: \`1+\` candidates - Violation detected, requires action`,
57+
` - Info: \`0\` candidates - No violations found`,
5858
);
59-
items.push(` - Info: \`0\` candidates - No violations found`);
6059
} else if (penalty.artefactSize) {
6160
const [, max] = penalty.artefactSize;
6261
items.push(
@@ -110,14 +109,18 @@ function formatStandardizedTreeSection(
110109
let pruningText = 'Default settings';
111110
if (pruning) {
112111
const pruningParts: string[] = [];
113-
if (pruning.minSize)
112+
if (pruning.minSize) {
114113
pruningParts.push(`Min size: \`${formatBytes(pruning.minSize)}\``);
115-
if (pruning.maxChildren)
114+
}
115+
if (pruning.maxChildren) {
116116
pruningParts.push(`Max children: \`${pruning.maxChildren}\``);
117-
if (pruning.maxDepth)
117+
}
118+
if (pruning.maxDepth) {
118119
pruningParts.push(`Max depth: \`${pruning.maxDepth}\``);
119-
if (pruning.pathLength)
120+
}
121+
if (pruning.pathLength) {
120122
pruningParts.push(`Path length: \`${pruning.pathLength}\``);
123+
}
121124

122125
if (pruningParts.length > 0) {
123126
pruningText = pruningParts.join(', ');
@@ -129,8 +132,12 @@ function formatStandardizedTreeSection(
129132
if (groups && groups.length > 0) {
130133
const groupSummaries = groups.map(group => {
131134
const parts: string[] = [];
132-
if (group.title) parts.push(`"${group.title}"`);
133-
if (group.icon) parts.push(`${group.icon}`);
135+
if (group.title) {
136+
parts.push(`"${group.title}"`);
137+
}
138+
if (group.icon) {
139+
parts.push(`${group.icon}`);
140+
}
134141
if (group.includeInputs) {
135142
if (Array.isArray(group.includeInputs)) {
136143
const includePatterns = group.includeInputs
@@ -257,24 +264,34 @@ export function prepareDescription(config: BundleStatsConfig): string {
257264

258265
// Add standardized sections
259266
const scoringSection = formatStandardizedScoringSection(scoring);
260-
if (scoringSection) sections.push(scoringSection);
267+
if (scoringSection) {
268+
sections.push(scoringSection);
269+
}
261270

262271
const issuesSection = formatStandardizedIssuesSection(scoring);
263-
if (issuesSection) sections.push(issuesSection);
272+
if (issuesSection) {
273+
sections.push(issuesSection);
274+
}
264275

265276
const selectionSection = formatStandardizedSelectionSection(selection);
266-
if (selectionSection) sections.push(selectionSection);
277+
if (selectionSection) {
278+
sections.push(selectionSection);
279+
}
267280

268281
// Handle insightsTable which could be false
269282
const normalizedInsightsTable =
270283
insightsTable === false ? undefined : insightsTable;
271284
const tableSection = formatStandardizedTableSection(
272285
normalizedInsightsTable,
273286
);
274-
if (tableSection) sections.push(tableSection);
287+
if (tableSection) {
288+
sections.push(tableSection);
289+
}
275290

276291
const treeSection = formatStandardizedTreeSection(dependencyTree);
277-
if (treeSection) sections.push(treeSection);
292+
if (treeSection) {
293+
sections.push(treeSection);
294+
}
278295

279296
// Wrap config sections in details if any exist
280297
if (sections.length > 0) {
@@ -342,7 +359,7 @@ export function normalizeBundleStatsOptions(
342359
// Use the proper selection normalization helper that merges global patterns
343360
const normalizedSelection = normalizeSelectionOptions(selection);
344361

345-
let normalizedPenalty: false | PenaltyConfig | undefined = undefined;
362+
let normalizedPenalty: false | PenaltyConfig | undefined;
346363
if (penalty && typeof penalty === 'object') {
347364
const { artefactSize, ...restPenalty } = penalty;
348365
normalizedPenalty = {
@@ -413,7 +430,7 @@ export function normalizeDependencyTreeOptions(
413430
maxChildren: 10,
414431
minSize: 1000,
415432
pathLength: 60,
416-
...(options?.pruning ?? {}),
433+
...options?.pruning,
417434
},
418435
mode: options?.mode ?? 'onlyMatching',
419436
};
@@ -451,13 +468,11 @@ export function normalizeRange(range: MinMax | number): MinMax {
451468
}
452469

453470
export function getAuditsFromConfigs(configs: BundleStatsConfig[]): Audit[] {
454-
return configs.map(({ slug, title, description }) => {
455-
return {
456-
slug,
457-
title,
458-
description,
459-
};
460-
});
471+
return configs.map(({ slug, title, description }) => ({
472+
slug,
473+
title,
474+
description,
475+
}));
461476
}
462477

463478
/**

packages/plugin-bundle-stats/src/lib/runner/audits/audit-outputs.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { AuditOutput } from '@code-pushup/models';
22
import type { BundleStatsConfig } from '../types.js';
33
import type { UnifiedStats } from '../unify/unified-stats.types.js';
4-
import { createDisplayValue } from '../utils.js';
5-
import { createEmptyAudit } from '../utils.js';
4+
import { createDisplayValue, createEmptyAudit } from '../utils.js';
65
import { createAuditOutputDetails } from './details/audit-details.js';
76
import { getIssues } from './details/issues.js';
87
import { createBundleStatsScoring } from './scoring.js';

packages/plugin-bundle-stats/src/lib/runner/audits/audit-outputs.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('generateAuditOutputs', () => {
5151
},
5252
scoring: {
5353
mode: 'onlyMatching',
54-
totalSize: [1000, 10000],
54+
totalSize: [1000, 10_000],
5555
},
5656
},
5757
],

packages/plugin-bundle-stats/src/lib/runner/audits/details/formatting.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ import {
44
findSegmentIndex,
55
normalizePathForMatching,
66
splitPathSegments,
7-
} from './grouping';
7+
} from './grouping.js';
88

99
// Regex cache to avoid recreating the same regex patterns
1010
const REGEX_CACHE = new Map<string, RegExp>();
1111

1212
function getCachedRegex(pattern: string): RegExp {
1313
const cached = REGEX_CACHE.get(pattern);
14-
if (cached) return cached;
14+
if (cached) {
15+
return cached;
16+
}
1517

1618
const regex = new RegExp(`${pattern}\\/([^\\/]+)`);
1719
REGEX_CACHE.set(pattern, regex);
@@ -42,9 +44,11 @@ export function extractScopedPackage(
4244
export function extractMeaningfulPathPart(path: string): string | null {
4345
const parts = splitPathSegments(path.replace(/^\.\//, ''));
4446

45-
if (parts.length === 0) return null;
47+
if (parts.length === 0) {
48+
return null;
49+
}
4650

47-
const lastPart = parts[parts.length - 1];
51+
const lastPart = parts.at(-1);
4852
if (lastPart) {
4953
const withoutExt = removeFileExtension(lastPart);
5054
if (withoutExt && !isGenericName(withoutExt)) {
@@ -53,7 +57,7 @@ export function extractMeaningfulPathPart(path: string): string | null {
5357
}
5458

5559
if (parts.length > 1) {
56-
const secondLast = parts[parts.length - 2];
60+
const secondLast = parts.at(-2);
5761
if (secondLast && !isGenericName(secondLast)) {
5862
return secondLast;
5963
}
@@ -71,12 +75,16 @@ export function cleanupGroupName(groupName: string): string {
7175
}
7276

7377
const segments = splitPathSegments(groupName);
74-
if (segments.length === 0) return groupName;
78+
if (segments.length === 0) {
79+
return groupName;
80+
}
7581

7682
// For scoped packages, try to extract the scope and package
7783
for (let i = 0; i < segments.length; i++) {
7884
const segment = segments[i];
79-
if (!segment) continue;
85+
if (!segment) {
86+
continue;
87+
}
8088

8189
// Handle scoped packages like @angular/router
8290
if (segment.startsWith('@') && i + 1 < segments.length) {
@@ -89,7 +97,9 @@ export function cleanupGroupName(groupName: string): string {
8997
// Extract the last meaningful segment (the actual package/folder name)
9098
for (let i = segments.length - 1; i >= 0; i--) {
9199
const segment = segments[i];
92-
if (!segment || isGenericName(segment)) continue;
100+
if (!segment || isGenericName(segment)) {
101+
continue;
102+
}
93103

94104
// Return the first meaningful segment we find from the end
95105
return segment;

0 commit comments

Comments
 (0)