Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.

Commit ae017ec

Browse files
committedJul 28, 2015
Use standard
·
v3.2.02.1.0
1 parent 018399b commit ae017ec

File tree

13 files changed

+133
-127
lines changed

13 files changed

+133
-127
lines changed
 

‎.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838

3939
// Personal styling preferences.
40+
"asi" : true,
4041
"newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
4142
"noempty" : true, // Prohibit use of empty blocks.
4243
"nomen" : true, // Prohibit use of initial or trailing underbars in names.

‎bin/cssstats.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
#!/usr/bin/env node
22

3-
var program = require('commander');
4-
var cssstats = require('..');
5-
var fs = require('fs');
6-
var stdin = require('stdin');
3+
var program = require('commander')
4+
var cssstats = require('..')
5+
var fs = require('fs')
6+
var stdin = require('stdin')
77

88
var version = '1.6.0'
99

10-
console.log('CSS Statistics CLI (' + version + ')');
10+
console.log('CSS Statistics CLI (' + version + ')')
1111

1212
program
13-
.version(version);
13+
.version(version)
1414

1515
program
1616
.command('file [file]')
1717
.description('read a local css file')
18-
.action(function(file) {
18+
.action(function (file) {
1919
if (!file) {
20-
console.log('Please specify a CSS file');
21-
return;
20+
console.log('Please specify a CSS file')
21+
return
2222
}
2323

2424
try {
25-
var css = fs.readFileSync(file, 'utf8');
26-
console.log(JSON.stringify(cssstats(css), null, 2));
25+
var css = fs.readFileSync(file, 'utf8')
26+
console.log(JSON.stringify(cssstats(css), null, 2))
2727
} catch (e) {
28-
console.log('CSS Statistics encountered an error reading ' + file);
29-
console.log(e);
28+
console.log('CSS Statistics encountered an error reading ' + file)
29+
console.log(e)
3030
}
31-
});
31+
})
3232

33-
program.parse(process.argv);
33+
program.parse(process.argv)
3434

3535
if (!program.args.length) {
36-
console.log('Input some CSS\n^C to cancel\n^D when complete');
36+
console.log('Input some CSS\n^C to cancel\n^D when complete')
3737

38-
stdin(function(css) {
38+
stdin(function (css) {
3939
if (css) {
40-
console.log(JSON.stringify(cssstats(css), null, 2));
40+
console.log(JSON.stringify(cssstats(css), null, 2))
4141
}
42-
});
42+
})
4343
}

‎index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ var selectors = require('./lib/selectors')
88
var declarations = require('./lib/declarations')
99
var mediaQueries = require('./lib/media-queries')
1010

