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
Copy file name to clipboardExpand all lines: README.md
+48-32Lines changed: 48 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ var csslint = require('gulp-csslint');
17
17
gulp.task('css', function() {
18
18
gulp.src('client/css/*.css')
19
19
.pipe(csslint())
20
-
.pipe(csslint.reporter());
20
+
.pipe(csslint.formatter());
21
21
});
22
22
```
23
23
@@ -39,7 +39,7 @@ gulp.src('client/css/*.css')
39
39
.pipe(csslint({
40
40
'shorthand':false
41
41
}))
42
-
.pipe(csslint.reporter());
42
+
.pipe(csslint.formatter());
43
43
```
44
44
45
45
### csslint(csslintrc)
@@ -52,7 +52,7 @@ You can also pass the path to your csslintrc file instead of a rule configuratio
52
52
```js
53
53
gulp.src('client/css/*.css')
54
54
.pipe(csslint('csslintrc.json'))
55
-
.pipe(csslint.reporter());
55
+
.pipe(csslint.formatter());
56
56
```
57
57
58
58
## Results
@@ -61,55 +61,71 @@ Adds the following properties to the file object:
61
61
62
62
```js
63
63
file.csslint.success=true; // or false
64
-
file.csslint.errorCount=0; // number of errors returned by CSSLint
65
-
file.csslint.results= []; // CSSLint errors
66
-
file.csslint.opt= {}; // The options you passed to CSSLint
64
+
file.csslint.report= {}; // The report from CSSLint after linting the file
67
65
```
68
66
69
-
## Using reporters
67
+
## Using formatters
70
68
71
-
Several reporters come built-in to css-lint. To use one of these reporters, pass the name to `csslint.reporter`.
69
+
Several formatters come built-in to CSSLint. To use one of these formatters, pass the name to `csslint.formatter`.
72
70
73
-
For a list of all reporters supported by `csslint`, see the [csslint wiki](https://github.com/CSSLint/csslint/wiki/Command-line-interface#--format).
71
+
For a list of all formatters supported by `csslint`, see the [csslint wiki](https://github.com/CSSLint/csslint/wiki/Command-line-interface#--format).
74
72
75
73
```js
76
74
gulp.task('lint', function() {
77
75
gulp.src('lib/*.css')
78
76
.pipe(csslint())
79
-
.pipe(csslint.reporter('junit-xml'));
77
+
.pipe(csslint.formatter('junit-xml'));
80
78
```
81
79
82
-
### Custom reporters
80
+
### Custom formatters
83
81
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.
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
-
varcustomReporter=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 pass options to the built-in formatter, by passing a second option to `reporter`.
108
+
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
+
121
+
### Formatter options
122
+
You can also pass options to the built-in formatter, by passing a second option to `formatter`.
107
123
108
124
```js
109
125
gulp.task('lint', function() {
110
126
gulp.src('lib/*.css')
111
127
.pipe(csslint())
112
-
.pipe(csslint.reporter('junit-xml', options));
128
+
.pipe(csslint.formatter('junit-xml', options));
113
129
});
114
130
```
115
131
@@ -122,19 +138,19 @@ Default is using `process.stdout.write`, but you can use e.g. `console.log`, or
0 commit comments