-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 923 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'use strict'
var standard = require('standard-react')
var format = require('util').format
var assign = require('object-assign')
var loaderUtils = require('loader-utils')
module.exports = function standardLoader (text) {
var self = this
var callback = this.async()
var config = assign(
this.options.standard || {},
loaderUtils.parseQuery(this.query)
)
this.cacheable()
standard.lintText(text, config, function (err, result) {
if (err) return callback(err, text)
if (result.errorCount === 0) return callback(err, text)
var warnings = result.results.reduce(function (items, result) {
return items.concat(result.messages.map(function (message) {
return format(
'%s:%d:%d: %s',
result.filePath, message.line || 0, message.column || 0, message.message
)
}))
}, [])
self.emitWarning(warnings.join('\n'))
callback(err, text)
})
}