xonecas.io
1510
Cn

cli-node-jshint / commit 0773b24

initial commit

sean2011-08-17 0773b24540a6e7d22c1c89b30f8e23d568f3c954

2 files changed

README.markdown+36−0
@@ -0,0 +1,36 @@
1+# Simple command line interface for JSHINT
2+
3+If you need more than this, you should take a look at @brentlintner
4+implemenation: [node-jshint](https://github.com/jshint/node-jshint).
5+This is a very simple solution. It depends on [jshint](https://github.com/jshint/jshint)
6+(do'h!) and, wait for it, [node.js](http://nodejs.org/).
7+
8+## Instalation
9+
10+You are going to need jshint, then just drop cli-jshint into that, or run these
11+two commands:
12+
13+ git clone https://github.com/jshint/jshint.git
14+ git clone ...
15+
16+## Usage
17+
18+Same as would expect, please head on to [jshint's webby](http://jshint.com/#docs)
19+ for the full docs. But this will get you started:
20+
21+ cd jshint
22+ ./cli-jshint path/to/js/file option:value option:value
23+
24+## Example
25+
26+With the options set in file:
27+
28+ ./cli-jshint ./cli-jshint
29+
30+With options
31+
32+ ./cli-jshint ./cli-jshint curly:true debug:true node:true
33+
34+### License?
35+
36+Please contribute, mangle, cuddle, ... at will.
cli-jshint+68−0
@@ -0,0 +1,68 @@
1+#! /usr/bin/env node
2+/*jshint node:true, curly:true, onevar:true, maxlen:80 */
3+
4+var jshint = require('./jshint.js').JSHINT,
5+ fs = require('fs'),
6+ args = process.argv.slice(2),
7+ paths = [],
8+ options = {},
9+ files = {},
10+ hasProp = Object.prototype.hasOwnProperty,
11+ keyValuePair;
12+
13+args.forEach(function (arg) {
14+ if (arg.indexOf('/') !== -1) {
15+ /* path to js file */
16+ paths.push(arg);
17+ } else {
18+ /* jshint option */
19+ keyValuePair = arg.split(':');
20+ options[keyValuePair[0]] = keyValuePair[1];
21+ }
22+});
23+
24+function reportErrors (errors) {
25+ errors.forEach(function (err) {
26+ console.log(
27+ err.reason,
28+ "\nline: "+ err.line +" char: "+ err.character,
29+ "\n"+ err.evidence +"\n\n"
30+ );
31+ });
32+}
33+
34+function parseFiles() {
35+ var prop;
36+
37+ for (prop in files) {
38+ if (hasProp.call(files, prop)) {
39+ console.log("\n\nChecking "+ prop);
40+
41+ if (jshint(files[prop], options)) {
42+ console.log("Hooray, no lint!\n\n");
43+ } else {
44+ console.log("Error(s): \n");
45+ reportErrors(jshint.errors);
46+ }
47+ }
48+ }
49+}
50+
51+(function readAll () {
52+ var path;
53+
54+ if (paths.length > 0) {
55+ path = paths.shift();
56+ fs.readFile(path, 'utf8', function (err, out) {
57+ if (err) {
58+ throw err;
59+ }
60+
61+ files[path] = out;
62+
63+ readAll();
64+ });
65+ } else {
66+ parseFiles();
67+ }
68+}) ();