1
- "use strict"
1
+ "use strict" ;
2
2
3
- var assign = require ( "object-assign" )
4
- var loaderUtils = require ( "loader-utils" )
5
- var objectHash = require ( "object-hash" )
6
- var pkg = require ( "./package.json" )
7
- var createCache = require ( "loader-fs-cache" )
8
- var cache = createCache ( "eslint-loader" )
3
+ var assign = require ( "object-assign" ) ;
4
+ var loaderUtils = require ( "loader-utils" ) ;
5
+ var objectHash = require ( "object-hash" ) ;
6
+ var pkg = require ( "./package.json" ) ;
7
+ var createCache = require ( "loader-fs-cache" ) ;
8
+ var cache = createCache ( "eslint-loader" ) ;
9
9
10
- var engines = { }
10
+ var engines = { } ;
11
11
12
12
/**
13
13
* Class representing an ESLintError.
@@ -19,10 +19,10 @@ class ESLintError extends Error {
19
19
* @param {string } messages - Formatted eslint errors.
20
20
*/
21
21
constructor ( messages ) {
22
- super ( )
23
- this . name = "ESLintError"
24
- this . message = messages
25
- this . stack = ""
22
+ super ( ) ;
23
+ this . name = "ESLintError" ;
24
+ this . message = messages ;
25
+ this . stack = "" ;
26
26
}
27
27
28
28
/**
@@ -32,7 +32,7 @@ class ESLintError extends Error {
32
32
* @return {string } error - A stringified representation of the error.
33
33
*/
34
34
inspect ( ) {
35
- return this . message
35
+ return this . message ;
36
36
}
37
37
}
38
38
@@ -47,87 +47,89 @@ class ESLintError extends Error {
47
47
function printLinterOutput ( res , config , webpack ) {
48
48
// skip ignored file warning
49
49
if (
50
- ! ( res . warningCount === 1 &&
50
+ ! (
51
+ res . warningCount === 1 &&
51
52
res . results [ 0 ] . messages [ 0 ] &&
52
53
res . results [ 0 ] . messages [ 0 ] . message &&
53
- res . results [ 0 ] . messages [ 0 ] . message . indexOf ( "ignore" ) > 1 )
54
+ res . results [ 0 ] . messages [ 0 ] . message . indexOf ( "ignore" ) > 1
55
+ )
54
56
) {
55
57
// quiet filter done now
56
58
// eslint allow rules to be specified in the input between comments
57
59
// so we can found warnings defined in the input itself
58
60
if ( res . warningCount && config . quiet ) {
59
- res . warningCount = 0
60
- res . results [ 0 ] . warningCount = 0
61
+ res . warningCount = 0 ;
62
+ res . results [ 0 ] . warningCount = 0 ;
61
63
res . results [ 0 ] . messages = res . results [ 0 ] . messages . filter ( function (
62
64
message
63
65
) {
64
- return message . severity !== 1
65
- } )
66
+ return message . severity !== 1 ;
67
+ } ) ;
66
68
}
67
69
68
70
// if enabled, use eslint auto-fixing where possible
69
71
if ( config . fix && res . results [ 0 ] . output ) {
70
- var eslint = require ( config . eslintPath )
71
- eslint . CLIEngine . outputFixes ( res )
72
+ var eslint = require ( config . eslintPath ) ;
73
+ eslint . CLIEngine . outputFixes ( res ) ;
72
74
}
73
75
74
76
if ( res . errorCount || res . warningCount ) {
75
77
// add filename for each results so formatter can have relevant filename
76
78
res . results . forEach ( function ( r ) {
77
- r . filePath = webpack . resourcePath
78
- } )
79
- var messages = config . formatter ( res . results )
79
+ r . filePath = webpack . resourcePath ;
80
+ } ) ;
81
+ var messages = config . formatter ( res . results ) ;
80
82
81
83
if ( config . outputReport && config . outputReport . filePath ) {
82
- var reportOutput
84
+ var reportOutput ;
83
85
// if a different formatter is passed in as an option use that
84
86
if ( config . outputReport . formatter ) {
85
- reportOutput = config . outputReport . formatter ( res . results )
86
- }
87
- else {
88
- reportOutput = messages
87
+ reportOutput = config . outputReport . formatter ( res . results ) ;
88
+ } else {
89
+ reportOutput = messages ;
89
90
}
90
- var filePath = loaderUtils . interpolateName ( webpack ,
91
- config . outputReport . filePath , {
92
- content : res . results . map ( function ( r ) {
93
- return r . source
94
- } ) . join ( "\n" ) ,
91
+ var filePath = loaderUtils . interpolateName (
92
+ webpack ,
93
+ config . outputReport . filePath ,
94
+ {
95
+ content : res . results
96
+ . map ( function ( r ) {
97
+ return r . source ;
98
+ } )
99
+ . join ( "\n" )
95
100
}
96
- )
97
- webpack . emitFile ( filePath , reportOutput )
101
+ ) ;
102
+ webpack . emitFile ( filePath , reportOutput ) ;
98
103
}
99
104
100
105
// default behavior: emit error only if we have errors
101
- var emitter = res . errorCount ? webpack . emitError : webpack . emitWarning
106
+ var emitter = res . errorCount ? webpack . emitError : webpack . emitWarning ;
102
107
103
108
// force emitError or emitWarning if user want this
104
109
if ( config . emitError ) {
105
- emitter = webpack . emitError
106
- }
107
- else if ( config . emitWarning ) {
108
- emitter = webpack . emitWarning
110
+ emitter = webpack . emitError ;
111
+ } else if ( config . emitWarning ) {
112
+ emitter = webpack . emitWarning ;
109
113
}
110
114
111
115
if ( emitter ) {
112
116
if ( config . failOnError && res . errorCount ) {
113
117
throw new ESLintError (
114
118
"Module failed because of a eslint error.\n" + messages
115
- )
116
- }
117
- else if ( config . failOnWarning && res . warningCount ) {
119
+ ) ;
120
+ } else if ( config . failOnWarning && res . warningCount ) {
118
121
throw new ESLintError (
119
122
"Module failed because of a eslint warning.\n" + messages
120
- )
123
+ ) ;
121
124
}
122
125
123
- emitter ( new ESLintError ( messages ) )
124
- }
125
- else {
126
+ emitter ( new ESLintError ( messages ) ) ;
127
+ } else {
126
128
throw new Error (
127
129
"Your module system doesn't support emitWarning. " +
128
130
"Update available? \n" +
129
131
messages
130
- )
132
+ ) ;
131
133
}
132
134
}
133
135
}
@@ -141,24 +143,23 @@ function printLinterOutput(res, config, webpack) {
141
143
* @return {void }
142
144
*/
143
145
module . exports = function ( input , map ) {
144
- var webpack = this
146
+ var webpack = this ;
145
147
146
148
var userOptions = assign (
147
149
// user defaults
148
150
( webpack . options && webpack . options . eslint ) || webpack . query || { } ,
149
151
// loader query string
150
152
loaderUtils . getOptions ( webpack )
151
- )
153
+ ) ;
152
154
153
- var userEslintPath = userOptions . eslintPath
154
- var formatter = require ( "eslint/lib/formatters/stylish" )
155
+ var userEslintPath = userOptions . eslintPath ;
156
+ var formatter = require ( "eslint/lib/formatters/stylish" ) ;
155
157
156
158
if ( userEslintPath ) {
157
159
try {
158
- formatter = require ( userEslintPath + "/lib/formatters/stylish" )
159
- }
160
- catch ( e ) {
161
- formatter = require ( "eslint/lib/formatters/stylish" )
160
+ formatter = require ( userEslintPath + "/lib/formatters/stylish" ) ;
161
+ } catch ( e ) {
162
+ formatter = require ( "eslint/lib/formatters/stylish" ) ;
162
163
}
163
164
}
164
165
@@ -168,69 +169,68 @@ module.exports = function(input, map) {
168
169
formatter : formatter ,
169
170
cacheIdentifier : JSON . stringify ( {
170
171
"eslint-loader" : pkg . version ,
171
- eslint : require ( userEslintPath || "eslint" ) . version ,
172
+ eslint : require ( userEslintPath || "eslint" ) . version
172
173
} ) ,
173
- eslintPath : "eslint" ,
174
+ eslintPath : "eslint"
174
175
} ,
175
176
userOptions
176
- )
177
+ ) ;
177
178
178
- var cacheDirectory = config . cache
179
- var cacheIdentifier = config . cacheIdentifier
179
+ var cacheDirectory = config . cache ;
180
+ var cacheIdentifier = config . cacheIdentifier ;
180
181
181
- delete config . cacheIdentifier
182
+ delete config . cacheIdentifier ;
182
183
183
184
// Create the engine only once per config
184
- var configHash = objectHash ( config )
185
+ var configHash = objectHash ( config ) ;
185
186
if ( ! engines [ configHash ] ) {
186
- var eslint = require ( config . eslintPath )
187
- engines [ configHash ] = new eslint . CLIEngine ( config )
187
+ var eslint = require ( config . eslintPath ) ;
188
+ engines [ configHash ] = new eslint . CLIEngine ( config ) ;
188
189
}
189
190
190
- webpack . cacheable ( )
191
+ webpack . cacheable ( ) ;
191
192
192
- var resourcePath = webpack . resourcePath
193
- var cwd = process . cwd ( )
193
+ var resourcePath = webpack . resourcePath ;
194
+ var cwd = process . cwd ( ) ;
194
195
195
196
// remove cwd from resource path in case webpack has been started from project
196
197
// root, to allow having relative paths in .eslintignore
197
198
if ( resourcePath . indexOf ( cwd ) === 0 ) {
198
- resourcePath = resourcePath . substr ( cwd . length + 1 )
199
+ resourcePath = resourcePath . substr ( cwd . length + 1 ) ;
199
200
}
200
201
201
- var engine = engines [ configHash ]
202
+ var engine = engines [ configHash ] ;
202
203
// return early if cached
203
204
if ( config . cache ) {
204
- var callback = webpack . async ( )
205
+ var callback = webpack . async ( ) ;
205
206
return cache (
206
207
{
207
208
directory : cacheDirectory ,
208
209
identifier : cacheIdentifier ,
209
210
options : config ,
210
211
source : input ,
211
212
transform : function ( ) {
212
- return lint ( engine , input , resourcePath )
213
- } ,
213
+ return lint ( engine , input , resourcePath ) ;
214
+ }
214
215
} ,
215
216
function ( err , res ) {
216
217
if ( err ) {
217
- return callback ( err )
218
+ return callback ( err ) ;
218
219
}
219
220
220
221
try {
221
- printLinterOutput ( res || { } , config , webpack )
222
- }
223
- catch ( e ) {
224
- err = e
222
+ printLinterOutput ( res || { } , config , webpack ) ;
223
+ } catch ( e ) {
224
+ err = e ;
225
225
}
226
- return callback ( err , input , map )
226
+ return callback ( err , input , map ) ;
227
227
}
228
- )
228
+ ) ;
229
229
}
230
- printLinterOutput ( lint ( engine , input , resourcePath ) , config , webpack )
231
- webpack . callback ( null , input , map )
232
- }
230
+ printLinterOutput ( lint ( engine , input , resourcePath ) , config , webpack ) ;
231
+ webpack . callback ( null , input , map ) ;
232
+ } ;
233
233
234
234
function lint ( engine , input , resourcePath ) {
235
- return engine . executeOnText ( input , resourcePath , true )
235
+ return engine . executeOnText ( input , resourcePath , true ) ;
236
236
}
0 commit comments