Skip to content

Commit c1e41f7

Browse files
committed
v0.1.0
2 parents e81c64f + 5124acb commit c1e41f7

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

CHANGELOG.md

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

3+
## 0.1.0 - 2013-10-11
4+
- CLI: lint mode
5+
36
## 0.0.15 - 2013-10-03
47
- Option: remove-empty-rulesets (#67)
58
- Option colon-space expanded

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ To run `csscomb`, you can use the following command from the project root:
3030
-h, --help output usage information
3131
-V, --version output the version number
3232
-c, --config [path] configuration file path
33+
-l, --lint in case some fixes needed returns an error
3334
```
3435
3536
## Configuration
@@ -423,7 +424,8 @@ Thanks for assistance and contributions:
423424
[@L0stSoul](https://github.com/L0stSoul),
424425
[@ignovak](https://github.com/ignovak),
425426
[@kizu](https://github.com/kizu),
426-
[@anton-rudeshko](https://github.com/anton-rudeshko)
427+
[@anton-rudeshko](https://github.com/anton-rudeshko),
428+
[@mishaberezin](https://github.com/mishaberezin)
427429
428430
## License
429431

lib/cli.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ program
1414
.usage('[options] <file ...>')
1515
.option('-v, --verbose', 'verbose mode')
1616
.option('-c, --config [path]', 'configuration file path')
17+
.option('-l, --lint', 'in case some fixes needed returns an error')
1718
.parse(process.argv);
1819

1920
if (!program.args.length) {
@@ -26,21 +27,29 @@ var configPath = program.config || (process.cwd() + '/.csscomb.json');
2627
if (fs.existsSync(configPath)) {
2728
var comb = new Comb();
2829
var config = require(configPath);
29-
var time = new Date();
30+
31+
console.time('spent');
32+
3033
config.verbose = program.verbose === true || config.verbose;
34+
config.lint = program.lint;
35+
3136
comb.configure(config);
32-
vow.all(program.args.map(function(path) {
33-
return comb.processPath(path);
34-
})).fail(function(e) {
35-
console.log('stack: ', e.stack);
36-
process.exit(1);
37-
}).always(function() {
37+
38+
vow.all(program.args.map(comb.processPath.bind(comb)))
39+
.then(function() {
3840
if (config.verbose) {
3941
console.log('');
4042
console.log(comb.processed + ' file' + (comb.processed === 1 ? '' : 's') + ' processed');
4143
console.log(comb.changed + ' file' + (comb.changed === 1 ? '' : 's') + ' fixed');
42-
console.log((new Date().getTime() - time.getTime()) + ' ms spent');
44+
console.timeEnd('spent');
45+
}
46+
if (config.lint && comb.tbchanged) {
47+
process.exit(1);
4348
}
49+
})
50+
.fail(function(e) {
51+
console.log('stack: ', e.stack);
52+
process.exit(1);
4453
});
4554
} else {
4655
console.log('Configuration file ' + configPath + ' was not found.');

lib/csscomb.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var gonzales = require('gonzales');
22
var minimatch = require('minimatch');
33
var vow = require('vow');
44
var vfs = require('vow-fs');
5+
var doNothing = function() {};
56

67
/**
78
* Starts Code Style processing process.
@@ -56,8 +57,10 @@ Comb.prototype = {
5657
});
5758

5859
this.processed = 0;
60+
this.tbchanged = 0;
5961
this.changed = 0;
6062
this._verbose = config.verbose;
63+
this._lint = config.lint;
6164
},
6265

6366
/**
@@ -125,11 +128,22 @@ Comb.prototype = {
125128
return vfs.read(path, 'utf8').then(function(data) {
126129
var processedData = _this.processString(data, path);
127130
var changed = data !== processedData;
128-
return vfs.write(path, processedData, 'utf8').then(function() {
129-
_this.processed++;
130-
if (changed) _this.changed++;
131-
if (_this._verbose) console.log((changed ? '✓' : ' ') + ' ' + path);
132-
});
131+
var lint = _this._lint;
132+
133+
var tick = changed ? (lint ? '!' : '✓') : ' ';
134+
var message = _this._verbose ? console.log.bind(null, tick, path) : doNothing;
135+
136+
_this.processed++;
137+
changed && _this.tbchanged++;
138+
139+
if (!changed || lint) {
140+
message();
141+
} else {
142+
return vfs.write(path, processedData, 'utf8').then(function() {
143+
_this.changed++;
144+
message();
145+
});
146+
}
133147
});
134148
}
135149
return null;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csscomb",
33
"description": "CSS coding style formatter",
4-
"version": "0.0.15",
4+
"version": "0.1.0",
55
"homepage": "http://csscomb.com/",
66
"author": "Mikhail Troshev <mishanga@yandex-team.ru>",
77
"repository": "https://github.com/csscomb/csscomb.js",
@@ -36,7 +36,7 @@
3636
}
3737
],
3838
"engines": {
39-
"node": "0.8 | 0.10"
39+
"node": ">= 0.8.0"
4040
},
4141
"dependencies": {
4242
"commander": "1.1.1",

0 commit comments

Comments
 (0)