Skip to content

Commit 17d99d6

Browse files
committed
Rename reporter to formatter to match CSSLint
1 parent 15e16e0 commit 17d99d6

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

README.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var csslint = require('gulp-csslint');
1717
gulp.task('css', function() {
1818
gulp.src('client/css/*.css')
1919
.pipe(csslint())
20-
.pipe(csslint.reporter());
20+
.pipe(csslint.formatter());
2121
});
2222
```
2323

@@ -39,7 +39,7 @@ gulp.src('client/css/*.css')
3939
.pipe(csslint({
4040
'shorthand': false
4141
}))
42-
.pipe(csslint.reporter());
42+
.pipe(csslint.formatter());
4343
```
4444

4545
### csslint(csslintrc)
@@ -52,7 +52,7 @@ You can also pass the path to your csslintrc file instead of a rule configuratio
5252
```js
5353
gulp.src('client/css/*.css')
5454
.pipe(csslint('csslintrc.json'))
55-
.pipe(csslint.reporter());
55+
.pipe(csslint.formatter());
5656
```
5757

5858
## Results
@@ -66,28 +66,28 @@ file.csslint.results = []; // CSSLint errors
6666
file.csslint.opt = {}; // The options you passed to CSSLint
6767
```
6868

69-
## Using reporters
69+
## Using formatters
7070

71-
Several reporters come built-in to css-lint. To use one of these reporters, pass the name to `csslint.reporter`.
71+
Several formatters come built-in to CSSLint. To use one of these formatters, pass the name to `csslint.formatter`.
7272

73-
For a list of all reporters supported by `csslint`, see the [csslint wiki](https://github.com/CSSLint/csslint/wiki/Command-line-interface#--format).
73+
For a list of all formatters supported by `csslint`, see the [csslint wiki](https://github.com/CSSLint/csslint/wiki/Command-line-interface#--format).
7474

7575
```js
7676
gulp.task('lint', function() {
7777
gulp.src('lib/*.css')
7878
.pipe(csslint())
79-
.pipe(csslint.reporter('junit-xml'));
79+
.pipe(csslint.formatter('junit-xml'));
8080
```
8181
82-
### Custom reporters
82+
### Custom formatters
8383
84-
Custom reporter functions can be passed as `csslint.reporter(reporterFunc)`. The reporter function will be called for each linted file and passed the file object as described above.
84+
Custom formatter functions can be passed as `csslint.formatter(formatterFunc)`. The formatter function will be called for each linted file and passed the file object as described above.
8585
8686
```js
8787
var csslint = require('gulp-csslint');
8888
var gutil = require('gulp-util');
8989

90-
var customReporter = function(file) {
90+
var customFormatter = function(file) {
9191
gutil.log(gutil.colors.cyan(file.csslint.errorCount)+' errors in '+gutil.colors.magenta(file.path));
9292

9393
file.csslint.results.forEach(function(result) {
@@ -98,18 +98,18 @@ var customReporter = function(file) {
9898
gulp.task('lint', function() {
9999
gulp.src('lib/*.css')
100100
.pipe(csslint())
101-
.pipe(csslint.reporter(customReporter));
101+
.pipe(csslint.formatter(customFormatter));
102102
});
103103
```
104104
105-
### Reporter options
106-
You can also pass options to the built-in formatter, by passing a second option to `reporter`.
105+
### Formatter options
106+
You can also pass options to the built-in formatter, by passing a second option to `formatter`.
107107
108108
```js
109109
gulp.task('lint', function() {
110110
gulp.src('lib/*.css')
111111
.pipe(csslint())
112-
.pipe(csslint.reporter('junit-xml', options));
112+
.pipe(csslint.formatter('junit-xml', options));
113113
});
114114
```
115115
@@ -122,19 +122,19 @@ Default is using `process.stdout.write`, but you can use e.g. `console.log`, or
122122
gulp.task('lint', function() {
123123
gulp.src('lib/*.css')
124124
.pipe(csslint())
125-
.pipe(csslint.reporter('junit-xml', {logger: console.log.bind(console)}));
125+
.pipe(csslint.formatter('junit-xml', {logger: console.log.bind(console)}));
126126
});
127127
```
128128
129129
```js
130130
gulp.task('lint', function() {
131131
gulp.src('lib/*.css')
132132
.pipe(csslint())
133-
.pipe(csslint.reporter('junit-xml', {logger: gutil.log.bind(null, 'gulp-csslint:')}));
133+
.pipe(csslint.formatter('junit-xml', {logger: gutil.log.bind(null, 'gulp-csslint:')}));
134134
});
135135
```
136136
137-
`logger` is called once for the starting format of the reporter, then once for each file containing violations, then
137+
`logger` is called once for the starting format of the formatter, then once for each file containing violations, then
138138
lastly once for the ending format. Instead of writing to `stdout`, you can write to file using this option.
139139
140140
```js
@@ -144,7 +144,7 @@ gulp.task('lint', function(cb) {
144144

145145
gulp.src('lib/*.css')
146146
.pipe(csslint())
147-
.pipe(csslint.reporter('junit-xml', {logger: function(str) { output += str; }}))
147+
.pipe(csslint.formatter('junit-xml', {logger: function(str) { output += str; }}))
148148
.on('end', function(err) {
149149
if (err) return cb(err);
150150

@@ -153,7 +153,7 @@ gulp.task('lint', function(cb) {
153153
});
154154
```
155155
156-
This functionality is only available when not using custom reporters.
156+
This functionality is only available when not using custom formatters.
157157
158158
## Custom rules
159159
@@ -169,22 +169,22 @@ csslint.addRule({
169169
gulp.task('lint', function() {
170170
gulp.src('lib/*.css')
171171
.pipe(csslint())
172-
.pipe(csslint.reporter())
172+
.pipe(csslint.formatter())
173173
});
174174
```
175175
176176
## Fail on errors
177177
178-
Pipe the file stream to `csslint.failReporter()` to fail on errors.
178+
Pipe the file stream to `csslint.failFormatter()` to fail on errors.
179179
180180
```js
181181
var csslint = require('gulp-csslint');
182182

183183
gulp.task('lint', function() {
184184
gulp.src('lib/*.css')
185185
.pipe(csslint())
186-
.pipe(csslint.reporter()) // Display errors
187-
.pipe(csslint.reporter('fail')); // Fail on error (or csslint.failReporter())
186+
.pipe(csslint.formatter()) // Display errors
187+
.pipe(csslint.formatter('fail')); // Fail on error (or csslint.failFormatter())
188188
});
189189
```
190190

index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,52 +71,52 @@ var cssLintPlugin = function(options) {
7171
});
7272
};
7373

74-
cssLintPlugin.reporter = function(customReporter, options) {
75-
var reporter = csslint.getFormatter('text');
76-
var builtInReporter = true;
74+
cssLintPlugin.formatter = function(customFormatter, options) {
75+
var formatter = csslint.getFormatter('text');
76+
var builtInFormatter = true;
7777
var output;
7878

7979
options = options || {};
8080

8181
var logger = options.logger || process.stdout.write.bind(process.stdout);
8282

83-
if (typeof customReporter === 'function') {
84-
reporter = customReporter;
85-
builtInReporter = false;
83+
if (typeof customFormatter === 'function') {
84+
formatter = customFormatter;
85+
builtInFormatter = false;
8686
}
87-
else if (typeof customReporter === 'string') {
88-
if (customReporter === 'fail') {
89-
return cssLintPlugin.failReporter();
87+
else if (typeof customFormatter === 'string') {
88+
if (customFormatter === 'fail') {
89+
return cssLintPlugin.failFormatter();
9090
}
9191

92-
reporter = csslint.getFormatter(customReporter);
92+
formatter = csslint.getFormatter(customFormatter);
9393
}
9494

95-
if (typeof reporter === 'undefined') {
96-
throw new Error('Invalid reporter');
95+
if (typeof formatter === 'undefined') {
96+
throw new Error('Invalid formatter');
9797
}
9898

99-
if (builtInReporter) {
100-
output = [reporter.startFormat()];
99+
if (builtInFormatter) {
100+
output = [formatter.startFormat()];
101101
}
102102

103103
return through.obj(
104104
function(file, enc, cb) {
105105
// Only report if CSSLint was ran and errors were found
106106
if (file.csslint && !file.csslint.success) {
107-
if (builtInReporter) {
108-
output.push(reporter.formatResults(file.csslint.originalReport, file.path, options));
107+
if (builtInFormatter) {
108+
output.push(formatter.formatResults(file.csslint.originalReport, file.path, options));
109109
}
110110
else {
111-
reporter(file);
111+
formatter(file);
112112
}
113113
}
114114

115115
return cb(null, file);
116116
},
117117
function(cb) {
118-
if (builtInReporter) {
119-
output.push(reporter.endFormat());
118+
if (builtInFormatter) {
119+
output.push(formatter.endFormat());
120120

121121
output
122122
.filter(function(str) {
@@ -137,7 +137,7 @@ cssLintPlugin.addRule = function(rule) {
137137
csslint.addRule(rule);
138138
};
139139

140-
cssLintPlugin.failReporter = function() {
140+
cssLintPlugin.failFormatter = function() {
141141
return through.obj(function(file, enc, cb) {
142142
// Nothing to report or no errors
143143
if (!file.csslint || file.csslint.success) {

test/main.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ describe('gulp-csslint', function() {
215215
browsers: 'All',
216216

217217
// initialization
218-
init: function(parser, reporter) {
218+
init: function(parser, formatter) {
219219
'use strict';
220220
var rule = this;
221221
parser.addListener('startrule', function(event) {
@@ -230,7 +230,7 @@ describe('gulp-csslint', function() {
230230
return;
231231
}
232232
if (!selector.match(/^\.(_)?(o|c|u|is|has|js|qa)-[a-z0-9]+$/)) {
233-
reporter.warn('Bad naming: ' + selector, line, col, rule);
233+
formatter.warn('Bad naming: ' + selector, line, col, rule);
234234
}
235235
}
236236
}
@@ -275,7 +275,7 @@ describe('gulp-csslint', function() {
275275
});
276276
});
277277

278-
describe('cssLintPlugin.reporter()', function() {
278+
describe('cssLintPlugin.formatter()', function() {
279279
it('should support built-in CSSLint formatters', function(done) {
280280
var a = 0;
281281

@@ -284,19 +284,19 @@ describe('gulp-csslint', function() {
284284
var callback = sinon.spy();
285285

286286
var lintStream = cssLintPlugin();
287-
var reporterStream = cssLintPlugin.reporter('checkstyle-xml', {logger: callback});
287+
var formatterStream = cssLintPlugin.formatter('checkstyle-xml', {logger: callback});
288288

289-
reporterStream.on('data', function() {
289+
formatterStream.on('data', function() {
290290
++a;
291291
});
292292
lintStream.on('data', function(file) {
293-
reporterStream.write(file);
293+
formatterStream.write(file);
294294
});
295295
lintStream.once('end', function() {
296-
reporterStream.end();
296+
formatterStream.end();
297297
});
298298

299-
reporterStream.once('end', function() {
299+
formatterStream.once('end', function() {
300300
a.should.equal(1);
301301
sinon.assert.calledThrice(callback);
302302
callback.firstCall.args[0].should.equal('<?xml version="1.0" encoding="utf-8"?><checkstyle>');
@@ -318,25 +318,25 @@ describe('gulp-csslint', function() {
318318
var expected = getContents('expected/checkstyle-xml.xml');
319319

320320
var lintStream = cssLintPlugin();
321-
var reporterStream = cssLintPlugin.reporter('checkstyle-xml', {
321+
var formatterStream = cssLintPlugin.formatter('checkstyle-xml', {
322322
logger: function(str) {
323323
output += str;
324324
}
325325
});
326326

327327
sinon.stub(gutil, 'log');
328328

329-
reporterStream.on('data', function() {
329+
formatterStream.on('data', function() {
330330
++a;
331331
});
332332
lintStream.on('data', function(file) {
333-
reporterStream.write(file);
333+
formatterStream.write(file);
334334
});
335335
lintStream.once('end', function() {
336-
reporterStream.end();
336+
formatterStream.end();
337337
});
338338

339-
reporterStream.once('end', function() {
339+
formatterStream.once('end', function() {
340340
fs.writeFile('test-output.xml', output, function() {
341341
a.should.equal(1);
342342
sinon.assert.notCalled(gutil.log);
@@ -365,21 +365,21 @@ describe('gulp-csslint', function() {
365365
var callback = sinon.spy();
366366

367367
var lintStream = cssLintPlugin();
368-
var reporterStream = cssLintPlugin.reporter('text', {logger: callback});
368+
var formatterStream = cssLintPlugin.formatter('text', {logger: callback});
369369

370-
reporterStream.on('data', function() {
370+
formatterStream.on('data', function() {
371371
++a;
372372
});
373373
lintStream.on('data', function(newFile) {
374374
should.exist(newFile.csslint.success);
375375
newFile.csslint.success.should.equal(true);
376-
reporterStream.write(newFile);
376+
formatterStream.write(newFile);
377377
});
378378
lintStream.once('end', function() {
379-
reporterStream.end();
379+
formatterStream.end();
380380
});
381381

382-
reporterStream.once('end', function() {
382+
formatterStream.once('end', function() {
383383
sinon.assert.notCalled(callback);
384384
a.should.equal(1);
385385

0 commit comments

Comments
 (0)