@@ -7,36 +7,30 @@ var linter = require('./linter');
77 * Function bound to the plugin `apply` method to run the linter and report any
88 * errors (and their source file locations)
99 * @param options - from the apply method, the options passed in
10- * @param compilation - the compiler object
10+ * @param compiler - the compiler object
1111 * @param done - webpack callback
1212 */
13- module . exports = function runCompilation ( options , compilation , done ) {
13+ module . exports = function runCompilation ( options , compiler , done ) {
1414 var errors = [ ] ;
1515 var warnings = [ ] ;
1616
1717 linter ( options )
18- . then ( function ( lint ) {
19- warnings = lint . results
20- . filter ( function ( f ) {
21- return f . warnings && f . warnings . length ;
22- } ) ;
23- errors = lint . results
24- . filter ( function ( f ) {
25- return f . errored ;
26- } ) . map ( function ( f ) {
27- return f . source ; // send error instead
28- } ) ;
29- if ( ! options . quiet ) {
30- console . log ( chalk . yellow ( options . formatter ( lint . results ) ) ) ;
31- }
18+ . then ( function linterSuccess ( lint ) {
19+ warnings = lint . results . filter ( function ( f ) {
20+ return f . warnings && f . warnings . length ;
21+ } ) ;
22+
23+ errors = lint . results . filter ( function ( f ) {
24+ return f . errored ;
25+ } ) ;
3226
3327 if ( options . failOnError && errors . length ) {
3428 done ( new Error ( 'Failed because of a stylelint error.\n' ) ) ;
3529 } else {
3630 done ( ) ;
3731 }
3832 } )
39- . catch ( function ( err ) {
33+ . catch ( function linterError ( err ) {
4034 if ( options . failOnError && errors . length ) {
4135 done ( new Error ( 'Failed because of a stylelint error.\n' ) ) ;
4236 } else {
@@ -45,9 +39,15 @@ module.exports = function runCompilation(options, compilation, done) {
4539 console . log ( chalk . red ( err ) ) ;
4640 } ) ;
4741
48- // eslint-disable-next-line no-unused-expressions
49- compilation . plugin && compilation . plugin ( 'compilation' , function ( compilation ) {
50- compilation . errors = compilation . errors . concat ( errors ) ;
51- compilation . warnings = compilation . warnings . concat ( warnings ) ;
42+ compiler . plugin ( 'compilation' , function onCompilation ( compilation ) {
43+ if ( warnings . length ) {
44+ compilation . warnings . push ( chalk . yellow ( options . formatter ( warnings ) ) ) ;
45+ warnings = [ ] ;
46+ }
47+
48+ if ( errors . length ) {
49+ compilation . errors . push ( chalk . red ( options . formatter ( errors ) ) ) ;
50+ errors = [ ] ;
51+ }
5252 } ) ;
5353} ;
0 commit comments