1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 |
|
5 | module.exports = function (done) {
|
6 | const standard = require('standard')
|
7 | const options = getOptions()
|
8 |
|
9 | standard.lintFiles(options.files || [], options, function (err, res) {
|
10 | if (err) return done(err)
|
11 | if (res.errorCount === 0 && res.warningCount === 0) return done()
|
12 | done(errorify(res))
|
13 | })
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function getOptions () {
|
21 | const pkg = require(path.join(process.cwd(), 'package.json'))
|
22 | const params = pkg.standard && pkg.standard || {}
|
23 | return params
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | function errorify (res) {
|
31 | const cwd = process.cwd()
|
32 | const count = res.errorCount + res.warningCount
|
33 | const err = new Error('' + count + (count === 1 ? ' issue' : ' issues') + ' found:')
|
34 | err.stack = '' + err.message
|
35 |
|
36 | res.results.forEach(function (result) {
|
37 | result.messages.forEach(function (message) {
|
38 | err.stack += ('\n ' +
|
39 | result.filePath.replace(cwd, '').replace(/^\//, '') +
|
40 | ':' + message.line + ':' + message.column + ': ' +
|
41 | message.message + ' (' + message.ruleId + ')')
|
42 | })
|
43 | })
|
44 |
|
45 | return err
|
46 | }
|