forked from isao/bbjshint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·53 lines (42 loc) · 1.22 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/local/bin/node
/*jshint node:true */
'use strict';
var fs = require('fs'),
path = require('path'),
lint = require('jshint').JSHINT,
bbresults = require('bbresults'),
stripJsonComments = require('strip-json-comments'),
title = 'JSHint results',
pathname = process.env.BB_DOC_PATH;
function getOptions(dir) {
var candidate, opts;
if (dir === '/') {
opts = require('./jshint-flags');
}
if (fs.existsSync(candidate = path.join(dir, '.jshintrc'))) {
opts = JSON.parse(stripJsonComments(fs.readFileSync(candidate)));
}
return opts || getOptions(path.join(dir, '..'));
}
function run(err, str) {
if (err) {
bbresults.notify('error, reading ' + pathname, {
title: title
});
} else if (lint(str, getOptions(path.dirname(pathname)))) {
bbresults.notify(pathname + ' is lint free', {
title: title
});
} else {
bbresults.show(lint.errors, pathname, title);
}
}
if (require.main === module) {
if (undefined === pathname) {
bbresults.notify('please save the document and try again', {
title: title
});
} else {
fs.readFile(pathname, 'utf-8', run);
}
}