@@ -7,36 +7,30 @@ var linter = require('./linter');
7
7
* Function bound to the plugin `apply` method to run the linter and report any
8
8
* errors (and their source file locations)
9
9
* @param options - from the apply method, the options passed in
10
- * @param compilation - the compiler object
10
+ * @param compiler - the compiler object
11
11
* @param done - webpack callback
12
12
*/
13
- module . exports = function runCompilation ( options , compilation , done ) {
13
+ module . exports = function runCompilation ( options , compiler , done ) {
14
14
var errors = [ ] ;
15
15
var warnings = [ ] ;
16
16
17
17
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
+ } ) ;
32
26
33
27
if ( options . failOnError && errors . length ) {
34
28
done ( new Error ( 'Failed because of a stylelint error.\n' ) ) ;
35
29
} else {
36
30
done ( ) ;
37
31
}
38
32
} )
39
- . catch ( function ( err ) {
33
+ . catch ( function linterError ( err ) {
40
34
if ( options . failOnError && errors . length ) {
41
35
done ( new Error ( 'Failed because of a stylelint error.\n' ) ) ;
42
36
} else {
@@ -45,9 +39,15 @@ module.exports = function runCompilation(options, compilation, done) {
45
39
console . log ( chalk . red ( err ) ) ;
46
40
} ) ;
47
41
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
+ }
52
52
} ) ;
53
53
} ;
0 commit comments