4
// Can be run using Rhino using:
5
// rhino -f ../lib/fulljslint.js jslint-wrapper.js ...
7
// js -f ../lib/fulljslint.js jslint-wrapper.js ...
9
// But Spidermonkey needs special support to emulate readFile.
11
// This file assumes the fulljslint.js was loaded.
12
if (typeof(JSLINT) == 'undefined') {
13
print('jslint.js: fulljslint.js should be loaded.');
17
function print_help_and_quit(status) {
18
print('jslint [-o options_file] file.js ...');
20
print('Run linter on all input Javascript files.');
22
print(' -h Print this help message and exits');
25
print(' -o file Read file as a JSON object specifing options');
26
print(' --options file to the parser.');
30
//SpiderMonkey doesn't have a readFile by default.
31
//We emulate one by PIPING in the content on STDIN with EOF markers.
32
if (typeof(readFile) == 'undefined') {
33
var readFile = function readFile(filename) {
34
var content = '', line = '';
35
while (line != 'EOF') {
36
content += line + '\n';
43
function get_options_file(filename) {
45
var input = readFile(filename);
47
print("jslint: Couldn't open options file '" + filename + "'.");
50
return eval("x = " + input);
52
print("jslint: Error reading options file:");
58
function get_opt(args) {
59
var config = {options: {}, files: []};
60
while (args.length > 0) {
61
var arg = args.shift();
66
print("jslint: Missing options argument");
67
print_help_and_quit(1);
69
config.options = get_options_file(args.shift());
73
print_help_and_quit(0);
77
print('jslint: Unknown option: ' + arg);
78
print_help_and_quit(1);
80
config.files.push(arg);
85
config.files.concat(args);
89
/* We use our custom reporting instead of JSLint.report() which
91
function print_implied_names() {
92
/* Report about implied global names. */
93
var implied_names = [], name;
94
for (name in JSLINT.implied) {
95
if (JSLINT.implied.hasOwnPropery(name)) {
96
implied_names.push(name);
100
if (implied_names.length > 0 ) {
101
print('Implied globals:');
102
implied_names.sort();
103
print(implied_names.join(', '));
108
function print_lint_errors() {
109
/* Report about lint errors. */
110
for (var i=0; i < JSLINT.errors.length; i++) {
111
var error = JSLINT.errors[i];
113
//It seems that this is possible :-(
116
var line_no = error.line + 1;
117
var char_no = error.character + 1;
119
'Line ' + line_no + ' character ' + char_no + ': ' +
121
if (error.evidence) {
122
print(error.evidence);
128
function main(args) {
129
config = get_opt(args);
130
if (!config.files.length) {
131
print('jslint: Missing files to lint.');
132
print_help_and_quit();
135
for (var i=0; i < config.files.length; i++) {
136
var filename = config.files[i];
137
var input = readFile(filename);
139
print("jslint: Couldn't open file '" + filename + "'.");
142
var is_clean = JSLINT(input, config.options);
144
print("jslint: Lint found in '" + filename + "':");
145
print_implied_names();
148
print("jslint: No problem found in '" + filename + "'.\n");
153
main([].slice.apply(arguments));