Skip to content

Commit 877aa7d

Browse files
author
Bart Veneman
committed
breaking: update css-analyzer to v6, drops actuals for TooMuchEmbeddedContent
1 parent d1fd649 commit 877aa7d

7 files changed

+69
-34
lines changed

package-lock.json

+58-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"check": "tsc --noEmit"
5252
},
5353
"dependencies": {
54-
"@projectwallace/css-analyzer": "^5.14.0"
54+
"@projectwallace/css-analyzer": "^6.0.0"
5555
},
5656
"devDependencies": {
5757
"typescript": "^5.4.5",

src/complexity.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ export const guards = [
2929
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
3030
result => {
3131
const mode = result.selectors.specificity.mode
32-
const selectorsAboveMode = result.selectors.specificity.items
33-
.filter(c => compareSpecificity(c, mode) < 0)
32+
/** @type {import('@projectwallace/css-analyzer').Specificity[]} */
33+
// @ts-expect-error css-analyzer type is incorrect
34+
const items = result.selectors.specificity.items
35+
const selectorsAboveMode = items.filter(c => compareSpecificity(c, mode) < 0)
3436
.length
3537

3638
const outcome = {
@@ -52,7 +54,7 @@ export const guards = [
5254
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
5355
result => {
5456
const MAX_SELECTOR_COMPLEXITY = 5
55-
const actual = result.selectors.complexity.max
57+
const actual = result.selectors.complexity.max || 0
5658

5759
const outcome = {
5860
id: 'MaxSelectorComplexity',

src/core.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ function calculateScore(result, guards) {
2929
}
3030
}
3131

32-
/**
33-
* @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis
34-
*/
32+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */
3533
export function calculate(analysis) {
3634
const performance = calculateScore(analysis, performanceGuards)
3735
const maintainability = calculateScore(analysis, maintainabilityGuards)

src/index.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Index('smoke test', () => {
7373
"id": "TooMuchEmbeddedContent",
7474
"score": 0,
7575
"value": 0,
76-
"actuals": []
7776
},
7877
{
7978
"id": "SourceLinesOfCode",
@@ -235,7 +234,6 @@ Index('smoke test', () => {
235234
"id": "TooMuchEmbeddedContent",
236235
"score": 0,
237236
"value": 0,
238-
"actuals": []
239237
}
240238
]
241239
},

src/performance.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export const guards = [
3939
const outcome = {
4040
id: 'DeclarationDuplications',
4141
score: 0,
42-
value: 1 - result.declarations.unique.ratio,
42+
value: 1 - result.declarations.uniquenessRatio,
4343
}
4444

45-
if (result.declarations.unique.ratio < 0.66) {
46-
outcome.score = Math.floor((1 - result.declarations.unique.ratio) * 10)
45+
if (result.declarations.uniquenessRatio < 0.66) {
46+
outcome.score = Math.floor((1 - result.declarations.uniquenessRatio) * 10)
4747
}
4848

4949
return outcome
@@ -72,13 +72,12 @@ export const guards = [
7272
// Should not contain too much embedded content
7373
// Deduct 1 point for every 250 bytes
7474
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
75-
result => {
75+
(result) => {
7676
const { size } = result.stylesheet.embeddedContent
7777
return {
7878
id: 'TooMuchEmbeddedContent',
7979
score: Math.min(20, Math.floor(size.total / 250)),
8080
value: size.total,
81-
actuals: Object.keys(result.stylesheet.embeddedContent.unique),
8281
}
8382
},
8483
]

src/performance.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ Performance('deducts points for having embedded content', () => {
186186
id: 'TooMuchEmbeddedContent',
187187
score: 20,
188188
value: 45990,
189-
actuals: Array.from({ length: 100 }).fill('').map((_, index) => generateEmbed(index)),
190189
},
191190
])
192191
})

0 commit comments

Comments
 (0)