You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
82
+
Custom formatters can be provided by first adding a valid CSSLint-formatter, such as `csslint-stylish`, then using it:
85
83
86
84
```js
87
85
var csslint =require('gulp-csslint');
88
-
var gutil =require('gulp-util');
89
86
90
-
varcustomFormatter=function(file) {
91
-
gutil.log(gutil.colors.cyan(file.csslint.errorCount)+' errors in '+gutil.colors.magenta(file.path));
87
+
csslint.addFormatter('csslint-stylish');
92
88
93
-
file.csslint.results.forEach(function(result) {
94
-
gutil.log(result.error.message+' on line '+result.error.line);
95
-
});
96
-
};
89
+
gulp.task('lint', function() {
90
+
gulp.src('lib/*.css')
91
+
.pipe(csslint())
92
+
.pipe(csslint.formatter('stylish'))
93
+
});
94
+
```
95
+
96
+
You can provide the formatter by requiring it directly as well:
You can also provide an object with the following contract to implement your own formatter:
109
+
110
+
```js
111
+
{
112
+
id:'string', // Name passed to csslint.formatter
113
+
startFormat:function() {}, // Called before parsing any files, should return a string
114
+
startFormat:function() {}, // Called after parsing all files, should return a string
115
+
formatResult:function (results, filename, options) {} // Called with a results-object per file linted. Optionally called with a filename, and options passed to csslint.formatter(*formatter*, *options*)
116
+
}
117
+
```
118
+
119
+
You can also provide a function, which is called for each file linted with the same arguments as `formatResults`.
120
+
105
121
### Formatter options
106
122
You can also pass options to the built-in formatter, by passing a second option to `formatter`.
0 commit comments