@caweb/cli 1.4.4 → 1.5.0
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/commands/index.js +13 -19
- package/commands/webpack/webpack.js +19 -102
- package/lib/cli.js +130 -124
- package/lib/helpers.js +3 -5
- package/lib/index.js +12 -18
- package/package.json +5 -28
- package/bin/css-audit/.editorconfig +0 -12
- package/bin/css-audit/.github/workflows/build-report.yml +0 -46
- package/bin/css-audit/.github/workflows/merge-trunk-to-report.yml +0 -17
- package/bin/css-audit/.github/workflows/node.yaml +0 -32
- package/bin/css-audit/.nvmrc +0 -1
- package/bin/css-audit/README.md +0 -131
- package/bin/css-audit/css-audit.config.js +0 -13
- package/bin/css-audit/index.js +0 -38
- package/bin/css-audit/package-lock.json +0 -6689
- package/bin/css-audit/package.json +0 -56
- package/bin/css-audit/public/.gitkeep +0 -1
- package/bin/css-audit/src/__tests__/alphas.js +0 -128
- package/bin/css-audit/src/__tests__/colors.js +0 -115
- package/bin/css-audit/src/__tests__/display-none.js +0 -52
- package/bin/css-audit/src/__tests__/important.js +0 -88
- package/bin/css-audit/src/__tests__/media-queries.js +0 -84
- package/bin/css-audit/src/__tests__/property-values.js +0 -55
- package/bin/css-audit/src/__tests__/run.js +0 -25
- package/bin/css-audit/src/__tests__/selectors.js +0 -66
- package/bin/css-audit/src/audits/alphas.js +0 -70
- package/bin/css-audit/src/audits/colors.js +0 -83
- package/bin/css-audit/src/audits/display-none.js +0 -39
- package/bin/css-audit/src/audits/important.js +0 -60
- package/bin/css-audit/src/audits/media-queries.js +0 -96
- package/bin/css-audit/src/audits/property-values.js +0 -65
- package/bin/css-audit/src/audits/selectors.js +0 -67
- package/bin/css-audit/src/audits/typography.js +0 -41
- package/bin/css-audit/src/formats/cli-table.js +0 -81
- package/bin/css-audit/src/formats/html/_audit-alpha.twig +0 -23
- package/bin/css-audit/src/formats/html/_audit-colors.twig +0 -23
- package/bin/css-audit/src/formats/html/_audit-default.twig +0 -24
- package/bin/css-audit/src/formats/html/index.twig +0 -88
- package/bin/css-audit/src/formats/html/style.css +0 -341
- package/bin/css-audit/src/formats/html.js +0 -52
- package/bin/css-audit/src/formats/json.js +0 -9
- package/bin/css-audit/src/run.js +0 -76
- package/bin/css-audit/src/utils/__tests__/cli.js +0 -70
- package/bin/css-audit/src/utils/__tests__/example-config.config.js +0 -12
- package/bin/css-audit/src/utils/__tests__/get-specificity.js +0 -39
- package/bin/css-audit/src/utils/cli.js +0 -133
- package/bin/css-audit/src/utils/format-report.js +0 -37
- package/bin/css-audit/src/utils/get-specificity.js +0 -97
- package/bin/css-audit/src/utils/get-values-count.js +0 -17
- package/lib/webpack/plugins/css-audit/css-audit.config.cjs +0 -5
- package/lib/webpack/plugins/css-audit/default.config.js +0 -19
- package/lib/webpack/plugins/css-audit/index.js +0 -297
- package/lib/webpack/plugins/css-audit/package.json +0 -12
- package/lib/webpack/plugins/jshint/.jshintrc +0 -31
- package/lib/webpack/plugins/jshint/index.js +0 -286
- package/lib/webpack/plugins/jshint/package-lock.json +0 -22
- package/lib/webpack/plugins/jshint/package.json +0 -15
- package/lib/webpack/plugins/jshint/reporter.cjs +0 -663
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const { parse } = require( 'postcss' );
|
|
5
|
-
const { parse: parseValue } = require( 'postcss-values-parser' );
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
const getValuesCount = require( '../utils/get-values-count' );
|
|
11
|
-
|
|
12
|
-
module.exports = function ( files = [] ) {
|
|
13
|
-
const alphas = [];
|
|
14
|
-
const colors = [];
|
|
15
|
-
|
|
16
|
-
files.forEach( ( { content, name } ) => {
|
|
17
|
-
const root = parse( content, { from: name } );
|
|
18
|
-
root.walkDecls( function ( { value } ) {
|
|
19
|
-
try {
|
|
20
|
-
const valueRoot = parseValue( value, {
|
|
21
|
-
ignoreUnknownWords: true,
|
|
22
|
-
} );
|
|
23
|
-
|
|
24
|
-
valueRoot.walkFuncs( ( node ) => {
|
|
25
|
-
if ( node.isColor && node.nodes.length ) {
|
|
26
|
-
const values = node.nodes
|
|
27
|
-
.filter( ( n ) => 'numeric' === n.type )
|
|
28
|
-
.map( ( n ) => Number( n.value ) );
|
|
29
|
-
if ( values.length === 4 ) {
|
|
30
|
-
alphas.push( values[ 3 ] );
|
|
31
|
-
colors.push( node.toString() );
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
} );
|
|
35
|
-
} catch ( error ) {}
|
|
36
|
-
} );
|
|
37
|
-
} );
|
|
38
|
-
|
|
39
|
-
const uniqAlphas = [ ...new Set( alphas ) ];
|
|
40
|
-
const alphasByCount = getValuesCount( alphas );
|
|
41
|
-
const uniqColors = [ ...new Set( colors ) ];
|
|
42
|
-
|
|
43
|
-
return {
|
|
44
|
-
audit: 'alphas',
|
|
45
|
-
name: 'Opacities',
|
|
46
|
-
template: 'alpha',
|
|
47
|
-
results: [
|
|
48
|
-
{
|
|
49
|
-
id: 'unique',
|
|
50
|
-
label: 'Number of unique alphas',
|
|
51
|
-
value: uniqAlphas.length,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: 'unique-colors',
|
|
55
|
-
label: 'Number of colors with opacity',
|
|
56
|
-
value: uniqColors.length,
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
id: 'all-alphas',
|
|
60
|
-
label: 'List of all alphas',
|
|
61
|
-
value: alphasByCount,
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
id: 'all-colors',
|
|
65
|
-
label: 'List of all colors with opacity',
|
|
66
|
-
value: uniqColors.sort(),
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
70
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const { parse } = require( 'postcss' );
|
|
5
|
-
const { parse: parseValue } = require( 'postcss-values-parser' );
|
|
6
|
-
const tinycolor2 = require( 'tinycolor2' );
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Internal dependencies
|
|
10
|
-
*/
|
|
11
|
-
const getValuesCount = require( '../utils/get-values-count' );
|
|
12
|
-
|
|
13
|
-
module.exports = function ( files = [] ) {
|
|
14
|
-
const colors = [];
|
|
15
|
-
|
|
16
|
-
files.forEach( ( { content, name } ) => {
|
|
17
|
-
const root = parse( content, { from: name } );
|
|
18
|
-
root.walkDecls( function ( { value } ) {
|
|
19
|
-
try {
|
|
20
|
-
const valueRoot = parseValue( value, {
|
|
21
|
-
ignoreUnknownWords: true,
|
|
22
|
-
} );
|
|
23
|
-
|
|
24
|
-
valueRoot.walkWords( ( node ) => {
|
|
25
|
-
if ( node.isColor ) {
|
|
26
|
-
colors.push( node.value );
|
|
27
|
-
}
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
valueRoot.walkFuncs( ( node ) => {
|
|
31
|
-
if ( node.isColor ) {
|
|
32
|
-
colors.push( node.toString() );
|
|
33
|
-
}
|
|
34
|
-
} );
|
|
35
|
-
} catch ( error ) {}
|
|
36
|
-
} );
|
|
37
|
-
} );
|
|
38
|
-
|
|
39
|
-
const uniqColors = [ ...new Set( colors ) ];
|
|
40
|
-
const colorsByCount = getValuesCount( colors );
|
|
41
|
-
|
|
42
|
-
const uniqOpaqueColors = [
|
|
43
|
-
...new Set(
|
|
44
|
-
uniqColors.map( ( colorStr ) => {
|
|
45
|
-
const color = tinycolor2( colorStr );
|
|
46
|
-
return color.toHexString();
|
|
47
|
-
} )
|
|
48
|
-
),
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
audit: 'colors',
|
|
53
|
-
name: 'Colors',
|
|
54
|
-
template: 'colors',
|
|
55
|
-
results: [
|
|
56
|
-
{
|
|
57
|
-
id: 'unique',
|
|
58
|
-
label: 'Number of unique colors',
|
|
59
|
-
value: uniqColors.length,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
id: 'unique-opaque',
|
|
63
|
-
label: 'Number of unique colors (ignoring opacity)',
|
|
64
|
-
value: uniqOpaqueColors.length,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
id: 'all-colors',
|
|
68
|
-
label: 'List of all colors',
|
|
69
|
-
value: uniqColors,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
id: 'top-10-colors',
|
|
73
|
-
label: 'Top 10 most-used colors',
|
|
74
|
-
value: colorsByCount.slice( 0, 10 ),
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: 'bottom-10-colors',
|
|
78
|
-
label: 'Top 10 least-used colors',
|
|
79
|
-
value: colorsByCount.slice( -10 ).reverse(),
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
};
|
|
83
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const { parse } = require( 'postcss' );
|
|
5
|
-
|
|
6
|
-
module.exports = function ( files = [] ) {
|
|
7
|
-
const instances = [];
|
|
8
|
-
|
|
9
|
-
files.forEach( ( { name, content } ) => {
|
|
10
|
-
const root = parse( content, { from: name } );
|
|
11
|
-
root.walkDecls( function ( { parent, prop, value } ) {
|
|
12
|
-
if ( 'display' === prop ) {
|
|
13
|
-
if ( 'none' === value ) {
|
|
14
|
-
instances.push( {
|
|
15
|
-
file: name,
|
|
16
|
-
selector: parent.selector,
|
|
17
|
-
} );
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
} );
|
|
21
|
-
} );
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
audit: 'display-none',
|
|
25
|
-
name: 'Display: None',
|
|
26
|
-
results: [
|
|
27
|
-
{
|
|
28
|
-
id: 'count',
|
|
29
|
-
label: 'Number of times `display: none` is used',
|
|
30
|
-
value: instances.length,
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
id: 'instances',
|
|
34
|
-
label: 'Places where `display: none` is used',
|
|
35
|
-
value: instances,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const { parse } = require( 'postcss' );
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
const getValuesCount = require( '../utils/get-values-count' );
|
|
10
|
-
|
|
11
|
-
module.exports = function ( files = [] ) {
|
|
12
|
-
let count = 0;
|
|
13
|
-
const properties = [];
|
|
14
|
-
const fileInstances = [];
|
|
15
|
-
|
|
16
|
-
files.forEach( ( { name, content } ) => {
|
|
17
|
-
let fileCount = 0;
|
|
18
|
-
const root = parse( content, { from: name } );
|
|
19
|
-
root.walkDecls( function ( { important, prop } ) {
|
|
20
|
-
if ( important ) {
|
|
21
|
-
count++;
|
|
22
|
-
fileCount++;
|
|
23
|
-
properties.push( prop );
|
|
24
|
-
}
|
|
25
|
-
} );
|
|
26
|
-
fileInstances.push( {
|
|
27
|
-
name,
|
|
28
|
-
count: fileCount,
|
|
29
|
-
// Get a ratio of !important per line.
|
|
30
|
-
perLine: fileCount / content.split( '\n' ).length,
|
|
31
|
-
} );
|
|
32
|
-
} );
|
|
33
|
-
|
|
34
|
-
const propertiesByCount = getValuesCount( properties );
|
|
35
|
-
const instancesPerFile = fileInstances
|
|
36
|
-
.filter( ( row ) => row.count > 0 )
|
|
37
|
-
.sort( ( a, b ) => b.count - a.count );
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
audit: 'important',
|
|
41
|
-
name: 'Important Overrides',
|
|
42
|
-
results: [
|
|
43
|
-
{
|
|
44
|
-
id: 'count',
|
|
45
|
-
label: 'Number of times `!important` is used',
|
|
46
|
-
value: count,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
id: 'count-per-file',
|
|
50
|
-
label: 'Number of times `!important` is used per file',
|
|
51
|
-
value: instancesPerFile,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: 'top-10-properties',
|
|
55
|
-
label: 'Top properties that use !important',
|
|
56
|
-
value: propertiesByCount.slice( 0, 10 ),
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
};
|
|
60
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const csstree = require( 'css-tree' );
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
const getValuesCount = require( '../utils/get-values-count' );
|
|
10
|
-
|
|
11
|
-
module.exports = function ( files = [] ) {
|
|
12
|
-
const allQueries = [];
|
|
13
|
-
const allSizes = [];
|
|
14
|
-
const nonWidthQueries = [];
|
|
15
|
-
files.forEach( ( { content } ) => {
|
|
16
|
-
const ast = csstree.parse( content );
|
|
17
|
-
csstree.walk( ast, {
|
|
18
|
-
visit: 'MediaQuery',
|
|
19
|
-
enter( node ) {
|
|
20
|
-
if ( node.children ) {
|
|
21
|
-
allQueries.push( csstree.generate( node ) );
|
|
22
|
-
}
|
|
23
|
-
csstree.walk( node, {
|
|
24
|
-
visit: 'MediaFeature',
|
|
25
|
-
enter( sizeNode ) {
|
|
26
|
-
if (
|
|
27
|
-
sizeNode.name === 'max-width' ||
|
|
28
|
-
sizeNode.name === 'min-width'
|
|
29
|
-
) {
|
|
30
|
-
if (
|
|
31
|
-
sizeNode.value &&
|
|
32
|
-
sizeNode.value.type === 'Dimension'
|
|
33
|
-
) {
|
|
34
|
-
allSizes.push(
|
|
35
|
-
csstree.generate( sizeNode.value )
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
nonWidthQueries.push(
|
|
40
|
-
csstree.generate( sizeNode )
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
} );
|
|
45
|
-
},
|
|
46
|
-
} );
|
|
47
|
-
} );
|
|
48
|
-
|
|
49
|
-
const uniqQueries = [ ...new Set( allQueries ) ];
|
|
50
|
-
const uniqSizes = [ ...new Set( allSizes ) ];
|
|
51
|
-
const queriesByCount = getValuesCount( allQueries );
|
|
52
|
-
const sizesByCount = getValuesCount( allSizes );
|
|
53
|
-
const nonWidthByCount = getValuesCount( nonWidthQueries );
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
audit: 'media-queries',
|
|
57
|
-
name: 'Media Queries',
|
|
58
|
-
results: [
|
|
59
|
-
{
|
|
60
|
-
id: 'count',
|
|
61
|
-
label: 'Number of total media queries',
|
|
62
|
-
value: allQueries.length,
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: 'count-unique-queries',
|
|
66
|
-
label: 'Number of seemingly-unique media queries',
|
|
67
|
-
value: uniqQueries.length,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: 'top-10-queries',
|
|
71
|
-
label: 'Top 10 most-used media queries',
|
|
72
|
-
value: queriesByCount.slice( 0, 10 ),
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
id: 'count-unique-sizes',
|
|
76
|
-
label: 'Number of unique breakpoint sizes',
|
|
77
|
-
value: uniqSizes.length,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
id: 'top-10-sizes',
|
|
81
|
-
label: 'Top 10 most-used breakpoint sizes',
|
|
82
|
-
value: sizesByCount.slice( 0, 10 ),
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
id: 'bottom-10-sizes',
|
|
86
|
-
label: 'Top 10 least-used breakpoint sizes',
|
|
87
|
-
value: sizesByCount.slice( -10 ).reverse(),
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
id: 'non-width',
|
|
91
|
-
label: 'Non-width related media queries',
|
|
92
|
-
value: nonWidthByCount,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
};
|
|
96
|
-
};
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const { parse } = require( 'postcss' );
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
const getValuesCount = require( '../utils/get-values-count' );
|
|
10
|
-
|
|
11
|
-
module.exports = function ( files = [], properties = [] ) {
|
|
12
|
-
const values = [];
|
|
13
|
-
if ( ! Array.isArray( properties ) ) {
|
|
14
|
-
properties = Array( properties );
|
|
15
|
-
}
|
|
16
|
-
// Skip out if no properties are passed in.
|
|
17
|
-
if ( ! properties.length ) {
|
|
18
|
-
return { results: [] };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
files.forEach( ( { content, name } ) => {
|
|
22
|
-
const root = parse( content, { from: name } );
|
|
23
|
-
root.walkDecls( function ( { prop, value } ) {
|
|
24
|
-
if ( -1 !== properties.indexOf( prop ) ) {
|
|
25
|
-
values.push( value );
|
|
26
|
-
}
|
|
27
|
-
} );
|
|
28
|
-
} );
|
|
29
|
-
|
|
30
|
-
const uniqueValues = [ ...new Set( values ) ];
|
|
31
|
-
const valuesByCount = getValuesCount( values );
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
audit: 'property-values',
|
|
35
|
-
name: `Property Values: ${ properties.join( ', ' ) }`,
|
|
36
|
-
results: [
|
|
37
|
-
{
|
|
38
|
-
id: 'count',
|
|
39
|
-
label: `Number of values for ${ properties.join( ', ' ) }`,
|
|
40
|
-
value: values.length,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
id: 'count-unique',
|
|
44
|
-
label: `Number of unique values for ${ properties.join(
|
|
45
|
-
', '
|
|
46
|
-
) }`,
|
|
47
|
-
value: uniqueValues.length,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
id: 'top-10-values',
|
|
51
|
-
label: `Top 10 most-used values for ${ properties.join(
|
|
52
|
-
', '
|
|
53
|
-
) }`,
|
|
54
|
-
value: valuesByCount.slice( 0, 10 ),
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
id: 'bottom-10-values',
|
|
58
|
-
label: `Top 10 least-used values for ${ properties.join(
|
|
59
|
-
', '
|
|
60
|
-
) }`,
|
|
61
|
-
value: valuesByCount.slice( -10 ).reverse(),
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
};
|
|
65
|
-
};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const { parse } = require( 'postcss' );
|
|
5
|
-
|
|
6
|
-
const { getSpecificityArray } = require( '../utils/get-specificity' );
|
|
7
|
-
|
|
8
|
-
module.exports = function ( files = [] ) {
|
|
9
|
-
// let longest = 0;
|
|
10
|
-
const selectors = [];
|
|
11
|
-
|
|
12
|
-
files.forEach( ( { name, content } ) => {
|
|
13
|
-
const root = parse( content, { from: name } );
|
|
14
|
-
root.walkRules( function ( { selector } ) {
|
|
15
|
-
const selectorList = selector.split( ',' );
|
|
16
|
-
selectorList.forEach( ( selectorName ) => {
|
|
17
|
-
// Remove excess whitespace from selectors.
|
|
18
|
-
selectorName = selectorName.replace( /\s+/g, ' ' ).trim();
|
|
19
|
-
const [ a, b, c ] = getSpecificityArray( selectorName );
|
|
20
|
-
const sum = 100 * a + 10 * b + c; // eslint-disable-line no-mixed-operators
|
|
21
|
-
selectors.push( {
|
|
22
|
-
file: name,
|
|
23
|
-
selector: selectorName,
|
|
24
|
-
a,
|
|
25
|
-
b,
|
|
26
|
-
c,
|
|
27
|
-
sum,
|
|
28
|
-
} );
|
|
29
|
-
} );
|
|
30
|
-
} );
|
|
31
|
-
} );
|
|
32
|
-
|
|
33
|
-
// Reverse sort to be highest -> lowest.
|
|
34
|
-
selectors.sort( ( a, b ) => b.sum - a.sum );
|
|
35
|
-
const selectorsByLength = [ ...selectors ].sort(
|
|
36
|
-
( a, b ) => b.selector.length - a.selector.length
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const selectorsWithIds = selectors.filter( ( { a } ) => a > 0 );
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
audit: 'selectors',
|
|
43
|
-
name: 'Selectors',
|
|
44
|
-
results: [
|
|
45
|
-
{
|
|
46
|
-
id: 'count',
|
|
47
|
-
label: 'Total number of selectors',
|
|
48
|
-
value: selectors.length,
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: 'count-with-ids',
|
|
52
|
-
label: 'Number of selectors with IDs',
|
|
53
|
-
value: selectorsWithIds.length,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
id: 'top-10-selectors',
|
|
57
|
-
label: 'Top 10 selectors with the highest specificity',
|
|
58
|
-
value: selectors.slice( 0, 10 ),
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
id: 'bottom-10-selectors',
|
|
62
|
-
label: 'Top 10 selectors by length',
|
|
63
|
-
value: selectorsByLength.slice( 0, 10 ),
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
};
|
|
67
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
const propertyValues = require( './property-values' );
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Run the property values audit with specific properties
|
|
8
|
-
* as a single audit.
|
|
9
|
-
*
|
|
10
|
-
* @param {array} files
|
|
11
|
-
*
|
|
12
|
-
* @returns Object containing audit data.
|
|
13
|
-
*/
|
|
14
|
-
module.exports = function ( files = [] ) {
|
|
15
|
-
const properties = [
|
|
16
|
-
'font-family',
|
|
17
|
-
'font-size',
|
|
18
|
-
'font-style',
|
|
19
|
-
'font-weight',
|
|
20
|
-
'line-height',
|
|
21
|
-
'letter-spacing',
|
|
22
|
-
'text-align',
|
|
23
|
-
'text-decoration',
|
|
24
|
-
'text-indent',
|
|
25
|
-
'text-overflow',
|
|
26
|
-
'text-shadow',
|
|
27
|
-
'text-transform',
|
|
28
|
-
'white-space',
|
|
29
|
-
'word-break',
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
const results = properties.map( ( property ) => {
|
|
33
|
-
return propertyValues( files, property ).results;
|
|
34
|
-
} );
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
audit: 'typography',
|
|
38
|
-
name: `Typography`,
|
|
39
|
-
results: results.flat(),
|
|
40
|
-
};
|
|
41
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
const colors = require( 'colors' );
|
|
2
|
-
const Table = require( 'cli-table3' );
|
|
3
|
-
|
|
4
|
-
const tableSettings = {
|
|
5
|
-
chars: {
|
|
6
|
-
top: '-',
|
|
7
|
-
'top-mid': '-',
|
|
8
|
-
'top-left': ' ',
|
|
9
|
-
'top-right': ' ',
|
|
10
|
-
bottom: '-',
|
|
11
|
-
'bottom-mid': '-',
|
|
12
|
-
'bottom-left': ' ',
|
|
13
|
-
'bottom-right': ' ',
|
|
14
|
-
left: '|',
|
|
15
|
-
'left-mid': '|',
|
|
16
|
-
mid: '-',
|
|
17
|
-
'mid-mid': '|',
|
|
18
|
-
right: '|',
|
|
19
|
-
'right-mid': '|',
|
|
20
|
-
middle: '│',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Convert the report data to a JSON string.
|
|
26
|
-
*
|
|
27
|
-
* The report value can be as a plain string, an array, or an array of objects
|
|
28
|
-
* to be rendered by `Table`. This expects the cli supports color output.
|
|
29
|
-
*
|
|
30
|
-
* @param {Object} report An indvidual audit result.
|
|
31
|
-
* @param {string} report.label A human-readable string describing the results.
|
|
32
|
-
* @param {string|string[]|Object[]} report.value The result for this audit.
|
|
33
|
-
* @return {string} A formatted string for output on cli.
|
|
34
|
-
*/
|
|
35
|
-
function formatReport( { label, value } ) {
|
|
36
|
-
let valueString = value;
|
|
37
|
-
|
|
38
|
-
if ( Array.isArray( value ) && value.length ) {
|
|
39
|
-
let table = '';
|
|
40
|
-
if ( 'object' === typeof value[ 0 ] ) {
|
|
41
|
-
tableSettings.head = Object.keys( value[ 0 ] );
|
|
42
|
-
table = new Table( tableSettings );
|
|
43
|
-
value.forEach( ( row ) => {
|
|
44
|
-
table.push(
|
|
45
|
-
Object.values( row ).map( ( item ) => {
|
|
46
|
-
item = String( item );
|
|
47
|
-
if ( item.length > 80 ) {
|
|
48
|
-
return item.slice( 0, 80 ) + '…';
|
|
49
|
-
}
|
|
50
|
-
return item;
|
|
51
|
-
} )
|
|
52
|
-
);
|
|
53
|
-
} );
|
|
54
|
-
} else {
|
|
55
|
-
table = new Table( tableSettings );
|
|
56
|
-
value.forEach( ( row ) => {
|
|
57
|
-
table.push( [ row ] );
|
|
58
|
-
} );
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
valueString = table.toString();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return `${ colors.green.bold( label ) }:\n${ valueString }\n\n`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Convert the report data to a JSON string.
|
|
69
|
-
*
|
|
70
|
-
* @param {Array<Array<Object>>} reports The list of report data.
|
|
71
|
-
* @return {string} reports as a JSON string.
|
|
72
|
-
*/
|
|
73
|
-
module.exports = function ( reports ) {
|
|
74
|
-
reports.map( ( { results } ) => results );
|
|
75
|
-
return reports.map( ( { name, results } ) => {
|
|
76
|
-
return (
|
|
77
|
-
`${ colors.magenta.bold( name ) }\n\n` +
|
|
78
|
-
results.map( formatReport ).join( '' )
|
|
79
|
-
);
|
|
80
|
-
} );
|
|
81
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{% for item in data.results %}
|
|
2
|
-
{% if item.value is iterable %}
|
|
3
|
-
<h3>{{item.label}}</h3>
|
|
4
|
-
<ul>
|
|
5
|
-
{% for value in item.value %}
|
|
6
|
-
|
|
7
|
-
{% if value.name or value.name == '0' %}
|
|
8
|
-
<li class="chip is-transparent" style="--chip-bg-color:{{value.name}};">
|
|
9
|
-
<span class="count">{{value.count}}</span>
|
|
10
|
-
{{value.name}}
|
|
11
|
-
</li>
|
|
12
|
-
{% else %}
|
|
13
|
-
<li class="chip is-transparent" style="--chip-bg-color:{{value}};">
|
|
14
|
-
{{value}}
|
|
15
|
-
</li>
|
|
16
|
-
{% endif %}
|
|
17
|
-
|
|
18
|
-
{% endfor %}
|
|
19
|
-
</ul>
|
|
20
|
-
{% else %}
|
|
21
|
-
<h3>{{ item.label}}: {{ item.value }}</h3>
|
|
22
|
-
{% endif %}
|
|
23
|
-
{% endfor %}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{% for item in data.results %}
|
|
2
|
-
{% if item.value is iterable %}
|
|
3
|
-
<h3>{{item.label}}</h3>
|
|
4
|
-
<ul>
|
|
5
|
-
{% for value in item.value %}
|
|
6
|
-
|
|
7
|
-
{% if value.name %}
|
|
8
|
-
<li class="chip" style="--chip-bg-color:{{value.name}};">
|
|
9
|
-
<span class="count">{{value.count}}</span>
|
|
10
|
-
{{value.name}}
|
|
11
|
-
</li>
|
|
12
|
-
{% else %}
|
|
13
|
-
<li class="chip" style="--chip-bg-color:{{value}};">
|
|
14
|
-
{{value}}
|
|
15
|
-
</li>
|
|
16
|
-
{% endif %}
|
|
17
|
-
|
|
18
|
-
{% endfor %}
|
|
19
|
-
</ul>
|
|
20
|
-
{% else %}
|
|
21
|
-
<h3>{{ item.label}}: {{ item.value }}</h3>
|
|
22
|
-
{% endif %}
|
|
23
|
-
{% endfor %}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{% for item in data.results %}
|
|
2
|
-
{% if item.value is iterable %}
|
|
3
|
-
<h3>{{item.label}}</h3>
|
|
4
|
-
<ol>
|
|
5
|
-
{% for value in item.value %}
|
|
6
|
-
{% if value.name %}
|
|
7
|
-
<li>
|
|
8
|
-
<span class="count">{{value.count}}</span>
|
|
9
|
-
<em>{{value.name}}</em>
|
|
10
|
-
</li>
|
|
11
|
-
{% endif %}
|
|
12
|
-
|
|
13
|
-
{% if value.file %}
|
|
14
|
-
<li>
|
|
15
|
-
<code>{{value.selector}}</code><br />
|
|
16
|
-
<em>{{value.file}}</em>
|
|
17
|
-
</li>
|
|
18
|
-
{% endif %}
|
|
19
|
-
{% endfor %}
|
|
20
|
-
</ol>
|
|
21
|
-
{% else %}
|
|
22
|
-
<h3>{{item.label}}: <span class="count">{{item.value}}</span></h3>
|
|
23
|
-
{% endif %}
|
|
24
|
-
{% endfor %}
|