11-
module.exports = function(src, opts) {
11+
module.exports = function (src, opts) {
1212

1313
opts = opts || {}
1414
opts = _.defaults(opts, {
15-
safe: true,
16-
// lite: false
15+
safe: true
1716
})
1817

19-
function parse(root, result) {
18+
function parse (root, result) {
2019

2120
var stats = {}
2221

@@ -40,8 +39,8 @@ module.exports = function(src, opts) {
4039
// Push message to PostCSS when used as a plugin
4140
if (result && result.messages) {
4241
result.messages.push({
43-
type: 'cssstats',
44-
plugin: 'postcss-cssstats',
42+
type: 'cssstats',
43+
plugin: 'postcss-cssstats',
4544
stats: stats
4645
})
4746
}
@@ -63,6 +62,5 @@ module.exports = function(src, opts) {
6362
throw new TypeError('cssstats expects a string or to be used as a PostCSS plugin')
6463
}
6564

66-
6765
}
6866

‎lib/aggregates.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11

2-
module.exports = function(obj) {
2+
module.exports = function (obj) {
33

4-
var result = {};
4+
var result = {}
55

6-
result.selectors = obj.selectors.length || 0;
7-
result.declarations = obj.declarations.all.length || 0;
8-
result.properties = Object.keys(obj.declarations.byProperty) || [];
9-
result.mediaQueries = Object.keys(obj.declarations.byMedia) || [];
6+
result.selectors = obj.selectors.length || 0
7+
result.declarations = obj.declarations.all.length || 0
8+
result.properties = Object.keys(obj.declarations.byProperty) || []
9+
result.mediaQueries = Object.keys(obj.declarations.byMedia) || []
1010

11-
function parseTotalUnique(key) {
12-
var totalUnique = {};
13-
totalUnique.total = obj.declarations.byProperty[key].length || 0;
14-
totalUnique.unique = obj.declarations.unique[key].length || 0;
15-
return totalUnique;
11+
function parseTotalUnique (key) {
12+
var totalUnique = {}
13+
totalUnique.total = obj.declarations.byProperty[key].length || 0
14+
totalUnique.unique = obj.declarations.unique[key].length || 0
15+
return totalUnique
1616
}
1717

18-
result.properties.forEach(function(key) {
19-
result[key] = parseTotalUnique(key);
20-
});
18+
result.properties.forEach(function (key) {
19+
result[key] = parseTotalUnique(key)
20+
})
2121

22-
return result;
22+
return result
2323

24-
};
24+
}

‎lib/declarations.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11

2-
var _ = require('lodash')
3-
var camelCase = require('camelcase')
42
var isVendorPrefixed = require('is-vendor-prefixed')
53

64
// var fontShorthand = require('./util/font-shorthand')
75
// var uniqueDeclarations = require('./util/unique-declarations')
86

9-
module.exports = function(root) {
7+
module.exports = function (root) {
108

119
var result = {
1210
total: 0,
@@ -19,13 +17,13 @@ module.exports = function(root) {
1917
// uniqueDeclarationsCount: 0
2018
}
2119

22-
root.eachRule(function(rule) {
23-
rule.eachDecl(function(declaration) {
20+
root.eachRule(function (rule) {
21+
rule.eachDecl(function (declaration) {
2422

2523
var prop = declaration.prop
2624

2725
result.total++
28-
result.properties[prop] = result.properties[prop] || []
26+
result.properties[prop] = result.properties[prop] || []
2927
result.properties[prop].push(declaration.value)
3028

3129
if (isVendorPrefixed(declaration.prop)) {

‎lib/media-queries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
var _ = require('lodash')
33

4-
module.exports = function(root) {
4+
module.exports = function (root) {
55

66
var result = {
77
total: 0,

‎lib/rules.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11

22
var _ = require('lodash')
33

4-
module.exports = function(root) {
4+
module.exports = function (root) {
55

66
var result = {
77
total: 0,
88
size: {
99
graph: [],
1010
max: 0,
1111
average: 0
12-
},
12+
}
1313
}
1414

15-
root.eachRule(function(rule) {
15+
root.eachRule(function (rule) {
1616
var declarations = 0
17-
rule.nodes.forEach(function(node) {
17+
rule.nodes.forEach(function (node) {
1818
if (node.type === 'decl') {
1919
declarations++
2020
}

‎lib/selectors.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var hasClassSelector = require('has-class-selector')
66
var hasPseudoElement = require('has-pseudo-element')
77
var hasPseudoClass = require('has-pseudo-class')
88

9-
module.exports = function(root) {
9+
module.exports = function (root) {
1010

1111
var result = {
1212
total: 0,
@@ -24,7 +24,7 @@ module.exports = function(root) {
2424
}
2525
}
2626

27-
function specificityGraph(selector) {
27+
function specificityGraph (selector) {
2828
return specificity.calculate(selector)[0]
2929
.specificity
3030
.split(',')
@@ -38,10 +38,9 @@ module.exports = function(root) {
3838
})
3939
}
4040

41-
42-
root.eachRule(function(rule) {
41+
root.eachRule(function (rule) {
4342
var graph
44-
rule.selectors.forEach(function(selector) {
43+
rule.selectors.forEach(function (selector) {
4544
result.total++
4645
result.values.push(selector)
4746

@@ -72,7 +71,7 @@ module.exports = function(root) {
7271
_.clone(result.values)
7372
.sort()
7473
.reduce(function (a, b, i, arr) {
75-
if (b == arr[i - 1] || b == arr[i + 1]) {
74+
if (b === arr[i - 1] || b === arr[i + 1]) {
7675
return a.concat(b)
7776
} else {
7877
return a

‎lib/size.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

2-
module.exports = function(string) {
2+
module.exports = function (string) {
33

4-
return Buffer.byteLength(string, 'utf8');
4+
return Buffer.byteLength(string, 'utf8')
5+
6+
}
57

6-
};

‎lib/util/font-shorthand.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,95 @@
1-
var cssFontParser = require('cssfontparser');
1+
var cssFontParser = require('cssfontparser')
22

3-
module.exports = function handleFontShorthand(obj) {
3+
module.exports = function handleFontShorthand (obj) {
44
if (obj.byProperty.font) {
5-
obj.byProperty.font.forEach(function(fontShorthand) {
6-
var fontProperties = cssFontParser(fontShorthand.value);
5+
obj.byProperty.font.forEach(function (fontShorthand) {
6+
var fontProperties = cssFontParser(fontShorthand.value)
77

88
if (!fontProperties) {
9-
return;
9+
return
1010
}
1111

1212
if (fontProperties.style) {
13-
obj.byProperty.fontStyle = obj.byProperty.fontStyle || [];
13+
obj.byProperty.fontStyle = obj.byProperty.fontStyle || []
1414

1515
obj.byProperty.fontStyle.push(
1616
generateDeclaration(
1717
'font-style',
1818
fontProperties.style,
1919
fontShorthand.index
2020
)
21-
);
21+
)
2222
}
2323

2424
if (fontProperties.variant) {
25-
obj.byProperty.fontVariant = obj.byProperty.fontVariant || [];
25+
obj.byProperty.fontVariant = obj.byProperty.fontVariant || []
2626

2727
obj.byProperty.fontVariant.push(
2828
generateDeclaration(
2929
'font-variant',
3030
fontProperties.variant,
3131
fontShorthand.index
3232
)
33-
);
33+
)
3434
}
3535

3636
if (fontProperties.weight) {
37-
obj.byProperty.fontWeight = obj.byProperty.fontWeight || [];
37+
obj.byProperty.fontWeight = obj.byProperty.fontWeight || []
3838

3939
obj.byProperty.fontWeight.push(
4040
generateDeclaration(
4141
'font-weight',
4242
fontProperties.weight,
4343
fontShorthand.index
4444
)
45-
);
45+
)
4646
}
4747

4848
if (fontProperties.size) {
49-
obj.byProperty.fontSize = obj.byProperty.fontSize || [];
49+
obj.byProperty.fontSize = obj.byProperty.fontSize || []
5050

5151
obj.byProperty.fontSize.push(
5252
generateDeclaration(
5353
'font-size',
5454
fontProperties.size,
5555
fontShorthand.index
5656
)
57-
);
57+
)
5858
}
5959

6060
if (fontProperties.lineHeight) {
61-
obj.byProperty.lineHeight = obj.byProperty.lineHeight || [];
61+
obj.byProperty.lineHeight = obj.byProperty.lineHeight || []
6262

6363
obj.byProperty.lineHeight.push(
6464
generateDeclaration(
6565
'line-height',
6666
fontProperties.lineHeight,
6767
fontShorthand.index
6868
)
69-
);
69+
)
7070
}
7171

7272
if (fontProperties.family) {
73-
obj.byProperty.fontFamily = obj.byProperty.fontFamily || [];
73+
obj.byProperty.fontFamily = obj.byProperty.fontFamily || []
7474

7575
obj.byProperty.fontFamily.push(
7676
generateDeclaration(
7777
'font-family',
7878
fontProperties.family.join(', '),
7979
fontShorthand.index
8080
)
81-
);
81+
)
8282
}
83-
});
83+
})
8484
}
85-
};
85+
}
8686

87-
function generateDeclaration(prop, value, index) {
87+
function generateDeclaration (prop, value, index) {
8888
return {
8989
type: 'decl',
9090
prop: prop,
9191
value: value,
9292
index: index
93-
};
93+
}
9494
}
95+

‎lib/util/unique-declarations.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
var _uniq = require('lodash').uniq;
1+
var _uniq = require('lodash').uniq
22

3-
module.exports = function uniqueDeclarations(obj) {
4-
var uniqueDecls = {};
3+
module.exports = function uniqueDeclarations (obj) {
4+
var uniqueDecls = {}
55

6-
Object.keys(obj.byProperty).forEach(function(propKey){
7-
uniqueDecls[propKey] = _uniq(obj.byProperty[propKey], 'value');
8-
});
6+
Object.keys(obj.byProperty).forEach(function (propKey) {
7+
uniqueDecls[propKey] = _uniq(obj.byProperty[propKey], 'value')
8+
})
9+
10+
return uniqueDecls
11+
}
912

10-
return uniqueDecls;
11-
};

‎package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,12 @@
4747
"jshint": "jshint index.js lib test",
4848
"standard": "standard",
4949
"test": "mocha test"
50+
},
51+
"standard": {
52+
"global": [
53+
"before",
54+
"describe",
55+
"it"
56+
]
5057
}
5158
}

‎test/test.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ var assert = require('assert')
44
var postcss = require('postcss')
55
var cssstats = require('..')
66

7-
describe('css-statistics', function() {
7+
describe('css-statistics', function () {
88
var stats
99

10-
before(function() {
10+
before(function () {
1111
stats = cssstats(fixture('small'))
1212
})
1313

14-
describe('PostCSS plugin', function() {
14+
describe('PostCSS plugin', function () {
1515

16-
it('should be handled correctly', function(done) {
16+
it('should be handled correctly', function (done) {
1717
postcss()
1818
.use(cssstats())
1919
.process(fixture('small'))
@@ -25,100 +25,100 @@ describe('css-statistics', function() {
2525
})
2626
})
2727

28-
describe('base stats', function() {
28+
describe('base stats', function () {
2929

30-
it('should calculate the correct file size', function() {
30+
it('should calculate the correct file size', function () {
3131
assert.equal(stats.size, 827)
3232
})
3333

34-
it('should calculate the correct gzipped file size', function() {
34+
it('should calculate the correct gzipped file size', function () {
3535
assert.equal(stats.gzipSize, 336)
3636
})
3737
})
3838

39-
describe('averages', function() {
39+
describe('averages', function () {
4040

41-
it('should correctly count specificity stats', function() {
41+
it('should correctly count specificity stats', function () {
4242
assert.equal(stats.selectors.specificity.average, 20.272727272727273)
4343
})
4444

45-
it('should correctly count rule size stats', function() {
45+
it('should correctly count rule size stats', function () {
4646
assert.equal(stats.rules.size.average, 2)
4747
})
4848
})
4949

50-
describe('aggregates', function() {
50+
describe('aggregates', function () {
5151

52-
it('should correctly count declarations', function() {
52+
it('should correctly count declarations', function () {
5353
assert.equal(stats.declarations.total, 20)
5454
})
5555

56-
it('should correctly count selectors', function() {
56+
it('should correctly count selectors', function () {
5757
assert.equal(stats.selectors.total, 11)
5858
})
5959

60-
it('should correctly count the number of id selectors', function() {
60+
it('should correctly count the number of id selectors', function () {
6161
assert.equal(stats.selectors.id, 1)
6262
})
6363

64-
it('should correctly count the number of class selectors', function() {
64+
it('should correctly count the number of class selectors', function () {
6565
assert.equal(stats.selectors.class, 8)
6666
})
6767

68-
it('should correctly count the number of pseudo element selectors', function() {
68+
it('should correctly count the number of pseudo element selectors', function () {
6969
assert.equal(stats.selectors.pseudoElement, 1)
7070
})
7171

72-
it('should correctly count the number of pseudo class selectors', function() {
72+
it('should correctly count the number of pseudo class selectors', function () {
7373
assert.equal(stats.selectors.pseudoClass, 3)
7474
})
7575

76-
it('should correctly aggregate the repeated selectors', function() {
76+
it('should correctly aggregate the repeated selectors', function () {
7777
assert.deepEqual(stats.selectors.repeated, ['.red'])
7878
})
7979
})
8080

81-
describe('declarations', function() {
81+
describe('declarations', function () {
8282

83-
it('should correctly count vendor prefixes', function() {
83+
it('should correctly count vendor prefixes', function () {
8484
assert.equal(stats.declarations.vendorPrefix, 5)
8585
})
8686

87-
it('should correctly count important values', function() {
87+
it('should correctly count important values', function () {
8888
assert.equal(stats.declarations.important, 2)
8989
})
9090

9191
// Deprecate in favor of presentation-side uniquing
92-
// it('should correctly count the number of unique declarations', function() {
92+
// it('should correctly count the number of unique declarations', function () {
9393
// assert.equal(stats.declarations.uniqueDeclarationsCount, 19)
9494
// })
9595

96-
it('should correctly count the number of declarations that reset properties', function() {
96+
it('should correctly count the number of declarations that reset properties', function () {
9797
assert.deepEqual(stats.declarations.resets, {'margin': 1, 'margin-bottom': 1})
9898
})
9999
})
100100

101-
describe('keyframes', function() {
101+
describe('keyframes', function () {
102102
var keyframeStats
103103

104-
before(function() {
104+
before(function () {
105105
keyframeStats = cssstats(fixture('keyframes'))
106106
})
107107

108-
it('should correctly get statistics for CSS in, and after, a keyframe', function() {
108+
it('should correctly get statistics for CSS in, and after, a keyframe', function () {
109109
assert.equal(keyframeStats.declarations.properties.color.length, 5)
110110
// assert.equal(keyframeStats.aggregates.color.unique, 4)
111111
})
112112
})
113113

114-
it('should be able to parse css and produce stats', function(done) {
114+
it('should be able to parse css and produce stats', function (done) {
115115
[
116116
'basscss',
117117
'small',
118118
// 'font-awesome',
119119
'gridio',
120120
'gridio-national-light'
121-
].forEach(function(stylesheet) {
121+
].forEach(function (stylesheet) {
122122
renderJson(stylesheet)
123123
})
124124
done()
@@ -127,36 +127,36 @@ describe('css-statistics', function() {
127127

128128
// This seems like something better suited for the app, not the core
129129
/*
130-
describe('font shorthand property', function() {
130+
describe('font shorthand property', function () {
131131
var stats
132132
133-
before(function() {
133+
before(function () {
134134
stats = cssstats(fixture('font-shorthand'))
135135
})
136136
137-
it('should be able to grab the font-size declaration', function() {
137+
it('should be able to grab the font-size declaration', function () {
138138
assert.equal(stats.declarations.properties['font-size'].length, 2)
139139
})
140140
141-
it('should be able to grab the font-family declaration', function() {
141+
it('should be able to grab the font-family declaration', function () {
142142
assert.equal(stats.declarations.properties['font-family'].length, 1)
143143
})
144144
145-
it('should be able to grab the font-weight declaration', function() {
145+
it('should be able to grab the font-weight declaration', function () {
146146
assert.equal(stats.declarations.properties['font-weight'].length, 1)
147147
})
148148
149-
it('should be able to grab the font-style declaration', function() {
149+
it('should be able to grab the font-style declaration', function () {
150150
assert.equal(stats.aggregates.fontStyle.total, 1)
151151
})
152152
})
153153
*/
154154

155-
function fixture(name) {
155+
function fixture (name) {
156156
return fs.readFileSync('test/fixtures/' + name + '.css', 'utf8').toString().trim()
157157
}
158158

159-
function renderJson(filename) {
159+
function renderJson (filename) {
160160
var css = fixture(filename)
161161
var obj = cssstats(css)
162162
fs.writeFileSync('./test/results/' + filename + '.json', JSON.stringify(obj, null, 2))

0 commit comments

Comments
 (0)
This repository has been archived.