Skip to content

Commit a271be9

Browse files
committed
v0.0.14
2 parents dd69632 + f0688dd commit a271be9

File tree

15 files changed

+211
-49
lines changed

15 files changed

+211
-49
lines changed

.csscomb.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"color-shorthand": true,
1111
"combinator-space": true,
1212
"element-case": "lower",
13+
"eof-newline": true,
1314
"leading-zero": false,
1415
"rule-indent": true,
1516
"stick-brace": "\n",

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.0.14 - 2013-09-12
4+
- Option: eof-newline (#55)
5+
- Verbose option (#62)
6+
- Some refactoring
7+
38
## 0.0.13 - 2013-09-12
49
- Fixed failing on empty files (#66)
510

README.md

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ Example configuration:
4040
```json
4141
{
4242
"exclude": ["node_modules/**"],
43+
"verbose": true,
44+
4345
"always-semicolon": true,
4446
"block-indent": true,
4547
"colon-space": true,
4648
"color-case": "lower",
4749
"color-shorthand": true,
4850
"element-case": "lower",
51+
"eof-newline": true,
4952
"leading-zero": false,
5053
"rule-indent": true,
5154
"stick-brace": true,
@@ -56,9 +59,30 @@ Example configuration:
5659
5760
## Options
5861
62+
### verbose
63+
64+
Available value: `{Boolean}` `true`
65+
66+
Config mode: `{ "verbose": true }`
67+
```bash
68+
$ ./bin/csscomb ./test
69+
✓ test/integral.origin.css
70+
test/integral.expect.css
71+
72+
2 files processed
73+
1 file fixed
74+
96 ms spent
75+
```
76+
77+
CLI mode:
78+
```bash
79+
$ ./bin/csscomb ./test --verbose
80+
$ ./bin/csscomb ./test -v
81+
```
82+
5983
### always-semicolon
6084
61-
Available value: `{Boolean}` true
85+
Available value: `{Boolean}` `true`
6286
6387
Example: `{ "always-semicolon": true }`
6488
@@ -75,9 +99,9 @@ a { color: red; }
7599
**Note**: better to use with [rule-indent](#rule-indent)
76100
77101
Available values:
78-
* `{Boolean}` true (means 4 spaces)
102+
* `{Boolean}` `true` (means 4 spaces)
79103
* `{Number}` of spaces
80-
* `{String}` of whitespace characters (`/[ \t]*/`)
104+
* `{String}` of whitespace characters (`/[ \t]+/`)
81105
82106
Example: `{ "block-indent": 2 }`
83107
@@ -98,7 +122,7 @@ a { color: red
98122
### colon-space
99123
100124
Available values:
101-
* `{Boolean}` true (means `after`)
125+
* `{Boolean}` `true` (means `after`)
102126
* `{String}`: `before`, `after`, `both` or any combination of whitespaces
103127
and/or a colon (` `, `: `, `\t:\n\t` etc.)
104128
@@ -217,6 +241,18 @@ li > a { color: red }
217241
LI > A { color: red }
218242
```
219243
244+
### eof-newline
245+
246+
Available values: `{Boolean}` `true` or `false`
247+
248+
Example: `{ "eof-newline": true }`
249+
250+
`a { color: red }` → `a { color: red }\n`
251+
252+
Example: `{ "eof-newline": false }`
253+
254+
`a { color: red }\n` → `a { color: red }`
255+
220256
### leading-zero
221257
222258
Available values: `{Boolean}` `true` or `false`
@@ -236,9 +272,9 @@ p { padding: .5em }
236272
**Note**: better to use with [block-indent](#block-indent)
237273
238274
Available values:
239-
* `{Boolean}` true (means 4 spaces)
275+
* `{Boolean}` `true` (means 4 spaces)
240276
* `{Number}` of spaces
241-
* `{String}` of whitespace characters (`/[ \t]*/`)
277+
* `{String}` of whitespace characters (`/[ \t]+/`)
242278
243279
Example: `{ "rule-indent": 2 }`
244280
@@ -300,8 +336,9 @@ p {
300336
### stick-brace
301337
302338
Available values:
303-
* `{Boolean}` true (means 1 spaces)
304-
* `{String}` of whitespace characters (`/[ \t\n]*/`)
339+
* `{Boolean}` `true` (means 1 space)
340+
* `{Number}` of spaces
341+
* `{String}` of whitespace characters (`/[ \t\n]+/`)
305342
306343
Example: `{ "stick-brace": "\n" }`
307344
@@ -316,13 +353,13 @@ a
316353
317354
### strip-spaces
318355
319-
Available value: `{Boolean}` true
356+
Available value: `{Boolean}` `true`
320357
321358
Example: `{ "strip-spaces": true }`
322359
323-
Before: `a { color: red } \nb { font-weight: normal }\n\n\n`
360+
`a { color: red } \n \n \n` → `a { color: red }\n`
324361
325-
After: `a { color: red }\nb { font-weight: normal }\n`
362+
`a { color: red }\t` → `a { color: red }`
326363
327364
### unitless-zero
328365

lib/cli.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Command line implementation for CSSComb
33
*
44
* Usage example:
5-
* ./node_modules/.bin/csscomb file1 [dir1 [fileN [dirN]]]
5+
* ./node_modules/.bin/csscomb [options] file1 [dir1 [fileN [dirN]]]
66
*/
77
var fs = require('fs');
88
var program = require('commander');
@@ -12,6 +12,7 @@ var Comb = require('./csscomb');
1212
program
1313
.version(require('../package.json').version)
1414
.usage('[options] <file ...>')
15+
.option('-v, --verbose', 'verbose mode')
1516
.option('-c, --config [path]', 'configuration file path')
1617
.parse(process.argv);
1718

@@ -24,12 +25,22 @@ var configPath = program.config || (process.cwd() + '/.csscomb.json');
2425

2526
if (fs.existsSync(configPath)) {
2627
var comb = new Comb();
27-
comb.configure(require(configPath));
28+
var config = require(configPath);
29+
var time = new Date();
30+
config.verbose = program.verbose === true || config.verbose;
31+
comb.configure(config);
2832
vow.all(program.args.map(function(path) {
2933
return comb.processPath(path);
3034
})).fail(function(e) {
3135
console.log('stack: ', e.stack);
3236
process.exit(1);
37+
}).always(function() {
38+
if (config.verbose) {
39+
console.log('');
40+
console.log(comb.processed + ' file' + (comb.processed === 1 ? '' : 's') + ' processed');
41+
console.log(comb.changed + ' file' + (comb.changed === 1 ? '' : 's') + ' fixed');
42+
console.log((new Date().getTime() - time.getTime()) + ' ms spent');
43+
}
3344
});
3445
} else {
3546
console.log('Configuration file ' + configPath + ' was not found.');

lib/csscomb.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var Comb = function() {
1717
'element-case',
1818
'leading-zero',
1919
'strip-spaces',
20+
'eof-newline',
2021
'stick-brace',
2122
'colon-space',
2223
'combinator-space',
@@ -52,6 +53,10 @@ Comb.prototype = {
5253
this._exclude = (config.exclude || []).map(function(pattern) {
5354
return new minimatch.Minimatch(pattern);
5455
});
56+
57+
this.processed = 0;
58+
this.changed = 0;
59+
this._verbose = config.verbose;
5560
},
5661

5762
/**
@@ -115,7 +120,13 @@ Comb.prototype = {
115120
var _this = this;
116121
if (this._shouldProcess(path) && path.match(/\.css$/)) {
117122
return vfs.read(path, 'utf8').then(function(data) {
118-
return vfs.write(path, _this.processString(data, path), 'utf8');
123+
var processedData = _this.processString(data, path);
124+
var changed = data !== processedData;
125+
return vfs.write(path, processedData, 'utf8').then(function() {
126+
_this.processed++;
127+
if (changed) _this.changed++;
128+
if (_this._verbose) console.log((changed ? '✓' : ' ') + ' ' + path);
129+
});
119130
});
120131
}
121132
return null;

lib/options/block-indent.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module.exports = {
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true) value = 4;
12-
if (typeof value === 'number' && value === Math.abs(Math.round(value))) value = new Array(value + 1).join(' ');
13-
if (typeof value === 'string' && value.match(/^[ \t]*$/)) this._value = value;
14-
if (!this._value) return;
15-
return this;
10+
delete this._value;
11+
if (value === true) this._value = ' ';
12+
if (typeof value === 'number' && value === Math.abs(Math.round(value)))
13+
this._value = new Array(value + 1).join(' ');
14+
if (typeof value === 'string' && value.match(/^[ \t]+$/)) this._value = value;
15+
if (typeof this._value === 'string') return this;
1616
},
1717

1818
/**

lib/options/eof-newline.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module.exports = {
2+
3+
/**
4+
* Sets handler value.
5+
*
6+
* @param {Boolean} value Option value
7+
* @returns {Object|undefined}
8+
*/
9+
setValue: function(value) {
10+
if (value === true || value === false) {
11+
this._value = value;
12+
return this;
13+
}
14+
},
15+
16+
/**
17+
* Processes tree node.
18+
* @param {String} nodeType
19+
* @param {node} node
20+
*/
21+
process: function(nodeType, node) {
22+
if (nodeType === 'stylesheet') {
23+
var lastChild = node[node.length - 1];
24+
if (lastChild[0] !== 's') {
25+
lastChild = ['s', ''];
26+
node.push(lastChild);
27+
}
28+
lastChild[1] = lastChild[1].replace(/\n$/, '');
29+
if (this._value) lastChild[1] += '\n';
30+
}
31+
}
32+
33+
};

lib/options/rule-indent.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ module.exports = {
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true) value = 4;
12-
if (typeof value === 'number' && value === Math.abs(Math.round(value))) value = new Array(value + 1).join(' ');
13-
if (typeof value === 'string' && value.match(/^[ \t]*$/)) this._value = value;
14-
if (!this._value) return;
15-
return this;
10+
delete this._value;
11+
if (value === true) this._value = ' ';
12+
if (typeof value === 'number' && value === Math.abs(Math.round(value)))
13+
this._value = new Array(value + 1).join(' ');
14+
if (typeof value === 'string' && value.match(/^[ \t]+$/)) this._value = value;
15+
if (typeof this._value === 'string') return this;
1616
},
1717

1818
/**

lib/options/stick-brace.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ module.exports = {
77
* @returns {Object|undefined}
88
*/
99
setValue: function(value) {
10-
this._value = false;
11-
if (value === true) value = ' ';
12-
if (typeof value === 'string' && value.match(/^[ \t\n]*$/)) this._value = value;
13-
if (!this._value) return;
14-
return this;
10+
delete this._value;
11+
if (value === true) this._value = ' ';
12+
if (typeof value === 'number' && value === Math.abs(Math.round(value)))
13+
this._value = new Array(value + 1).join(' ');
14+
if (typeof value === 'string' && value.match(/^[ \t\n]+$/)) this._value = value;
15+
if (typeof this._value === 'string') return this;
1516
},
1617

1718
/**

lib/options/strip-spaces.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,26 @@ module.exports = {
1919
*/
2020
process: function(nodeType, node) {
2121
if (nodeType === 's') {
22-
node[0] = node[0].replace(/[ \t]+\n/g, '\n');
22+
node[0] = this._trim(node[0]);
2323
}
24-
2524
if (nodeType === 'stylesheet') {
26-
if (node[node.length - 1][0] === 's') node.pop();
27-
node.push(['s', '\n']);
25+
var lastChild = node[node.length - 1];
26+
if (lastChild[0] === 's') {
27+
lastChild[1] = this._trim(lastChild[1])
28+
.replace(/[ \t]+$/, '')
29+
.replace(/[\n]+/g, '\n');
30+
}
2831
}
32+
},
33+
34+
/**
35+
* Trim trailing spaces on each line.
36+
* @private
37+
* @param {String} s Spaceful string
38+
* @returns {String}
39+
*/
40+
_trim: function(s) {
41+
return s.replace(/[ \t]+\n/g, '\n');
2942
}
3043

3144
};

0 commit comments

Comments
 (0)