3 var linter = require("../lib/linter");
4 var reporter = require("../lib/reporter");
5 var nopt = require("nopt");
6 var fs = require("fs");
8 var linter = require("../lib/jslint/linter"),
9 reporter = require("../lib/jslint/reporter"),
10 nopt = require("../lib/jslint/nopt/nopt"),
13 function commandOptions() {
16 'anon', 'bitwise', 'browser', 'cap', 'continue', 'css',
17 'debug', 'devel', 'eqeq', 'es5', 'evil', 'forin', 'fragment',
18 'newcap', 'node', 'nomen', 'on', 'passfail', 'plusplus',
19 'properties', 'regexp', 'rhino', 'undef', 'unparam',
20 'sloppy', 'sub', 'vars', 'white', 'widget', 'windows',
21 'json', 'color', 'jqmspace'
27 'predef' : [String, Array]
30 flags.forEach(function (option) {
31 commandOpts[option] = Boolean;
37 var options = commandOptions();
39 var parsed = nopt(options);
44 console.warn("Usage: " + process.argv[1] +
45 " [--" + Object.keys(options).join("] [--") +
46 "] [--] <scriptfile>...");
50 if (!parsed.argv.remain.length) {
51 die("No files specified.");
55 // If there are no more files to be processed, exit with the value 1
56 // if any of the files contains any lint.
57 var maybeExit = (function () {
59 var filesLeft = parsed.argv.remain.length,
62 return function (lint) {
66 if (filesLeft === 0) {
67 // This was the last file.
68 process.exit(ok ? 0 : 1);
74 function lintFile(file) {
76 fs.readFile(file, function (err, data) {
82 if (0xEF === data[0] && 0xBB === data[1] && 0xBF === data[2]) {
86 data = data.toString("utf8");
87 var lint = linter.lint(data, parsed);
90 console.log(JSON.stringify([file, lint.errors]));
92 reporter.report(file, lint, parsed.color);
99 parsed.argv.remain.forEach(lintFile);