Skip to content

Commit 9efce5b

Browse files
authored
breaking: update css-analyzer to v6, drops actuals for TooMuchEmbeddedContent (#29)
closes #28
1 parent d1fd649 commit 9efce5b

File tree

8 files changed

+77
-40
lines changed

8 files changed

+77
-40
lines changed

package-lock.json

Lines changed: 58 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 0 additions & 2 deletions
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/maintainability.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,18 @@ export const guards = [
6565
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
6666
result => {
6767
const MAX_SELECTORS_PER_RULESET = 10
68+
let max = result.rules.selectors.max || 0
6869

6970
const outcome = {
7071
id: 'MaxSelectorsPerRule',
7172
score: 0,
72-
value: result.rules.selectors.max,
73+
value: max,
7374
actuals: result.rules.selectors.items,
7475
}
7576

7677
// Deduct 0.5 points per selectors over 10
77-
if (result.rules.selectors.max > MAX_SELECTORS_PER_RULESET) {
78-
const score = Math.ceil((result.rules.selectors.max - MAX_SELECTORS_PER_RULESET) * 0.5)
78+
if (max > MAX_SELECTORS_PER_RULESET) {
79+
const score = Math.ceil((max - MAX_SELECTORS_PER_RULESET) * 0.5)
7980
outcome.score = Math.min(score, 15)
8081
}
8182

@@ -86,17 +87,18 @@ export const guards = [
8687
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
8788
result => {
8889
const MAX_DECLARATIONS_PER_RULESET = 10
90+
const max = result.rules.declarations.max || 0
8991

9092
const outcome = {
9193
id: 'MaxDeclarationsPerRule',
9294
score: 0,
93-
value: result.rules.declarations.max,
95+
value: max,
9496
actuals: result.rules.declarations.items,
9597
}
9698

9799
// Deduct 0.5 points per declarations over 10
98-
if (result.rules.declarations.max > MAX_DECLARATIONS_PER_RULESET) {
99-
const score = Math.ceil((result.rules.declarations.max - MAX_DECLARATIONS_PER_RULESET) * 0.5)
100+
if (max > MAX_DECLARATIONS_PER_RULESET) {
101+
const score = Math.ceil((max - MAX_DECLARATIONS_PER_RULESET) * 0.5)
100102
outcome.score = Math.min(15, score)
101103
}
102104

src/performance.js

Lines changed: 4 additions & 5 deletions
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

Lines changed: 0 additions & 1 deletion
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)