@@ -4,7 +4,7 @@ const PluginError = require('plugin-error');
4
4
const Lesshint = require ( 'lesshint' ) . Lesshint ;
5
5
const through = require ( 'through2' ) ;
6
6
7
- const { isExcluded } = require ( './utils' ) ;
7
+ const { getSeverityCount , isError , isExcluded, isWarning , pluralize } = require ( './utils' ) ;
8
8
9
9
const lesshintPlugin = ( options = { } ) => {
10
10
const lesshint = new Lesshint ( ) ;
@@ -33,9 +33,7 @@ const lesshintPlugin = (options = {}) => {
33
33
const contents = file . contents . toString ( ) ;
34
34
const results = lesshint . checkString ( contents , file . path ) ;
35
35
36
- warningCount = results . reduce ( ( sum , result ) => {
37
- return sum + ( result . severity === 'warning' ? 1 : 0 ) ;
38
- } , warningCount ) ;
36
+ warningCount += getSeverityCount ( results , isWarning ) ;
39
37
40
38
file . lesshint = {
41
39
resultCount : results . length ,
@@ -55,11 +53,10 @@ const lesshintPlugin = (options = {}) => {
55
53
showStack : false ,
56
54
} ) ) ;
57
55
} else if ( warningCount > maxWarnings ) {
58
- const count = ( warningCount === 1 ? 'warning' : 'warnings' ) ;
59
- const message = `Failed with ${ warningCount } ${ count } . Maximum allowed is ${ options . maxWarnings } .` ;
56
+ const message = `Failed with ${ warningCount } ${ pluralize ( 'warning' , warningCount ) } . Maximum allowed is ${ options . maxWarnings } .` ;
60
57
61
58
this . emit ( 'error' , new PluginError ( 'gulp-lesshint' , message , {
62
- name : 'LesshintError'
59
+ name : 'LesshintError' ,
63
60
} ) ) ;
64
61
}
65
62
@@ -92,9 +89,7 @@ lesshintPlugin.failOnError = () => {
92
89
93
90
return through . obj ( ( file , enc , cb ) => {
94
91
if ( file . lesshint ) {
95
- errorCount += file . lesshint . results . reduce ( ( count , result ) => {
96
- return count + ( result . severity === 'error' ) ;
97
- } , 0 ) ;
92
+ errorCount += getSeverityCount ( file . lesshint . results , isError ) ;
98
93
}
99
94
100
95
return cb ( null , file ) ;
@@ -103,10 +98,10 @@ lesshintPlugin.failOnError = () => {
103
98
return cb ( ) ;
104
99
}
105
100
106
- const message = `Failed with ${ errorCount } ` + ( errorCount === 1 ? 'error' : 'errors' ) ;
101
+ const message = `Failed with ${ errorCount } ${ pluralize ( 'error' , errorCount ) } ` ;
107
102
108
103
this . emit ( 'error' , new PluginError ( 'gulp-lesshint' , message , {
109
- name : 'LesshintError'
104
+ name : 'LesshintError' ,
110
105
} ) ) ;
111
106
112
107
return cb ( ) ;
0 commit comments