@projectwallace/css-code-quality 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.d.ts +56 -0
- package/dist/css-code-quality.js +295 -0
- package/dist/css-code-quality.umd.cjs +1 -0
- package/dist/index.d.ts +55 -53
- package/package.json +25 -15
- package/src/complexity.js +6 -0
- package/src/core.js +11 -6
- package/src/index.js +3 -1
- package/src/maintainability.js +8 -1
- package/src/performance.js +7 -0
- package/dist/css-code-quality.cjs +0 -2
- package/dist/css-code-quality.cjs.map +0 -1
- package/dist/css-code-quality.modern.js +0 -2
- package/dist/css-code-quality.modern.js.map +0 -1
- package/dist/css-code-quality.module.js +0 -2
- package/dist/css-code-quality.module.js.map +0 -1
- package/dist/css-code-quality.umd.js +0 -2
- package/dist/css-code-quality.umd.js.map +0 -1
- package/src/complexity.test.js +0 -126
- package/src/core.test.js +0 -11
- package/src/index.test.js +0 -391
- package/src/maintainability.test.js +0 -191
- package/src/performance.test.js +0 -194
package/src/maintainability.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const guards = [
|
|
2
2
|
|
|
3
|
-
// Source Lines of Code should be low
|
|
3
|
+
// Source Lines of Code should be low
|
|
4
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
4
5
|
result => {
|
|
5
6
|
const outcome = {
|
|
6
7
|
id: 'SourceLinesOfCode',
|
|
@@ -18,6 +19,7 @@ export const guards = [
|
|
|
18
19
|
},
|
|
19
20
|
|
|
20
21
|
// Average count of Selectors per RuleSet should be low
|
|
22
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
21
23
|
result => {
|
|
22
24
|
const ALLOWED_SELECTORS_PER_RULESET = 2
|
|
23
25
|
const actual = result.rules.selectors.mean
|
|
@@ -39,6 +41,7 @@ export const guards = [
|
|
|
39
41
|
},
|
|
40
42
|
|
|
41
43
|
// Average count of Declarations per RuleSet should be low
|
|
44
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
42
45
|
result => {
|
|
43
46
|
const ALLOWED_DECLARATIONS_PER_RULESET = 5
|
|
44
47
|
|
|
@@ -59,6 +62,7 @@ export const guards = [
|
|
|
59
62
|
},
|
|
60
63
|
|
|
61
64
|
// Max number of Selectors per Rule should be low
|
|
65
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
62
66
|
result => {
|
|
63
67
|
const MAX_SELECTORS_PER_RULESET = 10
|
|
64
68
|
|
|
@@ -79,6 +83,7 @@ export const guards = [
|
|
|
79
83
|
},
|
|
80
84
|
|
|
81
85
|
// Max number of Declarations per Rule should be low
|
|
86
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
82
87
|
result => {
|
|
83
88
|
const MAX_DECLARATIONS_PER_RULESET = 10
|
|
84
89
|
|
|
@@ -100,6 +105,7 @@ export const guards = [
|
|
|
100
105
|
|
|
101
106
|
// Number of Selectors per RuleSet should not differ too much from the most common amount of
|
|
102
107
|
// Selectors per RuleSet
|
|
108
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
103
109
|
result => {
|
|
104
110
|
const mode = result.rules.selectors.mode
|
|
105
111
|
const rulesHavingMoreThanMode = result.rules.selectors.items
|
|
@@ -126,6 +132,7 @@ export const guards = [
|
|
|
126
132
|
|
|
127
133
|
// Number of Declarations per RuleSet should not differ too much from the most common amount of
|
|
128
134
|
// Declarations per RuleSet
|
|
135
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
129
136
|
result => {
|
|
130
137
|
const mode = result.rules.selectors.mode
|
|
131
138
|
const rulesHavingMoreThanMode = result.rules.declarations.items.filter(item => item > mode).length
|
package/src/performance.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const guards = [
|
|
2
2
|
|
|
3
3
|
// Should not contain @import rules
|
|
4
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
4
5
|
result => ({
|
|
5
6
|
id: 'Imports',
|
|
6
7
|
score: result.atrules.import.total * 10,
|
|
@@ -9,6 +10,7 @@ export const guards = [
|
|
|
9
10
|
}),
|
|
10
11
|
|
|
11
12
|
// Should not contain empty rules
|
|
13
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
12
14
|
result => ({
|
|
13
15
|
id: 'EmptyRules',
|
|
14
16
|
score: result.rules.empty.total,
|
|
@@ -16,6 +18,7 @@ export const guards = [
|
|
|
16
18
|
}),
|
|
17
19
|
|
|
18
20
|
// Too many selectors appear multiple times
|
|
21
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
19
22
|
result => {
|
|
20
23
|
const outcome = {
|
|
21
24
|
id: 'SelectorDuplications',
|
|
@@ -31,6 +34,7 @@ export const guards = [
|
|
|
31
34
|
},
|
|
32
35
|
|
|
33
36
|
// Too many declarations appear multiple times
|
|
37
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
34
38
|
result => {
|
|
35
39
|
const outcome = {
|
|
36
40
|
id: 'DeclarationDuplications',
|
|
@@ -46,6 +50,7 @@ export const guards = [
|
|
|
46
50
|
},
|
|
47
51
|
|
|
48
52
|
// The total amount of CSS should not be too high
|
|
53
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
49
54
|
result => ({
|
|
50
55
|
id: 'CssSize',
|
|
51
56
|
score: result.stylesheet.size > 200_000 ? 5 : 0,
|
|
@@ -54,6 +59,7 @@ export const guards = [
|
|
|
54
59
|
|
|
55
60
|
// Should not contain (too much) comments
|
|
56
61
|
// Deduct 1 point for every 250 bytes
|
|
62
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
57
63
|
result => {
|
|
58
64
|
const { comments } = result.stylesheet
|
|
59
65
|
return {
|
|
@@ -65,6 +71,7 @@ export const guards = [
|
|
|
65
71
|
|
|
66
72
|
// Should not contain too much embedded content
|
|
67
73
|
// Deduct 1 point for every 250 bytes
|
|
74
|
+
/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} result */
|
|
68
75
|
result => {
|
|
69
76
|
const { size } = result.stylesheet.embeddedContent
|
|
70
77
|
return {
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
var e=require("@projectwallace/css-analyzer");function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o}var r=[function(e){return{id:"Imports",score:10*e.atrules.import.total,value:e.atrules.import.total,actuals:Object.keys(e.atrules.import.unique)}},function(e){return{id:"EmptyRules",score:e.rules.empty.total,value:e.rules.empty.total}},function(e){var t={id:"SelectorDuplications",score:0,value:1-e.selectors.uniquenessRatio};return e.selectors.uniquenessRatio<.66&&(t.score=Math.floor(10*(1-e.selectors.uniquenessRatio))),t},function(e){var t={id:"DeclarationDuplications",score:0,value:1-e.declarations.unique.ratio};return e.declarations.unique.ratio<.66&&(t.score=Math.floor(10*(1-e.declarations.unique.ratio))),t},function(e){return{id:"CssSize",score:e.stylesheet.size>2e5?5:0,value:e.stylesheet.size}},function(e){var t=e.stylesheet.comments;return{id:"TooMuchComments",score:Math.min(10,Math.floor(t.size/250)),value:t.size}},function(e){var t=e.stylesheet.embeddedContent.size;return{id:"TooMuchEmbeddedContent",score:Math.min(20,Math.floor(t.total/250)),value:t.total,actuals:Object.keys(e.stylesheet.embeddedContent.unique)}}],o=[function(e){var t={id:"SourceLinesOfCode",score:0,value:e.stylesheet.sourceLinesOfCode};if(e.stylesheet.sourceLinesOfCode>1e4){var r=Math.floor((e.stylesheet.sourceLinesOfCode-1e4)/1e3);t.score=Math.min(15,r)}return t},function(e){var t=e.rules.selectors.mean,r={id:"AverageSelectorsPerRule",score:0,value:t,actuals:e.rules.selectors.items};if(t>2){var o=Math.floor(5*(t-2));r.score=Math.min(15,o)}return r},function(e){var t={id:"AverageDeclarationsPerRule",score:0,value:e.rules.declarations.mean,actuals:e.rules.declarations.items};if(e.rules.declarations.mean>5){var r=Math.floor(5*(e.rules.declarations.mean-5));t.score=Math.min(15,r)}return t},function(e){var t={id:"MaxSelectorsPerRule",score:0,value:e.rules.selectors.max,actuals:e.rules.selectors.items};if(e.rules.selectors.max>10){var r=Math.ceil(.5*(e.rules.selectors.max-10));t.score=Math.min(r,15)}return t},function(e){var t={id:"MaxDeclarationsPerRule",score:0,value:e.rules.declarations.max,actuals:e.rules.declarations.items};if(e.rules.declarations.max>10){var r=Math.ceil(.5*(e.rules.declarations.max-10));t.score=Math.min(15,r)}return t},function(e){var t=e.rules.selectors.mode,r=e.rules.selectors.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonSelectorsPerRule",score:0,value:e.rules.selectors.mode,actuals:e.rules.selectors.items};if(r>.1*e.rules.total){var s=Math.floor(.01*r);o.score=Math.min(15,s)}return o},function(e){var t=e.rules.selectors.mode,r=e.rules.declarations.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonDeclarationsPerRule",score:0,value:e.rules.declarations.mode,actuals:e.rules.declarations.items};if(r>.1*e.rules.total){var s=Math.floor(.01*r);o.score=Math.min(15,s)}return o}],s=[function(e){var t=e.selectors.complexity.mode,r=e.selectors.complexity.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonSelectorComplexity",score:0,value:0===e.selectors.total?0:r/e.selectors.total,actuals:e.selectors.complexity.items};if(r>.1*e.selectors.total){var s=Math.floor(.01*r);o.score=Math.min(10,s)}return o},function(t){var r=t.selectors.specificity.mode,o=t.selectors.specificity.items.filter(function(t){return e.compareSpecificity(t,r)<0}).length,s={id:"MoreThanMostCommonSelectorSpecificity",score:0,value:0===t.selectors.total?0:o/t.selectors.total,actuals:t.selectors.specificity.items};if(o>.1*t.selectors.total){var a=Math.floor(.01*o);s.score=Math.min(10,a)}return s},function(e){var t=e.selectors.complexity.max,r={id:"MaxSelectorComplexity",score:0,value:e.selectors.complexity.max,actuals:e.selectors.complexity.items};if(t>5){var o=Math.ceil(.5*(t-5));r.score=Math.min(5,o)}return r},function(e){var t=e.selectors.complexity.mean,r={id:"AverageSelectorComplexity",score:0,value:t,actuals:e.selectors.complexity.items};if(t>2){var o=Math.ceil(2*(t-2));r.score=Math.min(10,o)}return r},function(e){var t=e.selectors.id.ratio,r={id:"IdSelectorRatio",score:0,value:t,actuals:Object.keys(e.selectors.id.unique)};if(t>.01){var o=Math.floor(10*(t-.01));r.score=Math.min(o,5)}return r},function(e){var t=e.declarations.importants.ratio,r={id:"ImportantRatio",score:0,value:t,actuals:e.declarations.importants.total};if(t>.01){var o=Math.floor(10*(t-.01));r.score=Math.min(o,5)}return r}];function a(e){for(var r,o=e.result,s=100,a=[],l=[],i=function(e,r){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return(o=o.call(e)).next.bind(o);if(Array.isArray(e)||(o=function(e,r){if(e){if("string"==typeof e)return t(e,r);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?t(e,r):void 0}}(e))){o&&(e=o);var s=0;return function(){return s>=e.length?{done:!0}:{done:!1,value:e[s++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.guards);!(r=i()).done;){var n=(0,r.value)(o);n.score>0?(s-=n.score,a.push(n)):l.push(n)}return{score:Math.max(s,0),violations:a,passes:l}}exports.calculate=function(t){return i=a({result:l=e.analyze(t),guards:r}),n=a({result:l,guards:o}),c=a({result:l,guards:s}),{score:0,violations:i.violations.concat(n.violations).concat(c.violations),passes:i.passes.concat(n.passes).concat(c.passes),performance:i,maintainability:n,complexity:c};var l,i,n,c};
|
|
2
|
-
//# sourceMappingURL=css-code-quality.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"css-code-quality.cjs","sources":["../src/performance.js","../src/maintainability.js","../src/complexity.js","../src/core.js","../src/index.js"],"sourcesContent":["export const guards = [\n\n // Should not contain @import rules\n result => ({\n id: 'Imports',\n score: result.atrules.import.total * 10,\n value: result.atrules.import.total,\n actuals: Object.keys(result.atrules.import.unique),\n }),\n\n // Should not contain empty rules\n result => ({\n id: 'EmptyRules',\n score: result.rules.empty.total,\n value: result.rules.empty.total,\n }),\n\n // Too many selectors appear multiple times\n result => {\n const outcome = {\n id: 'SelectorDuplications',\n score: 0,\n value: 1 - result.selectors.uniquenessRatio,\n }\n\n if (result.selectors.uniquenessRatio < 0.66) {\n outcome.score = Math.floor((1 - result.selectors.uniquenessRatio) * 10)\n }\n\n return outcome\n },\n\n // Too many declarations appear multiple times\n result => {\n const outcome = {\n id: 'DeclarationDuplications',\n score: 0,\n value: 1 - result.declarations.unique.ratio,\n }\n\n if (result.declarations.unique.ratio < 0.66) {\n outcome.score = Math.floor((1 - result.declarations.unique.ratio) * 10)\n }\n\n return outcome\n },\n\n // The total amount of CSS should not be too high\n result => ({\n id: 'CssSize',\n score: result.stylesheet.size > 200_000 ? 5 : 0,\n value: result.stylesheet.size,\n }),\n\n // Should not contain (too much) comments\n // Deduct 1 point for every 250 bytes\n result => {\n const { comments } = result.stylesheet\n return {\n id: 'TooMuchComments',\n score: Math.min(10, Math.floor(comments.size / 250)),\n value: comments.size,\n }\n },\n\n // Should not contain too much embedded content\n // Deduct 1 point for every 250 bytes\n result => {\n const { size } = result.stylesheet.embeddedContent\n return {\n id: 'TooMuchEmbeddedContent',\n score: Math.min(20, Math.floor(size.total / 250)),\n value: size.total,\n actuals: Object.keys(result.stylesheet.embeddedContent.unique),\n }\n },\n]\n","export const guards = [\n\n // Source Lines of Code should be low'\n result => {\n const outcome = {\n id: 'SourceLinesOfCode',\n score: 0,\n value: result.stylesheet.sourceLinesOfCode,\n }\n\n if (result.stylesheet.sourceLinesOfCode > 10000) {\n // deduct 1 point per 1000 lines of code over 10,000\n const score = Math.floor((result.stylesheet.sourceLinesOfCode - 10000) / 1000)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Selectors per RuleSet should be low\n result => {\n const ALLOWED_SELECTORS_PER_RULESET = 2\n const actual = result.rules.selectors.mean\n\n const outcome = {\n id: 'AverageSelectorsPerRule',\n score: 0,\n value: actual,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 5 points per selector over 2\n if (actual > ALLOWED_SELECTORS_PER_RULESET) {\n const score = Math.floor((actual - ALLOWED_SELECTORS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Declarations per RuleSet should be low\n result => {\n const ALLOWED_DECLARATIONS_PER_RULESET = 5\n\n const outcome = {\n id: 'AverageDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mean,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 5 points per declaration over 5\n if (result.rules.declarations.mean > ALLOWED_DECLARATIONS_PER_RULESET) {\n const score = Math.floor((result.rules.declarations.mean - ALLOWED_DECLARATIONS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Max number of Selectors per Rule should be low\n result => {\n const MAX_SELECTORS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.max,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 0.5 points per selectors over 10\n if (result.rules.selectors.max > MAX_SELECTORS_PER_RULESET) {\n const score = Math.ceil((result.rules.selectors.max - MAX_SELECTORS_PER_RULESET) * 0.5)\n outcome.score = Math.min(score, 15)\n }\n\n return outcome\n },\n\n // Max number of Declarations per Rule should be low\n result => {\n const MAX_DECLARATIONS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.max,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 0.5 points per declarations over 10\n if (result.rules.declarations.max > MAX_DECLARATIONS_PER_RULESET) {\n const score = Math.ceil((result.rules.declarations.max - MAX_DECLARATIONS_PER_RULESET) * 0.5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Selectors per RuleSet should not differ too much from the most common amount of\n // Selectors per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.selectors.items\n .filter(item => item > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.mode,\n actuals: result.rules.selectors.items,\n }\n\n // if more than 10% of RuleSets has more Selectors than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Declarations per RuleSet should not differ too much from the most common amount of\n // Declarations per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.declarations.items.filter(item => item > mode).length\n\n const outcome = {\n id: 'MoreThanMostCommonDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mode,\n actuals: result.rules.declarations.items,\n }\n\n // if more than 10% of RuleSets has more Declarations than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n]\n","import { compareSpecificity } from '@projectwallace/css-analyzer'\n\nexport const guards = [\n\n // Complexity per Selector should not differ too much from the most common Complexity\n result => {\n const mode = result.selectors.complexity.mode\n const selectorsAboveMode = result.selectors.complexity.items\n .filter(c => c > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorComplexity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.complexity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Specificity per Selector should not differ too much from the most common Specificity\n result => {\n const mode = result.selectors.specificity.mode\n const selectorsAboveMode = result.selectors.specificity.items\n .filter(c => compareSpecificity(c, mode) < 0)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorSpecificity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.specificity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Maximum Selector Complexity should be low\n result => {\n const MAX_SELECTOR_COMPLEXITY = 5\n const actual = result.selectors.complexity.max\n\n const outcome = {\n id: 'MaxSelectorComplexity',\n score: 0,\n value: result.selectors.complexity.max,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 0.5 points per complexity over 5, up to 5 points\n if (actual > MAX_SELECTOR_COMPLEXITY) {\n const score = Math.ceil((actual - MAX_SELECTOR_COMPLEXITY) * 0.5)\n outcome.score = Math.min(5, score)\n }\n\n return outcome\n },\n\n // Average Selector Complexity should be low\n result => {\n const ALLOWED_COMPLEXITY = 2\n const actual = result.selectors.complexity.mean\n\n const outcome = {\n id: 'AverageSelectorComplexity',\n score: 0,\n value: actual,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 2 points per selector over 2\n if (actual > ALLOWED_COMPLEXITY) {\n const score = Math.ceil((actual - ALLOWED_COMPLEXITY) * 2)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.selectors.id.ratio\n const outcome = {\n id: 'IdSelectorRatio',\n score: 0,\n value: actual,\n actuals: Object.keys(result.selectors.id.unique)\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.declarations.importants.ratio\n const outcome = {\n id: 'ImportantRatio',\n score: 0,\n value: actual,\n actuals: result.declarations.importants.total,\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n]\n","import { guards as performanceGuards } from './performance.js'\nimport { guards as maintainabilityGuards } from './maintainability.js'\nimport { guards as complexityGuards } from './complexity.js'\n\nfunction calculateScore({ result, guards }) {\n\tlet score = 100\n\tlet violations = []\n\tlet passes = []\n\n\tfor (const guard of guards) {\n\t\t/** @type {{score: number, value: number, id: string}} */\n\t\tconst outcome = guard(result)\n\n\t\tif (outcome.score > 0) {\n\t\t\tscore -= outcome.score\n\t\t\tviolations.push(outcome)\n\t\t} else {\n\t\t\tpasses.push(outcome)\n\t\t}\n\t}\n\n\treturn {\n\t\tscore: Math.max(score, 0),\n\t\tviolations,\n\t\tpasses,\n\t}\n}\n\n/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */\nexport function calculate(analysis) {\n\tconst performance = calculateScore({ result: analysis, guards: performanceGuards })\n\tconst maintainability = calculateScore({ result: analysis, guards: maintainabilityGuards })\n\tconst complexity = calculateScore({ result: analysis, guards: complexityGuards })\n\n\treturn {\n\t\t/** @deprecated */\n\t\tscore: 0,\n\t\tviolations: performance.violations\n\t\t\t.concat(maintainability.violations)\n\t\t\t.concat(complexity.violations),\n\t\tpasses: performance.passes\n\t\t\t.concat(maintainability.passes)\n\t\t\t.concat(complexity.passes),\n\t\tperformance,\n\t\tmaintainability,\n\t\tcomplexity,\n\t}\n}\n","import { analyze } from '@projectwallace/css-analyzer'\nimport { calculate as calculateFromAnalysis } from './core.js'\n\n/** @param {string} css */\nexport function calculate(css) {\n\tconst analysis = analyze(css)\n\treturn calculateFromAnalysis(analysis)\n}\n"],"names":["guards","result","id","score","atrules","total","value","actuals","Object","keys","unique","rules","empty","outcome","selectors","uniquenessRatio","Math","floor","declarations","ratio","stylesheet","size","comments","min","embeddedContent","sourceLinesOfCode","actual","mean","items","max","ceil","mode","rulesHavingMoreThanMode","filter","item","length","complexity","selectorsAboveMode","c","specificity","compareSpecificity","importants","calculateScore","_ref","_step","violations","passes","_iterator","_createForOfIteratorHelperLoose","done","guard","push","css","performance","analysis","analyze","performanceGuards","maintainability","maintainabilityGuards","complexityGuards","concat"],"mappings":"4JAAaA,EAAS,CAGpB,SAAAC,SAAW,CACTC,GAAI,UACJC,MAAqC,GAA9BF,EAAOG,eAAeC,MAC7BC,MAAOL,EAAOG,eAAeC,MAC7BE,QAASC,OAAOC,KAAKR,EAAOG,eAAeM,QAC5C,EAGD,SAAAT,SAAW,CACTC,GAAI,aACJC,MAAOF,EAAOU,MAAMC,MAAMP,MAC1BC,MAAOL,EAAOU,MAAMC,MAAMP,MAC3B,EAGD,SAAAJ,GACE,IAAMY,EAAU,CACdX,GAAI,uBACJC,MAAO,EACPG,MAAO,EAAIL,EAAOa,UAAUC,iBAO9B,OAJId,EAAOa,UAAUC,gBAAkB,MACrCF,EAAQV,MAAQa,KAAKC,MAA+C,IAAxC,EAAIhB,EAAOa,UAAUC,mBAG5CF,CACT,EAGA,SAAAZ,GACE,IAAMY,EAAU,CACdX,GAAI,0BACJC,MAAO,EACPG,MAAO,EAAIL,EAAOiB,aAAaR,OAAOS,OAOxC,OAJIlB,EAAOiB,aAAaR,OAAOS,MAAQ,MACrCN,EAAQV,MAAQa,KAAKC,MAA+C,IAAxC,EAAIhB,EAAOiB,aAAaR,OAAOS,SAGtDN,CACT,EAGA,SAAAZ,SAAW,CACTC,GAAI,UACJC,MAAOF,EAAOmB,WAAWC,KAAO,IAAU,EAAI,EAC9Cf,MAAOL,EAAOmB,WAAWC,KAC1B,EAID,SAAApB,GACE,IAAQqB,EAAarB,EAAOmB,WAApBE,SACR,MAAO,CACLpB,GAAI,kBACJ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EAAM0C,EAAN1C,OACrBE,EAAQ,IACR0C,EAAa,GACbC,EAAS,GAEbC,2qBAAAC,CALuCL,EAAN3C,UAKP4C,EAAAG,KAAAE,MAAE,KAErBpC,GAAUqC,EAFDN,EAAAtC,OAEOL,GAElBY,EAAQV,MAAQ,GACnBA,GAASU,EAAQV,MACjB0C,EAAWM,KAAKtC,IAEhBiC,EAAOK,KAAKtC,EAEd,CAEA,MAAO,CACNV,MAAOa,KAAKa,IAAI1B,EAAO,GACvB0C,WAAAA,EACAC,OAAAA,EAEF,4BCtB0BM,GAEzB,ODwBMC,EAAcX,EAAe,CAAEzC,OADZqD,ECxBRC,UAAQH,GDyB8BpD,OAAQwD,IACzDC,EAAkBf,EAAe,CAAEzC,OAAQqD,EAAUtD,OAAQ0D,IAC7DtB,EAAaM,EAAe,CAAEzC,OAAQqD,EAAUtD,OAAQ2D,IAEvD,CAENxD,MAAO,EACP0C,WAAYQ,EAAYR,WACtBe,OAAOH,EAAgBZ,YACvBe,OAAOxB,EAAWS,YACpBC,OAAQO,EAAYP,OAClBc,OAAOH,EAAgBX,QACvBc,OAAOxB,EAAWU,QACpBO,YAAAA,EACAI,gBAAAA,EACArB,WAAAA,OAhBwBkB,EACnBD,EACAI,EACArB,CCzBP"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{compareSpecificity as e,analyze as t}from"@projectwallace/css-analyzer";const s=[e=>({id:"Imports",score:10*e.atrules.import.total,value:e.atrules.import.total,actuals:Object.keys(e.atrules.import.unique)}),e=>({id:"EmptyRules",score:e.rules.empty.total,value:e.rules.empty.total}),e=>{const t={id:"SelectorDuplications",score:0,value:1-e.selectors.uniquenessRatio};return e.selectors.uniquenessRatio<.66&&(t.score=Math.floor(10*(1-e.selectors.uniquenessRatio))),t},e=>{const t={id:"DeclarationDuplications",score:0,value:1-e.declarations.unique.ratio};return e.declarations.unique.ratio<.66&&(t.score=Math.floor(10*(1-e.declarations.unique.ratio))),t},e=>({id:"CssSize",score:e.stylesheet.size>2e5?5:0,value:e.stylesheet.size}),e=>{const{comments:t}=e.stylesheet;return{id:"TooMuchComments",score:Math.min(10,Math.floor(t.size/250)),value:t.size}},e=>{const{size:t}=e.stylesheet.embeddedContent;return{id:"TooMuchEmbeddedContent",score:Math.min(20,Math.floor(t.total/250)),value:t.total,actuals:Object.keys(e.stylesheet.embeddedContent.unique)}}],o=[e=>{const t={id:"SourceLinesOfCode",score:0,value:e.stylesheet.sourceLinesOfCode};if(e.stylesheet.sourceLinesOfCode>1e4){const s=Math.floor((e.stylesheet.sourceLinesOfCode-1e4)/1e3);t.score=Math.min(15,s)}return t},e=>{const t=e.rules.selectors.mean,s={id:"AverageSelectorsPerRule",score:0,value:t,actuals:e.rules.selectors.items};if(t>2){const e=Math.floor(5*(t-2));s.score=Math.min(15,e)}return s},e=>{const t={id:"AverageDeclarationsPerRule",score:0,value:e.rules.declarations.mean,actuals:e.rules.declarations.items};if(e.rules.declarations.mean>5){const s=Math.floor(5*(e.rules.declarations.mean-5));t.score=Math.min(15,s)}return t},e=>{const t={id:"MaxSelectorsPerRule",score:0,value:e.rules.selectors.max,actuals:e.rules.selectors.items};if(e.rules.selectors.max>10){const s=Math.ceil(.5*(e.rules.selectors.max-10));t.score=Math.min(s,15)}return t},e=>{const t={id:"MaxDeclarationsPerRule",score:0,value:e.rules.declarations.max,actuals:e.rules.declarations.items};if(e.rules.declarations.max>10){const s=Math.ceil(.5*(e.rules.declarations.max-10));t.score=Math.min(15,s)}return t},e=>{const t=e.rules.selectors.mode,s=e.rules.selectors.items.filter(e=>e>t).length,o={id:"MoreThanMostCommonSelectorsPerRule",score:0,value:e.rules.selectors.mode,actuals:e.rules.selectors.items};if(s>.1*e.rules.total){const e=Math.floor(.01*s);o.score=Math.min(15,e)}return o},e=>{const t=e.rules.selectors.mode,s=e.rules.declarations.items.filter(e=>e>t).length,o={id:"MoreThanMostCommonDeclarationsPerRule",score:0,value:e.rules.declarations.mode,actuals:e.rules.declarations.items};if(s>.1*e.rules.total){const e=Math.floor(.01*s);o.score=Math.min(15,e)}return o}],r=[e=>{const t=e.selectors.complexity.mode,s=e.selectors.complexity.items.filter(e=>e>t).length,o={id:"MoreThanMostCommonSelectorComplexity",score:0,value:0===e.selectors.total?0:s/e.selectors.total,actuals:e.selectors.complexity.items};if(s>.1*e.selectors.total){const e=Math.floor(.01*s);o.score=Math.min(10,e)}return o},t=>{const s=t.selectors.specificity.mode,o=t.selectors.specificity.items.filter(t=>e(t,s)<0).length,r={id:"MoreThanMostCommonSelectorSpecificity",score:0,value:0===t.selectors.total?0:o/t.selectors.total,actuals:t.selectors.specificity.items};if(o>.1*t.selectors.total){const e=Math.floor(.01*o);r.score=Math.min(10,e)}return r},e=>{const t=e.selectors.complexity.max,s={id:"MaxSelectorComplexity",score:0,value:e.selectors.complexity.max,actuals:e.selectors.complexity.items};if(t>5){const e=Math.ceil(.5*(t-5));s.score=Math.min(5,e)}return s},e=>{const t=e.selectors.complexity.mean,s={id:"AverageSelectorComplexity",score:0,value:t,actuals:e.selectors.complexity.items};if(t>2){const e=Math.ceil(2*(t-2));s.score=Math.min(10,e)}return s},e=>{const t=e.selectors.id.ratio,s={id:"IdSelectorRatio",score:0,value:t,actuals:Object.keys(e.selectors.id.unique)};if(t>.01){const e=Math.floor(10*(t-.01));s.score=Math.min(e,5)}return s},e=>{const t=e.declarations.importants.ratio,s={id:"ImportantRatio",score:0,value:t,actuals:e.declarations.importants.total};if(t>.01){const e=Math.floor(10*(t-.01));s.score=Math.min(e,5)}return s}];function l({result:e,guards:t}){let s=100,o=[],r=[];for(const l of t){const t=l(e);t.score>0?(s-=t.score,o.push(t)):r.push(t)}return{score:Math.max(s,0),violations:o,passes:r}}function a(e){return function(e){const t=l({result:e,guards:s}),a=l({result:e,guards:o}),c=l({result:e,guards:r});return{score:0,violations:t.violations.concat(a.violations).concat(c.violations),passes:t.passes.concat(a.passes).concat(c.passes),performance:t,maintainability:a,complexity:c}}(t(e))}export{a as calculate};
|
|
2
|
-
//# sourceMappingURL=css-code-quality.modern.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"css-code-quality.modern.js","sources":["../src/performance.js","../src/maintainability.js","../src/complexity.js","../src/core.js","../src/index.js"],"sourcesContent":["export const guards = [\n\n // Should not contain @import rules\n result => ({\n id: 'Imports',\n score: result.atrules.import.total * 10,\n value: result.atrules.import.total,\n actuals: Object.keys(result.atrules.import.unique),\n }),\n\n // Should not contain empty rules\n result => ({\n id: 'EmptyRules',\n score: result.rules.empty.total,\n value: result.rules.empty.total,\n }),\n\n // Too many selectors appear multiple times\n result => {\n const outcome = {\n id: 'SelectorDuplications',\n score: 0,\n value: 1 - result.selectors.uniquenessRatio,\n }\n\n if (result.selectors.uniquenessRatio < 0.66) {\n outcome.score = Math.floor((1 - result.selectors.uniquenessRatio) * 10)\n }\n\n return outcome\n },\n\n // Too many declarations appear multiple times\n result => {\n const outcome = {\n id: 'DeclarationDuplications',\n score: 0,\n value: 1 - result.declarations.unique.ratio,\n }\n\n if (result.declarations.unique.ratio < 0.66) {\n outcome.score = Math.floor((1 - result.declarations.unique.ratio) * 10)\n }\n\n return outcome\n },\n\n // The total amount of CSS should not be too high\n result => ({\n id: 'CssSize',\n score: result.stylesheet.size > 200_000 ? 5 : 0,\n value: result.stylesheet.size,\n }),\n\n // Should not contain (too much) comments\n // Deduct 1 point for every 250 bytes\n result => {\n const { comments } = result.stylesheet\n return {\n id: 'TooMuchComments',\n score: Math.min(10, Math.floor(comments.size / 250)),\n value: comments.size,\n }\n },\n\n // Should not contain too much embedded content\n // Deduct 1 point for every 250 bytes\n result => {\n const { size } = result.stylesheet.embeddedContent\n return {\n id: 'TooMuchEmbeddedContent',\n score: Math.min(20, Math.floor(size.total / 250)),\n value: size.total,\n actuals: Object.keys(result.stylesheet.embeddedContent.unique),\n }\n },\n]\n","export const guards = [\n\n // Source Lines of Code should be low'\n result => {\n const outcome = {\n id: 'SourceLinesOfCode',\n score: 0,\n value: result.stylesheet.sourceLinesOfCode,\n }\n\n if (result.stylesheet.sourceLinesOfCode > 10000) {\n // deduct 1 point per 1000 lines of code over 10,000\n const score = Math.floor((result.stylesheet.sourceLinesOfCode - 10000) / 1000)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Selectors per RuleSet should be low\n result => {\n const ALLOWED_SELECTORS_PER_RULESET = 2\n const actual = result.rules.selectors.mean\n\n const outcome = {\n id: 'AverageSelectorsPerRule',\n score: 0,\n value: actual,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 5 points per selector over 2\n if (actual > ALLOWED_SELECTORS_PER_RULESET) {\n const score = Math.floor((actual - ALLOWED_SELECTORS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Declarations per RuleSet should be low\n result => {\n const ALLOWED_DECLARATIONS_PER_RULESET = 5\n\n const outcome = {\n id: 'AverageDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mean,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 5 points per declaration over 5\n if (result.rules.declarations.mean > ALLOWED_DECLARATIONS_PER_RULESET) {\n const score = Math.floor((result.rules.declarations.mean - ALLOWED_DECLARATIONS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Max number of Selectors per Rule should be low\n result => {\n const MAX_SELECTORS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.max,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 0.5 points per selectors over 10\n if (result.rules.selectors.max > MAX_SELECTORS_PER_RULESET) {\n const score = Math.ceil((result.rules.selectors.max - MAX_SELECTORS_PER_RULESET) * 0.5)\n outcome.score = Math.min(score, 15)\n }\n\n return outcome\n },\n\n // Max number of Declarations per Rule should be low\n result => {\n const MAX_DECLARATIONS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.max,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 0.5 points per declarations over 10\n if (result.rules.declarations.max > MAX_DECLARATIONS_PER_RULESET) {\n const score = Math.ceil((result.rules.declarations.max - MAX_DECLARATIONS_PER_RULESET) * 0.5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Selectors per RuleSet should not differ too much from the most common amount of\n // Selectors per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.selectors.items\n .filter(item => item > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.mode,\n actuals: result.rules.selectors.items,\n }\n\n // if more than 10% of RuleSets has more Selectors than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Declarations per RuleSet should not differ too much from the most common amount of\n // Declarations per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.declarations.items.filter(item => item > mode).length\n\n const outcome = {\n id: 'MoreThanMostCommonDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mode,\n actuals: result.rules.declarations.items,\n }\n\n // if more than 10% of RuleSets has more Declarations than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n]\n","import { compareSpecificity } from '@projectwallace/css-analyzer'\n\nexport const guards = [\n\n // Complexity per Selector should not differ too much from the most common Complexity\n result => {\n const mode = result.selectors.complexity.mode\n const selectorsAboveMode = result.selectors.complexity.items\n .filter(c => c > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorComplexity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.complexity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Specificity per Selector should not differ too much from the most common Specificity\n result => {\n const mode = result.selectors.specificity.mode\n const selectorsAboveMode = result.selectors.specificity.items\n .filter(c => compareSpecificity(c, mode) < 0)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorSpecificity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.specificity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Maximum Selector Complexity should be low\n result => {\n const MAX_SELECTOR_COMPLEXITY = 5\n const actual = result.selectors.complexity.max\n\n const outcome = {\n id: 'MaxSelectorComplexity',\n score: 0,\n value: result.selectors.complexity.max,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 0.5 points per complexity over 5, up to 5 points\n if (actual > MAX_SELECTOR_COMPLEXITY) {\n const score = Math.ceil((actual - MAX_SELECTOR_COMPLEXITY) * 0.5)\n outcome.score = Math.min(5, score)\n }\n\n return outcome\n },\n\n // Average Selector Complexity should be low\n result => {\n const ALLOWED_COMPLEXITY = 2\n const actual = result.selectors.complexity.mean\n\n const outcome = {\n id: 'AverageSelectorComplexity',\n score: 0,\n value: actual,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 2 points per selector over 2\n if (actual > ALLOWED_COMPLEXITY) {\n const score = Math.ceil((actual - ALLOWED_COMPLEXITY) * 2)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.selectors.id.ratio\n const outcome = {\n id: 'IdSelectorRatio',\n score: 0,\n value: actual,\n actuals: Object.keys(result.selectors.id.unique)\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.declarations.importants.ratio\n const outcome = {\n id: 'ImportantRatio',\n score: 0,\n value: actual,\n actuals: result.declarations.importants.total,\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n]\n","import { guards as performanceGuards } from './performance.js'\nimport { guards as maintainabilityGuards } from './maintainability.js'\nimport { guards as complexityGuards } from './complexity.js'\n\nfunction calculateScore({ result, guards }) {\n\tlet score = 100\n\tlet violations = []\n\tlet passes = []\n\n\tfor (const guard of guards) {\n\t\t/** @type {{score: number, value: number, id: string}} */\n\t\tconst outcome = guard(result)\n\n\t\tif (outcome.score > 0) {\n\t\t\tscore -= outcome.score\n\t\t\tviolations.push(outcome)\n\t\t} else {\n\t\t\tpasses.push(outcome)\n\t\t}\n\t}\n\n\treturn {\n\t\tscore: Math.max(score, 0),\n\t\tviolations,\n\t\tpasses,\n\t}\n}\n\n/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */\nexport function calculate(analysis) {\n\tconst performance = calculateScore({ result: analysis, guards: performanceGuards })\n\tconst maintainability = calculateScore({ result: analysis, guards: maintainabilityGuards })\n\tconst complexity = calculateScore({ result: analysis, guards: complexityGuards })\n\n\treturn {\n\t\t/** @deprecated */\n\t\tscore: 0,\n\t\tviolations: performance.violations\n\t\t\t.concat(maintainability.violations)\n\t\t\t.concat(complexity.violations),\n\t\tpasses: performance.passes\n\t\t\t.concat(maintainability.passes)\n\t\t\t.concat(complexity.passes),\n\t\tperformance,\n\t\tmaintainability,\n\t\tcomplexity,\n\t}\n}\n","import { analyze } from '@projectwallace/css-analyzer'\nimport { calculate as calculateFromAnalysis } from './core.js'\n\n/** @param {string} css */\nexport function calculate(css) {\n\tconst analysis = analyze(css)\n\treturn calculateFromAnalysis(analysis)\n}\n"],"names":["guards","result","id","score","atrules","import","total","value","actuals","Object","keys","unique","rules","empty","outcome","selectors","uniquenessRatio","Math","floor","declarations","ratio","stylesheet","size","comments","min","embeddedContent","sourceLinesOfCode","actual","mean","items","max","ceil","mode","rulesHavingMoreThanMode","filter","item","length","complexity","selectorsAboveMode","c","specificity","compareSpecificity","importants","calculateScore","violations","passes","guard","push","calculate","css","analysis","performance","performanceGuards","maintainability","maintainabilityGuards","complexityGuards","concat","calculateFromAnalysis","analyze"],"mappings":"qFAAaA,EAAS,CAGpBC,KACEC,GAAI,UACJC,MAAqC,GAA9BF,EAAOG,QAAQC,OAAOC,MAC7BC,MAAON,EAAOG,QAAQC,OAAOC,MAC7BE,QAASC,OAAOC,KAAKT,EAAOG,QAAQC,OAAOM,UAI7CV,KACEC,GAAI,aACJC,MAAOF,EAAOW,MAAMC,MAAMP,MAC1BC,MAAON,EAAOW,MAAMC,MAAMP,QAI5BL,IACE,MAAMa,EAAU,CACdZ,GAAI,uBACJC,MAAO,EACPI,MAAO,EAAIN,EAAOc,UAAUC,iBAO9B,OAJIf,EAAOc,UAAUC,gBAAkB,MACrCF,EAAQX,MAAQc,KAAKC,MAA+C,IAAxC,EAAIjB,EAAOc,UAAUC,mBAG5CF,GAITb,IACE,MAAMa,EAAU,CACdZ,GAAI,0BACJC,MAAO,EACPI,MAAO,EAAIN,EAAOkB,aAAaR,OAAOS,OAOxC,OAJInB,EAAOkB,aAAaR,OAAOS,MAAQ,MACrCN,EAAQX,MAAQc,KAAKC,MAA+C,IAAxC,EAAIjB,EAAOkB,aAAaR,OAAOS,SAGtDN,GAITb,KACEC,GAAI,UACJC,MAAOF,EAAOoB,WAAWC,KAAO,IAAU,EAAI,EAC9Cf,MAAON,EAAOoB,WAAWC,OAK3BrB,IACE,MAAMsB,SAAEA,GAAatB,EAAOoB,WAC5B,MAAO,CACLnB,GAAI,kBACJC,MAAOc,KAAKO,IAAI,GAAIP,KAAKC,MA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EAAO,GACvByC,aACAC,SAEF,UCtBgBG,EAAUC,GAEzB,gBDuByBC,GACzB,MAAMC,EAAcR,EAAe,CAAE1C,OAAQiD,EAAUlD,OAAQoD,IACzDC,EAAkBV,EAAe,CAAE1C,OAAQiD,EAAUlD,OAAQsD,IAC7DjB,EAAaM,EAAe,CAAE1C,OAAQiD,EAAUlD,OAAQuD,IAE9D,MAAO,CAENpD,MAAO,EACPyC,WAAYO,EAAYP,WACtBY,OAAOH,EAAgBT,YACvBY,OAAOnB,EAAWO,YACpBC,OAAQM,EAAYN,OAClBW,OAAOH,EAAgBR,QACvBW,OAAOnB,EAAWQ,QACpBM,cACAE,kBACAhB,aAEF,CCzCQoB,CADUC,EAAQT,GAE1B"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{compareSpecificity as e,analyze as t}from"@projectwallace/css-analyzer";function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o}var o=[function(e){return{id:"Imports",score:10*e.atrules.import.total,value:e.atrules.import.total,actuals:Object.keys(e.atrules.import.unique)}},function(e){return{id:"EmptyRules",score:e.rules.empty.total,value:e.rules.empty.total}},function(e){var t={id:"SelectorDuplications",score:0,value:1-e.selectors.uniquenessRatio};return e.selectors.uniquenessRatio<.66&&(t.score=Math.floor(10*(1-e.selectors.uniquenessRatio))),t},function(e){var t={id:"DeclarationDuplications",score:0,value:1-e.declarations.unique.ratio};return e.declarations.unique.ratio<.66&&(t.score=Math.floor(10*(1-e.declarations.unique.ratio))),t},function(e){return{id:"CssSize",score:e.stylesheet.size>2e5?5:0,value:e.stylesheet.size}},function(e){var t=e.stylesheet.comments;return{id:"TooMuchComments",score:Math.min(10,Math.floor(t.size/250)),value:t.size}},function(e){var t=e.stylesheet.embeddedContent.size;return{id:"TooMuchEmbeddedContent",score:Math.min(20,Math.floor(t.total/250)),value:t.total,actuals:Object.keys(e.stylesheet.embeddedContent.unique)}}],s=[function(e){var t={id:"SourceLinesOfCode",score:0,value:e.stylesheet.sourceLinesOfCode};if(e.stylesheet.sourceLinesOfCode>1e4){var r=Math.floor((e.stylesheet.sourceLinesOfCode-1e4)/1e3);t.score=Math.min(15,r)}return t},function(e){var t=e.rules.selectors.mean,r={id:"AverageSelectorsPerRule",score:0,value:t,actuals:e.rules.selectors.items};if(t>2){var o=Math.floor(5*(t-2));r.score=Math.min(15,o)}return r},function(e){var t={id:"AverageDeclarationsPerRule",score:0,value:e.rules.declarations.mean,actuals:e.rules.declarations.items};if(e.rules.declarations.mean>5){var r=Math.floor(5*(e.rules.declarations.mean-5));t.score=Math.min(15,r)}return t},function(e){var t={id:"MaxSelectorsPerRule",score:0,value:e.rules.selectors.max,actuals:e.rules.selectors.items};if(e.rules.selectors.max>10){var r=Math.ceil(.5*(e.rules.selectors.max-10));t.score=Math.min(r,15)}return t},function(e){var t={id:"MaxDeclarationsPerRule",score:0,value:e.rules.declarations.max,actuals:e.rules.declarations.items};if(e.rules.declarations.max>10){var r=Math.ceil(.5*(e.rules.declarations.max-10));t.score=Math.min(15,r)}return t},function(e){var t=e.rules.selectors.mode,r=e.rules.selectors.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonSelectorsPerRule",score:0,value:e.rules.selectors.mode,actuals:e.rules.selectors.items};if(r>.1*e.rules.total){var s=Math.floor(.01*r);o.score=Math.min(15,s)}return o},function(e){var t=e.rules.selectors.mode,r=e.rules.declarations.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonDeclarationsPerRule",score:0,value:e.rules.declarations.mode,actuals:e.rules.declarations.items};if(r>.1*e.rules.total){var s=Math.floor(.01*r);o.score=Math.min(15,s)}return o}],a=[function(e){var t=e.selectors.complexity.mode,r=e.selectors.complexity.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonSelectorComplexity",score:0,value:0===e.selectors.total?0:r/e.selectors.total,actuals:e.selectors.complexity.items};if(r>.1*e.selectors.total){var s=Math.floor(.01*r);o.score=Math.min(10,s)}return o},function(t){var r=t.selectors.specificity.mode,o=t.selectors.specificity.items.filter(function(t){return e(t,r)<0}).length,s={id:"MoreThanMostCommonSelectorSpecificity",score:0,value:0===t.selectors.total?0:o/t.selectors.total,actuals:t.selectors.specificity.items};if(o>.1*t.selectors.total){var a=Math.floor(.01*o);s.score=Math.min(10,a)}return s},function(e){var t=e.selectors.complexity.max,r={id:"MaxSelectorComplexity",score:0,value:e.selectors.complexity.max,actuals:e.selectors.complexity.items};if(t>5){var o=Math.ceil(.5*(t-5));r.score=Math.min(5,o)}return r},function(e){var t=e.selectors.complexity.mean,r={id:"AverageSelectorComplexity",score:0,value:t,actuals:e.selectors.complexity.items};if(t>2){var o=Math.ceil(2*(t-2));r.score=Math.min(10,o)}return r},function(e){var t=e.selectors.id.ratio,r={id:"IdSelectorRatio",score:0,value:t,actuals:Object.keys(e.selectors.id.unique)};if(t>.01){var o=Math.floor(10*(t-.01));r.score=Math.min(o,5)}return r},function(e){var t=e.declarations.importants.ratio,r={id:"ImportantRatio",score:0,value:t,actuals:e.declarations.importants.total};if(t>.01){var o=Math.floor(10*(t-.01));r.score=Math.min(o,5)}return r}];function l(e){for(var t,o=e.result,s=100,a=[],l=[],i=function(e,t){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return(o=o.call(e)).next.bind(o);if(Array.isArray(e)||(o=function(e,t){if(e){if("string"==typeof e)return r(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?r(e,t):void 0}}(e))){o&&(e=o);var s=0;return function(){return s>=e.length?{done:!0}:{done:!1,value:e[s++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.guards);!(t=i()).done;){var n=(0,t.value)(o);n.score>0?(s-=n.score,a.push(n)):l.push(n)}return{score:Math.max(s,0),violations:a,passes:l}}function i(e){return i=l({result:r=t(e),guards:o}),n=l({result:r,guards:s}),c=l({result:r,guards:a}),{score:0,violations:i.violations.concat(n.violations).concat(c.violations),passes:i.passes.concat(n.passes).concat(c.passes),performance:i,maintainability:n,complexity:c};var r,i,n,c}export{i as calculate};
|
|
2
|
-
//# sourceMappingURL=css-code-quality.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"css-code-quality.module.js","sources":["../src/performance.js","../src/maintainability.js","../src/complexity.js","../src/core.js","../src/index.js"],"sourcesContent":["export const guards = [\n\n // Should not contain @import rules\n result => ({\n id: 'Imports',\n score: result.atrules.import.total * 10,\n value: result.atrules.import.total,\n actuals: Object.keys(result.atrules.import.unique),\n }),\n\n // Should not contain empty rules\n result => ({\n id: 'EmptyRules',\n score: result.rules.empty.total,\n value: result.rules.empty.total,\n }),\n\n // Too many selectors appear multiple times\n result => {\n const outcome = {\n id: 'SelectorDuplications',\n score: 0,\n value: 1 - result.selectors.uniquenessRatio,\n }\n\n if (result.selectors.uniquenessRatio < 0.66) {\n outcome.score = Math.floor((1 - result.selectors.uniquenessRatio) * 10)\n }\n\n return outcome\n },\n\n // Too many declarations appear multiple times\n result => {\n const outcome = {\n id: 'DeclarationDuplications',\n score: 0,\n value: 1 - result.declarations.unique.ratio,\n }\n\n if (result.declarations.unique.ratio < 0.66) {\n outcome.score = Math.floor((1 - result.declarations.unique.ratio) * 10)\n }\n\n return outcome\n },\n\n // The total amount of CSS should not be too high\n result => ({\n id: 'CssSize',\n score: result.stylesheet.size > 200_000 ? 5 : 0,\n value: result.stylesheet.size,\n }),\n\n // Should not contain (too much) comments\n // Deduct 1 point for every 250 bytes\n result => {\n const { comments } = result.stylesheet\n return {\n id: 'TooMuchComments',\n score: Math.min(10, Math.floor(comments.size / 250)),\n value: comments.size,\n }\n },\n\n // Should not contain too much embedded content\n // Deduct 1 point for every 250 bytes\n result => {\n const { size } = result.stylesheet.embeddedContent\n return {\n id: 'TooMuchEmbeddedContent',\n score: Math.min(20, Math.floor(size.total / 250)),\n value: size.total,\n actuals: Object.keys(result.stylesheet.embeddedContent.unique),\n }\n },\n]\n","export const guards = [\n\n // Source Lines of Code should be low'\n result => {\n const outcome = {\n id: 'SourceLinesOfCode',\n score: 0,\n value: result.stylesheet.sourceLinesOfCode,\n }\n\n if (result.stylesheet.sourceLinesOfCode > 10000) {\n // deduct 1 point per 1000 lines of code over 10,000\n const score = Math.floor((result.stylesheet.sourceLinesOfCode - 10000) / 1000)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Selectors per RuleSet should be low\n result => {\n const ALLOWED_SELECTORS_PER_RULESET = 2\n const actual = result.rules.selectors.mean\n\n const outcome = {\n id: 'AverageSelectorsPerRule',\n score: 0,\n value: actual,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 5 points per selector over 2\n if (actual > ALLOWED_SELECTORS_PER_RULESET) {\n const score = Math.floor((actual - ALLOWED_SELECTORS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Declarations per RuleSet should be low\n result => {\n const ALLOWED_DECLARATIONS_PER_RULESET = 5\n\n const outcome = {\n id: 'AverageDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mean,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 5 points per declaration over 5\n if (result.rules.declarations.mean > ALLOWED_DECLARATIONS_PER_RULESET) {\n const score = Math.floor((result.rules.declarations.mean - ALLOWED_DECLARATIONS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Max number of Selectors per Rule should be low\n result => {\n const MAX_SELECTORS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.max,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 0.5 points per selectors over 10\n if (result.rules.selectors.max > MAX_SELECTORS_PER_RULESET) {\n const score = Math.ceil((result.rules.selectors.max - MAX_SELECTORS_PER_RULESET) * 0.5)\n outcome.score = Math.min(score, 15)\n }\n\n return outcome\n },\n\n // Max number of Declarations per Rule should be low\n result => {\n const MAX_DECLARATIONS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.max,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 0.5 points per declarations over 10\n if (result.rules.declarations.max > MAX_DECLARATIONS_PER_RULESET) {\n const score = Math.ceil((result.rules.declarations.max - MAX_DECLARATIONS_PER_RULESET) * 0.5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Selectors per RuleSet should not differ too much from the most common amount of\n // Selectors per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.selectors.items\n .filter(item => item > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.mode,\n actuals: result.rules.selectors.items,\n }\n\n // if more than 10% of RuleSets has more Selectors than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Declarations per RuleSet should not differ too much from the most common amount of\n // Declarations per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.declarations.items.filter(item => item > mode).length\n\n const outcome = {\n id: 'MoreThanMostCommonDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mode,\n actuals: result.rules.declarations.items,\n }\n\n // if more than 10% of RuleSets has more Declarations than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n]\n","import { compareSpecificity } from '@projectwallace/css-analyzer'\n\nexport const guards = [\n\n // Complexity per Selector should not differ too much from the most common Complexity\n result => {\n const mode = result.selectors.complexity.mode\n const selectorsAboveMode = result.selectors.complexity.items\n .filter(c => c > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorComplexity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.complexity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Specificity per Selector should not differ too much from the most common Specificity\n result => {\n const mode = result.selectors.specificity.mode\n const selectorsAboveMode = result.selectors.specificity.items\n .filter(c => compareSpecificity(c, mode) < 0)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorSpecificity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.specificity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Maximum Selector Complexity should be low\n result => {\n const MAX_SELECTOR_COMPLEXITY = 5\n const actual = result.selectors.complexity.max\n\n const outcome = {\n id: 'MaxSelectorComplexity',\n score: 0,\n value: result.selectors.complexity.max,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 0.5 points per complexity over 5, up to 5 points\n if (actual > MAX_SELECTOR_COMPLEXITY) {\n const score = Math.ceil((actual - MAX_SELECTOR_COMPLEXITY) * 0.5)\n outcome.score = Math.min(5, score)\n }\n\n return outcome\n },\n\n // Average Selector Complexity should be low\n result => {\n const ALLOWED_COMPLEXITY = 2\n const actual = result.selectors.complexity.mean\n\n const outcome = {\n id: 'AverageSelectorComplexity',\n score: 0,\n value: actual,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 2 points per selector over 2\n if (actual > ALLOWED_COMPLEXITY) {\n const score = Math.ceil((actual - ALLOWED_COMPLEXITY) * 2)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.selectors.id.ratio\n const outcome = {\n id: 'IdSelectorRatio',\n score: 0,\n value: actual,\n actuals: Object.keys(result.selectors.id.unique)\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.declarations.importants.ratio\n const outcome = {\n id: 'ImportantRatio',\n score: 0,\n value: actual,\n actuals: result.declarations.importants.total,\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n]\n","import { guards as performanceGuards } from './performance.js'\nimport { guards as maintainabilityGuards } from './maintainability.js'\nimport { guards as complexityGuards } from './complexity.js'\n\nfunction calculateScore({ result, guards }) {\n\tlet score = 100\n\tlet violations = []\n\tlet passes = []\n\n\tfor (const guard of guards) {\n\t\t/** @type {{score: number, value: number, id: string}} */\n\t\tconst outcome = guard(result)\n\n\t\tif (outcome.score > 0) {\n\t\t\tscore -= outcome.score\n\t\t\tviolations.push(outcome)\n\t\t} else {\n\t\t\tpasses.push(outcome)\n\t\t}\n\t}\n\n\treturn {\n\t\tscore: Math.max(score, 0),\n\t\tviolations,\n\t\tpasses,\n\t}\n}\n\n/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */\nexport function calculate(analysis) {\n\tconst performance = calculateScore({ result: analysis, guards: performanceGuards })\n\tconst maintainability = calculateScore({ result: analysis, guards: maintainabilityGuards })\n\tconst complexity = calculateScore({ result: analysis, guards: complexityGuards })\n\n\treturn {\n\t\t/** @deprecated */\n\t\tscore: 0,\n\t\tviolations: performance.violations\n\t\t\t.concat(maintainability.violations)\n\t\t\t.concat(complexity.violations),\n\t\tpasses: performance.passes\n\t\t\t.concat(maintainability.passes)\n\t\t\t.concat(complexity.passes),\n\t\tperformance,\n\t\tmaintainability,\n\t\tcomplexity,\n\t}\n}\n","import { analyze } from '@projectwallace/css-analyzer'\nimport { calculate as calculateFromAnalysis } from './core.js'\n\n/** @param {string} css */\nexport function calculate(css) {\n\tconst analysis = analyze(css)\n\treturn calculateFromAnalysis(analysis)\n}\n"],"names":["guards","result","id","score","atrules","total","value","actuals","Object","keys","unique","rules","empty","outcome","selectors","uniquenessRatio","Math","floor","declarations","ratio","stylesheet","size","comments","min","embeddedContent","sourceLinesOfCode","actual","mean","items","max","ceil","mode","rulesHavingMoreThanMode","filter","item","length","complexity","selectorsAboveMode","c","specificity","compareSpecificity","importants","calculateScore","_ref","_step","violations","passes","_iterator","_createForOfIteratorHelperLoose","done","guard","push","calculate","css","performance","analysis","analyze","performanceGuards","maintainability","maintainabilityGuards","complexityGuards","concat"],"mappings":"6LAAaA,EAAS,CAGpB,SAAAC,SAAW,CACTC,GAAI,UACJC,MAAqC,GAA9BF,EAAOG,eAAeC,MAC7BC,MAAOL,EAAOG,eAAeC,MAC7BE,QAASC,OAAOC,KAAKR,EAAOG,eAAeM,QAC5C,EAGD,SAAAT,SAAW,CACTC,GAAI,aACJC,MAAOF,EAAOU,MAAMC,MAAMP,MAC1BC,MAAOL,EAAOU,MAAMC,MAAMP,MAC3B,EAGD,SAAAJ,GACE,IAAMY,EAAU,CACdX,GAAI,uBACJC,MAAO,EACPG,MAAO,EAAIL,EAAOa,UAAUC,iBAO9B,OAJId,EAAOa,UAAUC,gBAAkB,MACrCF,EAAQV,MAAQa,KAAKC,MAA+C,IAAxC,EAAIhB,EAAOa,UAAUC,mBAG5CF,CACT,EAGA,SAAAZ,GACE,IAAMY,EAAU,CACdX,GAAI,0BACJC,MAAO,EACPG,MAAO,EAAIL,EAAOiB,aAAaR,OAAOS,OAOxC,OAJIlB,EAAOiB,aAAaR,OAAOS,MAAQ,MACrCN,EAAQV,MAAQa,KAAKC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,iBACJC,MAAO,EACPG,MAAOoB,EACPnB,QAASN,EAAOiB,aAAauB,WAAWpC,OAG1C,GAAIqB,EATY,IASM,CACpB,IAAMvB,EAAQa,KAAKC,MAA2B,IAApBS,EAVZ,MAWdb,EAAQV,MAAQa,KAAKO,IAAIpB,EAAO,EAClC,CAEA,OAAOU,CACT,GCxHF,SAAS6B,EAAcC,GAKtB,QAA0BC,EALD3C,EAAM0C,EAAN1C,OACrBE,EAAQ,IACR0C,EAAa,GACbC,EAAS,GAEbC,2qBAAAC,CALuCL,EAAN3C,UAKP4C,EAAAG,KAAAE,MAAE,KAErBpC,GAAUqC,EAFDN,EAAAtC,OAEOL,GAElBY,EAAQV,MAAQ,GACnBA,GAASU,EAAQV,MACjB0C,EAAWM,KAAKtC,IAEhBiC,EAAOK,KAAKtC,EAEd,CAEA,MAAO,CACNV,MAAOa,KAAKa,IAAI1B,EAAO,GACvB0C,WAAAA,EACAC,OAAAA,EAEF,UCtBgBM,EAAUC,GAEzB,ODwBMC,EAAcZ,EAAe,CAAEzC,OADZsD,ECxBRC,EAAQH,GDyB8BrD,OAAQyD,IACzDC,EAAkBhB,EAAe,CAAEzC,OAAQsD,EAAUvD,OAAQ2D,IAC7DvB,EAAaM,EAAe,CAAEzC,OAAQsD,EAAUvD,OAAQ4D,IAEvD,CAENzD,MAAO,EACP0C,WAAYS,EAAYT,WACtBgB,OAAOH,EAAgBb,YACvBgB,OAAOzB,EAAWS,YACpBC,OAAQQ,EAAYR,OAClBe,OAAOH,EAAgBZ,QACvBe,OAAOzB,EAAWU,QACpBQ,YAAAA,EACAI,gBAAAA,EACAtB,WAAAA,OAhBwBmB,EACnBD,EACAI,EACAtB,CCzBP"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@projectwallace/css-analyzer")):"function"==typeof define&&define.amd?define(["exports","@projectwallace/css-analyzer"],t):t((e||self).cssCodeQuality={},e.cssAnalyzer)}(this,function(e,t){function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o}var o=[function(e){return{id:"Imports",score:10*e.atrules.import.total,value:e.atrules.import.total,actuals:Object.keys(e.atrules.import.unique)}},function(e){return{id:"EmptyRules",score:e.rules.empty.total,value:e.rules.empty.total}},function(e){var t={id:"SelectorDuplications",score:0,value:1-e.selectors.uniquenessRatio};return e.selectors.uniquenessRatio<.66&&(t.score=Math.floor(10*(1-e.selectors.uniquenessRatio))),t},function(e){var t={id:"DeclarationDuplications",score:0,value:1-e.declarations.unique.ratio};return e.declarations.unique.ratio<.66&&(t.score=Math.floor(10*(1-e.declarations.unique.ratio))),t},function(e){return{id:"CssSize",score:e.stylesheet.size>2e5?5:0,value:e.stylesheet.size}},function(e){var t=e.stylesheet.comments;return{id:"TooMuchComments",score:Math.min(10,Math.floor(t.size/250)),value:t.size}},function(e){var t=e.stylesheet.embeddedContent.size;return{id:"TooMuchEmbeddedContent",score:Math.min(20,Math.floor(t.total/250)),value:t.total,actuals:Object.keys(e.stylesheet.embeddedContent.unique)}}],s=[function(e){var t={id:"SourceLinesOfCode",score:0,value:e.stylesheet.sourceLinesOfCode};if(e.stylesheet.sourceLinesOfCode>1e4){var r=Math.floor((e.stylesheet.sourceLinesOfCode-1e4)/1e3);t.score=Math.min(15,r)}return t},function(e){var t=e.rules.selectors.mean,r={id:"AverageSelectorsPerRule",score:0,value:t,actuals:e.rules.selectors.items};if(t>2){var o=Math.floor(5*(t-2));r.score=Math.min(15,o)}return r},function(e){var t={id:"AverageDeclarationsPerRule",score:0,value:e.rules.declarations.mean,actuals:e.rules.declarations.items};if(e.rules.declarations.mean>5){var r=Math.floor(5*(e.rules.declarations.mean-5));t.score=Math.min(15,r)}return t},function(e){var t={id:"MaxSelectorsPerRule",score:0,value:e.rules.selectors.max,actuals:e.rules.selectors.items};if(e.rules.selectors.max>10){var r=Math.ceil(.5*(e.rules.selectors.max-10));t.score=Math.min(r,15)}return t},function(e){var t={id:"MaxDeclarationsPerRule",score:0,value:e.rules.declarations.max,actuals:e.rules.declarations.items};if(e.rules.declarations.max>10){var r=Math.ceil(.5*(e.rules.declarations.max-10));t.score=Math.min(15,r)}return t},function(e){var t=e.rules.selectors.mode,r=e.rules.selectors.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonSelectorsPerRule",score:0,value:e.rules.selectors.mode,actuals:e.rules.selectors.items};if(r>.1*e.rules.total){var s=Math.floor(.01*r);o.score=Math.min(15,s)}return o},function(e){var t=e.rules.selectors.mode,r=e.rules.declarations.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonDeclarationsPerRule",score:0,value:e.rules.declarations.mode,actuals:e.rules.declarations.items};if(r>.1*e.rules.total){var s=Math.floor(.01*r);o.score=Math.min(15,s)}return o}],a=[function(e){var t=e.selectors.complexity.mode,r=e.selectors.complexity.items.filter(function(e){return e>t}).length,o={id:"MoreThanMostCommonSelectorComplexity",score:0,value:0===e.selectors.total?0:r/e.selectors.total,actuals:e.selectors.complexity.items};if(r>.1*e.selectors.total){var s=Math.floor(.01*r);o.score=Math.min(10,s)}return o},function(e){var r=e.selectors.specificity.mode,o=e.selectors.specificity.items.filter(function(e){return t.compareSpecificity(e,r)<0}).length,s={id:"MoreThanMostCommonSelectorSpecificity",score:0,value:0===e.selectors.total?0:o/e.selectors.total,actuals:e.selectors.specificity.items};if(o>.1*e.selectors.total){var a=Math.floor(.01*o);s.score=Math.min(10,a)}return s},function(e){var t=e.selectors.complexity.max,r={id:"MaxSelectorComplexity",score:0,value:e.selectors.complexity.max,actuals:e.selectors.complexity.items};if(t>5){var o=Math.ceil(.5*(t-5));r.score=Math.min(5,o)}return r},function(e){var t=e.selectors.complexity.mean,r={id:"AverageSelectorComplexity",score:0,value:t,actuals:e.selectors.complexity.items};if(t>2){var o=Math.ceil(2*(t-2));r.score=Math.min(10,o)}return r},function(e){var t=e.selectors.id.ratio,r={id:"IdSelectorRatio",score:0,value:t,actuals:Object.keys(e.selectors.id.unique)};if(t>.01){var o=Math.floor(10*(t-.01));r.score=Math.min(o,5)}return r},function(e){var t=e.declarations.importants.ratio,r={id:"ImportantRatio",score:0,value:t,actuals:e.declarations.importants.total};if(t>.01){var o=Math.floor(10*(t-.01));r.score=Math.min(o,5)}return r}];function l(e){for(var t,o=e.result,s=100,a=[],l=[],i=function(e,t){var o="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(o)return(o=o.call(e)).next.bind(o);if(Array.isArray(e)||(o=function(e,t){if(e){if("string"==typeof e)return r(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?r(e,t):void 0}}(e))){o&&(e=o);var s=0;return function(){return s>=e.length?{done:!0}:{done:!1,value:e[s++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.guards);!(t=i()).done;){var n=(0,t.value)(o);n.score>0?(s-=n.score,a.push(n)):l.push(n)}return{score:Math.max(s,0),violations:a,passes:l}}e.calculate=function(e){return i=l({result:r=t.analyze(e),guards:o}),n=l({result:r,guards:s}),c=l({result:r,guards:a}),{score:0,violations:i.violations.concat(n.violations).concat(c.violations),passes:i.passes.concat(n.passes).concat(c.passes),performance:i,maintainability:n,complexity:c};var r,i,n,c}});
|
|
2
|
-
//# sourceMappingURL=css-code-quality.umd.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"css-code-quality.umd.js","sources":["../src/performance.js","../src/maintainability.js","../src/complexity.js","../src/core.js","../src/index.js"],"sourcesContent":["export const guards = [\n\n // Should not contain @import rules\n result => ({\n id: 'Imports',\n score: result.atrules.import.total * 10,\n value: result.atrules.import.total,\n actuals: Object.keys(result.atrules.import.unique),\n }),\n\n // Should not contain empty rules\n result => ({\n id: 'EmptyRules',\n score: result.rules.empty.total,\n value: result.rules.empty.total,\n }),\n\n // Too many selectors appear multiple times\n result => {\n const outcome = {\n id: 'SelectorDuplications',\n score: 0,\n value: 1 - result.selectors.uniquenessRatio,\n }\n\n if (result.selectors.uniquenessRatio < 0.66) {\n outcome.score = Math.floor((1 - result.selectors.uniquenessRatio) * 10)\n }\n\n return outcome\n },\n\n // Too many declarations appear multiple times\n result => {\n const outcome = {\n id: 'DeclarationDuplications',\n score: 0,\n value: 1 - result.declarations.unique.ratio,\n }\n\n if (result.declarations.unique.ratio < 0.66) {\n outcome.score = Math.floor((1 - result.declarations.unique.ratio) * 10)\n }\n\n return outcome\n },\n\n // The total amount of CSS should not be too high\n result => ({\n id: 'CssSize',\n score: result.stylesheet.size > 200_000 ? 5 : 0,\n value: result.stylesheet.size,\n }),\n\n // Should not contain (too much) comments\n // Deduct 1 point for every 250 bytes\n result => {\n const { comments } = result.stylesheet\n return {\n id: 'TooMuchComments',\n score: Math.min(10, Math.floor(comments.size / 250)),\n value: comments.size,\n }\n },\n\n // Should not contain too much embedded content\n // Deduct 1 point for every 250 bytes\n result => {\n const { size } = result.stylesheet.embeddedContent\n return {\n id: 'TooMuchEmbeddedContent',\n score: Math.min(20, Math.floor(size.total / 250)),\n value: size.total,\n actuals: Object.keys(result.stylesheet.embeddedContent.unique),\n }\n },\n]\n","export const guards = [\n\n // Source Lines of Code should be low'\n result => {\n const outcome = {\n id: 'SourceLinesOfCode',\n score: 0,\n value: result.stylesheet.sourceLinesOfCode,\n }\n\n if (result.stylesheet.sourceLinesOfCode > 10000) {\n // deduct 1 point per 1000 lines of code over 10,000\n const score = Math.floor((result.stylesheet.sourceLinesOfCode - 10000) / 1000)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Selectors per RuleSet should be low\n result => {\n const ALLOWED_SELECTORS_PER_RULESET = 2\n const actual = result.rules.selectors.mean\n\n const outcome = {\n id: 'AverageSelectorsPerRule',\n score: 0,\n value: actual,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 5 points per selector over 2\n if (actual > ALLOWED_SELECTORS_PER_RULESET) {\n const score = Math.floor((actual - ALLOWED_SELECTORS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Average count of Declarations per RuleSet should be low\n result => {\n const ALLOWED_DECLARATIONS_PER_RULESET = 5\n\n const outcome = {\n id: 'AverageDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mean,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 5 points per declaration over 5\n if (result.rules.declarations.mean > ALLOWED_DECLARATIONS_PER_RULESET) {\n const score = Math.floor((result.rules.declarations.mean - ALLOWED_DECLARATIONS_PER_RULESET) * 5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Max number of Selectors per Rule should be low\n result => {\n const MAX_SELECTORS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.max,\n actuals: result.rules.selectors.items,\n }\n\n // Deduct 0.5 points per selectors over 10\n if (result.rules.selectors.max > MAX_SELECTORS_PER_RULESET) {\n const score = Math.ceil((result.rules.selectors.max - MAX_SELECTORS_PER_RULESET) * 0.5)\n outcome.score = Math.min(score, 15)\n }\n\n return outcome\n },\n\n // Max number of Declarations per Rule should be low\n result => {\n const MAX_DECLARATIONS_PER_RULESET = 10\n\n const outcome = {\n id: 'MaxDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.max,\n actuals: result.rules.declarations.items,\n }\n\n // Deduct 0.5 points per declarations over 10\n if (result.rules.declarations.max > MAX_DECLARATIONS_PER_RULESET) {\n const score = Math.ceil((result.rules.declarations.max - MAX_DECLARATIONS_PER_RULESET) * 0.5)\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Selectors per RuleSet should not differ too much from the most common amount of\n // Selectors per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.selectors.items\n .filter(item => item > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorsPerRule',\n score: 0,\n value: result.rules.selectors.mode,\n actuals: result.rules.selectors.items,\n }\n\n // if more than 10% of RuleSets has more Selectors than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n\n // Number of Declarations per RuleSet should not differ too much from the most common amount of\n // Declarations per RuleSet\n result => {\n const mode = result.rules.selectors.mode\n const rulesHavingMoreThanMode = result.rules.declarations.items.filter(item => item > mode).length\n\n const outcome = {\n id: 'MoreThanMostCommonDeclarationsPerRule',\n score: 0,\n value: result.rules.declarations.mode,\n actuals: result.rules.declarations.items,\n }\n\n // if more than 10% of RuleSets has more Declarations than most common:\n if (rulesHavingMoreThanMode > result.rules.total * 0.1) {\n // then deduct 0.01 for ever applicable RuleSet\n const score = Math.floor(rulesHavingMoreThanMode * 0.01)\n // with a maximum of 10 points\n outcome.score = Math.min(15, score)\n }\n\n return outcome\n },\n]\n","import { compareSpecificity } from '@projectwallace/css-analyzer'\n\nexport const guards = [\n\n // Complexity per Selector should not differ too much from the most common Complexity\n result => {\n const mode = result.selectors.complexity.mode\n const selectorsAboveMode = result.selectors.complexity.items\n .filter(c => c > mode)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorComplexity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.complexity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Specificity per Selector should not differ too much from the most common Specificity\n result => {\n const mode = result.selectors.specificity.mode\n const selectorsAboveMode = result.selectors.specificity.items\n .filter(c => compareSpecificity(c, mode) < 0)\n .length\n\n const outcome = {\n id: 'MoreThanMostCommonSelectorSpecificity',\n score: 0,\n value: result.selectors.total === 0 ? 0 : selectorsAboveMode / result.selectors.total,\n actuals: result.selectors.specificity.items,\n }\n\n if (selectorsAboveMode > result.selectors.total * 0.1) {\n const score = Math.floor(selectorsAboveMode * 0.01)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n // Maximum Selector Complexity should be low\n result => {\n const MAX_SELECTOR_COMPLEXITY = 5\n const actual = result.selectors.complexity.max\n\n const outcome = {\n id: 'MaxSelectorComplexity',\n score: 0,\n value: result.selectors.complexity.max,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 0.5 points per complexity over 5, up to 5 points\n if (actual > MAX_SELECTOR_COMPLEXITY) {\n const score = Math.ceil((actual - MAX_SELECTOR_COMPLEXITY) * 0.5)\n outcome.score = Math.min(5, score)\n }\n\n return outcome\n },\n\n // Average Selector Complexity should be low\n result => {\n const ALLOWED_COMPLEXITY = 2\n const actual = result.selectors.complexity.mean\n\n const outcome = {\n id: 'AverageSelectorComplexity',\n score: 0,\n value: actual,\n actuals: result.selectors.complexity.items,\n }\n\n // Deduct 2 points per selector over 2\n if (actual > ALLOWED_COMPLEXITY) {\n const score = Math.ceil((actual - ALLOWED_COMPLEXITY) * 2)\n outcome.score = Math.min(10, score)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.selectors.id.ratio\n const outcome = {\n id: 'IdSelectorRatio',\n score: 0,\n value: actual,\n actuals: Object.keys(result.selectors.id.unique)\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n\n result => {\n const ALLOWED = 0.01\n const actual = result.declarations.importants.ratio\n const outcome = {\n id: 'ImportantRatio',\n score: 0,\n value: actual,\n actuals: result.declarations.importants.total,\n }\n\n if (actual > ALLOWED) {\n const score = Math.floor((actual - ALLOWED) * 10)\n outcome.score = Math.min(score, 5)\n }\n\n return outcome\n },\n]\n","import { guards as performanceGuards } from './performance.js'\nimport { guards as maintainabilityGuards } from './maintainability.js'\nimport { guards as complexityGuards } from './complexity.js'\n\nfunction calculateScore({ result, guards }) {\n\tlet score = 100\n\tlet violations = []\n\tlet passes = []\n\n\tfor (const guard of guards) {\n\t\t/** @type {{score: number, value: number, id: string}} */\n\t\tconst outcome = guard(result)\n\n\t\tif (outcome.score > 0) {\n\t\t\tscore -= outcome.score\n\t\t\tviolations.push(outcome)\n\t\t} else {\n\t\t\tpasses.push(outcome)\n\t\t}\n\t}\n\n\treturn {\n\t\tscore: Math.max(score, 0),\n\t\tviolations,\n\t\tpasses,\n\t}\n}\n\n/** @param {ReturnType<import('@projectwallace/css-analyzer').analyze>} analysis */\nexport function calculate(analysis) {\n\tconst performance = calculateScore({ result: analysis, guards: performanceGuards })\n\tconst maintainability = calculateScore({ result: analysis, guards: maintainabilityGuards })\n\tconst complexity = calculateScore({ result: analysis, guards: complexityGuards })\n\n\treturn {\n\t\t/** @deprecated */\n\t\tscore: 0,\n\t\tviolations: performance.violations\n\t\t\t.concat(maintainability.violations)\n\t\t\t.concat(complexity.violations),\n\t\tpasses: performance.passes\n\t\t\t.concat(maintainability.passes)\n\t\t\t.concat(complexity.passes),\n\t\tperformance,\n\t\tmaintainability,\n\t\tcomplexity,\n\t}\n}\n","import { analyze } from '@projectwallace/css-analyzer'\nimport { calculate as calculateFromAnalysis } from './core.js'\n\n/** @param {string} css */\nexport function calculate(css) {\n\tconst analysis = analyze(css)\n\treturn calculateFromAnalysis(analysis)\n}\n"],"names":["guards","result","id","score","atrules","total","value","actuals","Object","keys","unique","rules","empty","outcome","selectors","uniquenessRatio","Math","floor","declarations","ratio","stylesheet","size","comments","min","embeddedContent","sourceLinesOfCode","actual","mean","items","max","ceil","mode","rulesHavingMoreThanMode","filter","item","length","complexity","selectorsAboveMode","c","specificity","compareSpecificity","importants","calculateScore","_ref","_step","violations","passes","_iterator","_createForOfIteratorHelperLoose","done","guard","push","css","performance","analysis","analyze","performanceGuards","maintainability","maintainabilityGuards","complexityGuards","concat"],"mappings":"6aAAaA,EAAS,CAGpB,SAAAC,SAAW,CACTC,GAAI,UACJC,MAAqC,GAA9BF,EAAOG,eAAeC,MAC7BC,MAAOL,EAAOG,eAAeC,MAC7BE,QAASC,OAAOC,KAAKR,EAAOG,eAAeM,QAC5C,EAGD,SAAAT,SAAW,CACTC,GAAI,aACJC,MAAOF,EAAOU,MAAMC,MAAMP,MAC1BC,MAAOL,EAAOU,MAAMC,MAAMP,MAC3B,EAGD,SAAAJ,GACE,IAAMY,EAAU,CACdX,GAAI,uBACJC,MAAO,EACPG,MAAO,EAAIL,EAAOa,UAAUC,iBAO9B,OAJId,EAAOa,UAAUC,gBAAkB,MACrCF,EAAQV,MAAQa,KAAKC,MAA+C,IAAxC,EAAIhB,EAAOa,UAAUC,mBAG5CF,CACT,EAGA,SAAAZ,GACE,IAAMY,EAAU,CACdX,GAAI,0BACJC,MAAO,EACPG,MAAO,EAAIL,EAAOiB,aAAaR,OAAOS,OAOxC,OAJIlB,EAAOiB,aAAaR,OAAOS,MAAQ,MACrCN,EAAQV,MAAQa,KAAKC,MAA+C,IAAxC,EAAIhB,EAAOiB,aAAaR,OAAOS,SAGtDN,CACT,EAGA,SAAAZ,SAAW,CACTC,GAAI,UACJC,MAAOF,EAAOmB,WAAWC,KAAO,IAAU,EAAI,EAC9Cf,MAAOL,EAAOmB,WAAWC,KAC1B,EAID,SAAApB,GACE,IAAQqB,EAAarB,EAAOmB,WAApBE,SACR,MAAO,CACLpB,GAAI,kBACJC,MAAOa,KAAKO,IAAI,GAAIP,KAAKC,MAAMK,EAASD,KAAO,MAC/Cf,MAAOgB,EAASD,KAEpB,EAIA,SAAApB,GACE,IAAQoB,EAASpB,EAAOmB,WAAWI,gBAA3BH,KACR,MAAO,CACLnB,GAAI,yBACJC,MAAOa,KAAKO,IAAI,GAAIP,KAAKC,MAAMI,EAAKhB,MAAQ,MAC5CC,MAAOe,EAAKh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EA,MAAO,CACNV,MAAOa,KAAKa,IAAI1B,EAAO,GACvB0C,WAAAA,EACAC,OAAAA,EAEF,sBCtB0BM,GAEzB,ODwBMC,EAAcX,EAAe,CAAEzC,OADZqD,ECxBRC,UAAQH,GDyB8BpD,OAAQwD,IACzDC,EAAkBf,EAAe,CAAEzC,OAAQqD,EAAUtD,OAAQ0D,IAC7DtB,EAAaM,EAAe,CAAEzC,OAAQqD,EAAUtD,OAAQ2D,IAEvD,CAENxD,MAAO,EACP0C,WAAYQ,EAAYR,WACtBe,OAAOH,EAAgBZ,YACvBe,OAAOxB,EAAWS,YACpBC,OAAQO,EAAYP,OAClBc,OAAOH,EAAgBX,QACvBc,OAAOxB,EAAWU,QACpBO,YAAAA,EACAI,gBAAAA,EACArB,WAAAA,OAhBwBkB,EACnBD,EACAI,EACArB,CCzBP"}
|
package/src/complexity.test.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import * as assert from 'uvu/assert'
|
|
2
|
-
import { suite } from 'uvu'
|
|
3
|
-
import { calculate } from './index.js'
|
|
4
|
-
|
|
5
|
-
const Complexity = suite('Complexity')
|
|
6
|
-
|
|
7
|
-
Complexity('should deduct points for a lot of Selectors more complex than most common Complexity', () => {
|
|
8
|
-
const fixture = `
|
|
9
|
-
${Array.from({ length: 1000 })
|
|
10
|
-
.fill('')
|
|
11
|
-
.map(_ => `selector { }`)
|
|
12
|
-
.join('')
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
${Array.from({ length: 500 })
|
|
16
|
-
.fill('')
|
|
17
|
-
.map(_ => `:where(selector) { }`)
|
|
18
|
-
.join('')
|
|
19
|
-
}
|
|
20
|
-
`
|
|
21
|
-
const actual = calculate(fixture)
|
|
22
|
-
|
|
23
|
-
assert.equal(actual.complexity.violations, [
|
|
24
|
-
{
|
|
25
|
-
id: 'MoreThanMostCommonSelectorComplexity',
|
|
26
|
-
score: 5,
|
|
27
|
-
value: 1 / 3,
|
|
28
|
-
actuals: (Array.from({ length: 1000 }).fill(1)).concat(Array.from({ length: 500 }).fill(2)),
|
|
29
|
-
}
|
|
30
|
-
])
|
|
31
|
-
assert.is(actual.complexity.score, 95)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
Complexity('should deduct points for a lot of Selectors more complex than most common Specificity', () => {
|
|
35
|
-
const fixture = `
|
|
36
|
-
${Array.from({ length: 500 })
|
|
37
|
-
.fill('')
|
|
38
|
-
.map(_ => `selector1 { }`)
|
|
39
|
-
.join('')
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
${Array.from({ length: 200 })
|
|
43
|
-
.fill('')
|
|
44
|
-
.map(_ => `.selector { }`)
|
|
45
|
-
.join('')
|
|
46
|
-
}
|
|
47
|
-
`
|
|
48
|
-
const actual = calculate(fixture)
|
|
49
|
-
|
|
50
|
-
assert.equal(actual.complexity.violations, [
|
|
51
|
-
{
|
|
52
|
-
id: 'MoreThanMostCommonSelectorSpecificity',
|
|
53
|
-
score: 2,
|
|
54
|
-
value: 200 / 700,
|
|
55
|
-
actuals: (Array.from({ length: 500 }).fill([0, 0, 1])).concat(Array.from({ length: 200 }).fill([0, 1, 0])),
|
|
56
|
-
}
|
|
57
|
-
])
|
|
58
|
-
assert.is(actual.complexity.score, 98)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
Complexity('deducts points for selectors with high complexity', () => {
|
|
62
|
-
const fixture = `
|
|
63
|
-
a b c d e f {}
|
|
64
|
-
`
|
|
65
|
-
const actual = calculate(fixture)
|
|
66
|
-
|
|
67
|
-
assert.equal(actual.complexity.violations, [
|
|
68
|
-
{
|
|
69
|
-
id: 'MaxSelectorComplexity',
|
|
70
|
-
score: 3,
|
|
71
|
-
value: 11,
|
|
72
|
-
actuals: [11],
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
id: 'AverageSelectorComplexity',
|
|
76
|
-
score: 10,
|
|
77
|
-
value: 11,
|
|
78
|
-
actuals: [11],
|
|
79
|
-
}
|
|
80
|
-
])
|
|
81
|
-
assert.is(actual.complexity.score, 87)
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
Complexity('deducts points for having a high ratio of ID selectors', () => {
|
|
85
|
-
const fixture = `
|
|
86
|
-
a {}
|
|
87
|
-
b {}
|
|
88
|
-
c {}
|
|
89
|
-
#a {}
|
|
90
|
-
`
|
|
91
|
-
const actual = calculate(fixture)
|
|
92
|
-
|
|
93
|
-
assert.equal(actual.complexity.violations, [
|
|
94
|
-
{
|
|
95
|
-
id: 'IdSelectorRatio',
|
|
96
|
-
score: 2,
|
|
97
|
-
value: 0.25,
|
|
98
|
-
actuals: ['#a'],
|
|
99
|
-
}
|
|
100
|
-
])
|
|
101
|
-
assert.is(actual.complexity.score, 98)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
Complexity('deducts points for having a high ratio !importants', () => {
|
|
105
|
-
const fixture = `
|
|
106
|
-
selector {
|
|
107
|
-
a: b;
|
|
108
|
-
c: d;
|
|
109
|
-
e: f;
|
|
110
|
-
g: h !important;
|
|
111
|
-
}
|
|
112
|
-
`
|
|
113
|
-
const actual = calculate(fixture)
|
|
114
|
-
|
|
115
|
-
assert.equal(actual.complexity.violations, [
|
|
116
|
-
{
|
|
117
|
-
id: 'ImportantRatio',
|
|
118
|
-
score: 2,
|
|
119
|
-
value: 0.25,
|
|
120
|
-
actuals: 1,
|
|
121
|
-
}
|
|
122
|
-
])
|
|
123
|
-
assert.is(actual.complexity.score, 98)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
Complexity.run()
|
package/src/core.test.js
DELETED