Skip to content

Commit

Permalink
Merge e3b2f19 into ac8355f
Browse files Browse the repository at this point in the history
  • Loading branch information
bartveneman committed Apr 15, 2020
2 parents ac8355f + e3b2f19 commit 7b4dbb4
Show file tree
Hide file tree
Showing 126 changed files with 2,480 additions and 13,789 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
/node_modules
.nyc_output
coverage
.DS_Store
6,186 changes: 490 additions & 5,696 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 20 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@
"parker",
"performance",
"styleguide",
"metrics"
"metrics",
"selector",
"value",
"declaration",
"property",
"rule",
"atrule"
],
"main": "src/analyzer/index.js",
"main": "src/index.js",
"files": [
"src"
],
"scripts": {
"test": "xo && nyc ava"
},
"xo": {
"space": true,
"semicolon": false,
"rules": {
"operator-linebreak": "off",
"space-before-function-paren": "off"
}
"test": "nyc ava -v"
},
"prettier": {
"useTabs": true,
"semi": false,
"singleQuote": true,
"bracketSpacing": false,
"overrides": [
{
"files": "*.json",
Expand All @@ -55,23 +53,13 @@
},
"dependencies": {
"color-sorter": "^4.0.1",
"css-at-supports-browser-h4cks-analyzer": "^2.0.0",
"css-media-query-browser-h4cks-analyzer": "^2.0.0",
"css-property-browser-h4cks-analyzer": "^2.0.0",
"css-selector-browser-h4cks-analyzer": "^2.0.0",
"css-selector-complexity": "^0.1.2",
"css-selector-parser": "^1.4.1",
"css-shorthand-expand": "^1.2.0",
"css-time-sort": "^1.0.0",
"css-tree": "^1.0.0-alpha.39",
"css-unit-sort": "^3.3.1",
"css-value-browser-h4cks-analyzer": "^2.0.0",
"flat": "^5.0.0",
"gzip-size": "^5.1.1",
"is-vendor-prefixed": "^3.3.1",
"path": "^0.12.7",
"postcss": "^7.0.27",
"postcss-values-parser": "^3.1.1",
"specificity": "^0.4.1",
"split-css-value": "^0.1.1",
"split-lines": "^2.0.0",
"string-natural-compare": "^3.0.1",
"tinycolor2": "^1.4.1",
Expand All @@ -81,12 +69,19 @@
"ava": "^3.5.0",
"coveralls": "^3.0.9",
"nyc": "^15.0.0",
"xo": "^0.28.0"
"prettier": "^2.0.4"
},
"nyc": {
"reporter": [
"lcov",
"text"
]
},
"ava": {
"files": [
"test/**/*.js",
"src/node_modules/**/test.js",
"src/node_modules/**/test/*.js"
]
}
}
21 changes: 21 additions & 0 deletions src/aggregates/_types.js
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',
}
43 changes: 43 additions & 0 deletions src/aggregates/declarations.js
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,
},
]
}
18 changes: 18 additions & 0 deletions src/aggregates/index.js
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
}, {})
}
102 changes: 102 additions & 0 deletions src/aggregates/properties.js
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,
},
]
}
101 changes: 101 additions & 0 deletions src/aggregates/rules.js
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,
},
]
}
Loading

0 comments on commit 7b4dbb4

Please sign in to comment.