-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
126 changed files
with
2,480 additions
and
13,789 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules | ||
/node_modules | ||
.nyc_output | ||
coverage | ||
.DS_Store |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
exports.FORMATS = { | ||
STRING: 'string', | ||
RATIO: 'ratio', | ||
FILESIZE: 'filesize', | ||
COUNT: 'integer', | ||
SELECTOR: 'selector', | ||
DECLARATION: 'declaration', | ||
PROPERTY: 'property', | ||
VALUE: 'value', | ||
RULE: 'rule', | ||
ATRULE: 'atrule', | ||
SPECIFICITY: 'specificity', | ||
} | ||
|
||
exports.AGGREGATES = { | ||
SUM: 'sum', | ||
AVERAGE: 'average', | ||
MAX: 'max', | ||
MIN: 'min', | ||
LIST: 'list', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const { FORMATS, AGGREGATES } = require('./_types') | ||
|
||
module.exports = ({ rules }) => { | ||
const declarations = rules | ||
.map((rule) => rule.declarations) | ||
.reduce((all, current) => all.concat(current), []) | ||
|
||
const unique = new Set(declarations.map((d) => d.stats.key)) | ||
const importants = declarations.filter((d) => d.isImportant) | ||
|
||
return [ | ||
{ | ||
id: 'declarations.total', | ||
value: declarations.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'declarations.unique.total', | ||
value: unique.size, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'declarations.unique.ratio', | ||
value: unique.size / declarations.length, | ||
format: FORMATS.RATIO, | ||
aggregate: AGGREGATES.AVERAGE, | ||
}, | ||
{ | ||
id: 'declarations.important.total', | ||
value: importants.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'declarations.important.ratio', | ||
value: importants.length / declarations.length, | ||
format: FORMATS.RATIO, | ||
aggregate: AGGREGATES.AVERAGE, | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const declarations = require('./declarations') | ||
const stylesheet = require('./stylesheet') | ||
const rulez = require('./rules') // ¯\_(ツ)_/¯ | ||
const properties = require('./properties') | ||
const selectors = require('./selectors') | ||
|
||
module.exports = ({ atrules, rules, css }) => { | ||
return [] | ||
.concat(declarations({ css, atrules, rules })) | ||
.concat(stylesheet({ css, atrules, rules })) | ||
.concat(rulez({ atrules, rules })) | ||
.concat(selectors({ atrules, rules })) | ||
.concat(properties({ atrules, rules })) | ||
.reduce((list, metric) => { | ||
list[metric.id] = metric | ||
return list | ||
}, {}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const { FORMATS, AGGREGATES } = require('./_types') | ||
const { stripPropertyAnalysis } = require('../analyze') | ||
const uniqueWithCount = require('array-unique-with-count') | ||
|
||
function stripUnique(item) { | ||
return { | ||
...item, | ||
value: stripPropertyAnalysis(item.value), | ||
} | ||
} | ||
|
||
module.exports = ({ atrules, rules }) => { | ||
const properties = rules | ||
.map((rule) => rule.declarations) | ||
.reduce((all, current) => all.concat(current), []) | ||
.map((declaration) => declaration.property) | ||
|
||
const unique = uniqueWithCount(properties).map(stripUnique) | ||
|
||
// Browserhacks | ||
const browserhacks = properties.filter((p) => p.stats.isBrowserHack) | ||
const uniqueBrowserhacks = uniqueWithCount(browserhacks).map(stripUnique) | ||
|
||
// Vendor prefixes | ||
const vendorPrefixes = properties.filter((p) => p.stats.isVendorPrefixed) | ||
const uniqueVendorPrefixes = uniqueWithCount(vendorPrefixes).map(stripUnique) | ||
|
||
return [ | ||
{ | ||
id: 'properties.total', | ||
value: properties.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'properties.unique.total', | ||
value: unique.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'properties.unique.ratio', | ||
value: unique.length / properties.length, | ||
format: FORMATS.RATIO, | ||
aggregate: AGGREGATES.AVERAGE, | ||
}, | ||
{ | ||
id: 'properties.unique', | ||
value: unique, | ||
format: FORMATS.PROPERTY, | ||
aggregate: AGGREGATES.LIST, | ||
}, | ||
{ | ||
id: 'properties.prefixed.total', | ||
value: vendorPrefixes.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'properties.prefixed.unique', | ||
value: uniqueVendorPrefixes, | ||
format: FORMATS.PROPERTY, | ||
aggregate: AGGREGATES.LIST, | ||
}, | ||
{ | ||
id: 'properties.prefixed.unique.total', | ||
value: uniqueVendorPrefixes.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'properties.prefixed.ratio', | ||
value: vendorPrefixes.length / properties.length, | ||
format: FORMATS.PROPERTY, | ||
aggregate: AGGREGATES.LIST, | ||
}, | ||
{ | ||
id: 'properties.browserhacks.total', | ||
value: browserhacks.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'properties.browserhacks.unique', | ||
value: uniqueBrowserhacks, | ||
format: FORMATS.PROPERTY, | ||
aggregate: AGGREGATES.LIST, | ||
}, | ||
{ | ||
id: 'properties.browserhacks.unique.total', | ||
value: uniqueBrowserhacks.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'properties.browserhacks.ratio', | ||
value: browserhacks.length / properties.length, | ||
format: FORMATS.PROPERTY, | ||
aggregate: AGGREGATES.LIST, | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const { FORMATS, AGGREGATES } = require('./_types') | ||
const { stripRuleAnalysis } = require('../analyze') | ||
|
||
module.exports = ({ rules }) => { | ||
const empty = rules.filter((r) => r.stats.isEmpty) | ||
const declarations = rules | ||
.map((rule) => rule.declarations) | ||
.reduce((all, current) => all.concat(current), []) | ||
const selectors = rules | ||
.map((rule) => rule.selectors) | ||
.reduce((all, current) => all.concat(current), []) | ||
|
||
let maxDeclarationCount = 0 | ||
let rulesWithMostDeclarations = [] | ||
|
||
let maxSelectorCount = 0 | ||
let rulesWithMostSelectors = [] | ||
|
||
for (let rule of rules) { | ||
// DECLARATIONS | ||
const declarationCount = rule.declarations.length | ||
|
||
if (declarationCount > maxDeclarationCount) { | ||
maxDeclarationCount = declarationCount | ||
rulesWithMostDeclarations = [] | ||
} | ||
|
||
if (declarationCount === maxDeclarationCount) { | ||
rulesWithMostDeclarations.push(rule) | ||
} | ||
|
||
// SELECTORS | ||
const selectorCount = rule.selectors.length | ||
|
||
if (selectorCount > maxSelectorCount) { | ||
maxSelectorCount = selectorCount | ||
rulesWithMostSelectors = [] | ||
} | ||
|
||
if (selectorCount === maxSelectorCount) { | ||
rulesWithMostSelectors.push(rule) | ||
} | ||
} | ||
|
||
return [ | ||
{ | ||
id: 'rules.total', | ||
value: rules.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'rules.empty.total', | ||
value: empty.length, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'rules.empty.ratio', | ||
value: empty.length / rules.length, | ||
format: FORMATS.RATIO, | ||
aggregate: AGGREGATES.AVERAGE, | ||
}, | ||
{ | ||
id: 'rules.selectors.average', | ||
value: selectors.length / rules.length, | ||
format: FORMATS.RATIO, | ||
aggregate: AGGREGATES.AVERAGE, | ||
}, | ||
{ | ||
id: 'rules.selectors.maximum.total', | ||
value: maxSelectorCount, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'rules.selectors.maximum.selectors', | ||
value: rulesWithMostSelectors.map(stripRuleAnalysis), | ||
format: FORMATS.SELECTOR, | ||
aggregate: AGGREGATES.LIST, | ||
}, | ||
{ | ||
id: 'rules.declarations.average', | ||
value: declarations.length / rules.length, | ||
format: FORMATS.RATIO, | ||
aggregate: AGGREGATES.AVERAGE, | ||
}, | ||
{ | ||
id: 'rules.declarations.maximum.total', | ||
value: maxDeclarationCount, | ||
format: FORMATS.COUNT, | ||
aggregate: AGGREGATES.SUM, | ||
}, | ||
{ | ||
id: 'rules.declarations.maximum.declarations', | ||
value: rulesWithMostDeclarations.map(stripRuleAnalysis), | ||
format: FORMATS.DECLARATION, | ||
aggregate: AGGREGATES.LIST, | ||
}, | ||
] | ||
} |
Oops, something went wrong.