-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
41 lines (30 loc) · 969 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
36
37
38
39
40
'use strict';
var JSHINT = require('jshint').JSHINT;
var jshintcli = require('jshint/src/cli.js');
var through = require('through');
module.exports = function(file) {
var data = '';
return through(
function write(buf) {
data += buf;
},
function end() {
var files = jshintcli.gather({ args: [file] });
var isIgnored = files.length === 0;
if (!isIgnored) {
var config = jshintcli.getConfig(file);
delete config.dirname;
if (!JSHINT(data, config, config.globals)) {
this.emit('error', JSHINT.errors.map(formatError).join('\n'));
}
}
this.queue(data);
this.queue(null);
}
);
function formatError(error) {
if (error) {
return file + ': line ' + error.line + ', col ' + error.character + ', ' + error.reason;
}
}
};