Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
43b922e
added turd file
chad3814 Jan 4, 2013
fd20859
big moderization, now works with the latest express
chad3814 Jan 8, 2013
292a6a3
fixed executing lintnode
chad3814 Jan 8, 2013
1b52a01
updated to newest jslint (2012-12-31) and lowercased the jslint ident…
chad3814 Jan 8, 2013
7b0d654
updated package
chad3814 Jan 24, 2013
00031a9
fixed the package
chad3814 Jan 24, 2013
524aa9c
more package tweaks
chad3814 Jan 24, 2013
6a523d0
bumped version to fix keyword snafu
chad3814 Jan 24, 2013
32a48d9
updated to jslint.js from 2013-05-01, added setImmediate and clearImm…
chad3814 May 4, 2013
4dd18e4
bumped the version for the update of jslint
chad3814 May 4, 2013
ada6d71
changed to how node-jslint loads the jslint.js
chad3814 May 6, 2013
c931631
updated to actual jslint.js
chad3814 May 6, 2013
7dcd945
added a commandline help
chad3814 May 6, 2013
ab2071d
added --quiet option
chad3814 May 6, 2013
0d3adee
install a commandline tool to use the server, called jslinter
chad3814 May 6, 2013
e0401db
fix empty lintnode-jslint-set
chad3814 May 6, 2013
6a71363
added optional pretty printing of errors
chad3814 May 7, 2013
d9c4897
new client prints errors prettier and exits with non-zero when there …
chad3814 May 7, 2013
205dc4b
oops had pretty printed errors off by a line and a character
chad3814 May 7, 2013
dfb1457
added a newline prefix to the pretty printed error
chad3814 May 8, 2013
37ae5cb
updated to newest jslint.js
chad3814 Jul 15, 2013
297c19f
updated jslint.js to 2013-07-17, bumped package version
chad3814 Jul 23, 2013
c6b4540
updated to jslint 2013-09-22
chad3814 Oct 27, 2013
6945601
bumped npm version
chad3814 Oct 27, 2013
b0cb6e6
Updated to newest jslint.js (2013-11-13)
chad3814 Nov 19, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
170 changes: 108 additions & 62 deletions app.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/usr/bin/env node

'use strict';

/* HTTP interface to JSLint.

Takes roughly half the time to jslint something with this than to
Expand All @@ -6,128 +10,144 @@
Invoke from bash script like:

curl --form source="<${1}" --form filename="${1}" ${JSLINT_URL}

or use the provided jslint.curl

jslint.curl <file>

*/

/*global process, require */
var express = require("express");
var JSLINT = require('./fulljslint');
var fs = require('fs');
var _ = require('underscore');
var http = require('http');
var jslint = require('./nodelint');
var package_info = require('./package');

var app = express.createServer();
var app = express();

app.configure(function () {
app.use(express.errorHandler(
{ dumpExceptions: true, showStack: true }));
app.use(express.bodyParser());
});
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.use(express.bodyParser());

var jslint_port = 3003;
var quiet = false;

/* copied from jslint's rhino.js */
// use jslint's default options, by default
var jslint_options = {
bitwise: true,
eqeqeq: true,
immed: true,
newcap: true,
nomen: true,
onevar: true,
plusplus: true,
regexp: true,
rhino: true,
undef: true,
white: true
};

var outputErrors = function (errors) {
var outputPrettyErrors = function (filename, errors) {
var results = ['\n', filename, '\n'];
errors.forEach(function (e, i) {
if (e) {
var pad = '#' + i + ' ';
while (pad.length < 4) {
pad = ' ' + pad;
}
e.evidence = e.evidence || '';
results.push(pad, e.reason || '', '\n ', e.evidence.replace(/^\s*/, ''), ' // Line ', e.line, ', Pos ', e.character, '\n');
}
});
return results.join('');
};

var outputTerseErrors = function (filename, errors) {
var e, i, output = [];
// debug("Handling " + errors.length + "errors" + '\n');
function write(s) {
output.push(s + '\n');
}

/* This formatting is copied from JSLint's rhino.js, to be compatible with
the command-line invocation. */
for (i = 0; i < errors.length; i += 1) {
e = errors[i];
if (e) {
write('Lint at line ' + e.line + ' character ' +
e.character + ': ' + e.reason);
write((e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
write('');
output.push('Lint at line ', e.line, ' character ', e.character, ': ', e.reason, '\n');
output.push((e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"), '\n');
output.push('\n');
}
}
return output.join('');
return filename + '\n' + output.join('');
};

var getOptionString = function () {
return Object.keys(jslint_options).map(function (opt) {
return opt + ": " + jslint_options[opt];
}).join('; ');
};

app.get('/', function (req, res) {
res.send('lintnode');
res.type('text/plain').end('lintnode version: ' + package_info.version + '\n' + 'jslint edition: ' + jslint.edition + '\n' + 'options: ' + getOptionString());
});

app.post('/jslint', function (req, res) {
if (req.body.source.substr(0, 2) === '#!') {
/*jslint regexp: true*/
req.body.source = req.body.source.replace(/^#!.*/, '');
/*jslint regexp: false*/
}
function doLint(sourcedata) {
var passed, results;
passed = JSLINT.JSLINT(sourcedata, jslint_options);
passed = jslint(sourcedata, jslint_options);
if (passed) {
results = "jslint: No problems found in " + req.body.filename + "\n";
} else {
results = outputErrors(JSLINT.JSLINT.errors);
if (req.body.pretty) {
results = outputPrettyErrors(req.body.filename, jslint.errors);
} else {
results = outputTerseErrors(req.body.filename, jslint.errors);
}
}
return results;
}
res.send(doLint(req.body.source), {'Content-Type': 'text/plain'});
res.type('text/plain').end(doLint(req.body.source));
});

/* This action always return some JSLint problems. */
var exampleFunc = function (req, res) {
JSLINT.JSLINT("a = function(){ return 7 + x }()",
var exampleErrors = function (req, res) {
jslint("a = function(){ return 7 + x }()",
jslint_options);
res.send(outputErrors(JSLINT.JSLINT.errors),
{'Content-Type': 'text/plain'});
res.type('text/plain').end(outputTerseErrors('example', jslint.errors));
};

app.get('/example/errors', exampleFunc);
app.post('/example/errors', exampleFunc);

/* This action always returns JSLint's a-okay message. */
app.post('/example/ok', function (req, res) {
res.send("jslint: No problems found in example.js\n",
{'Content-Type': 'text/plain'});
});
var exampleOk = function (req, res) {
res.type('text/plain').end("jslint: No problems found in example.js\n");
};

app.get('/example/errors', exampleErrors);
app.post('/example/errors', exampleErrors);

app.get('/example/ok', exampleOk);
app.post('/example/ok', exampleOk);

function parseCommandLine() {
var port_index, exclude_index, exclude_opts, include_index, include_opts, set_index, set_opts, set_pair, properties;
var port_index, exclude_index, exclude_opts, include_index, include_opts, set_index, set_opts, set_pair, help_index, quiet_index;
port_index = process.argv.indexOf('--port');
exclude_index = process.argv.indexOf('--exclude');
include_index = process.argv.indexOf('--include');
set_index = process.argv.indexOf('--set');
quiet_index = process.argv.indexOf('--quiet');
help_index = process.argv.indexOf('--help');
if (port_index > -1) {
jslint_port = process.argv[port_index + 1];
}
if (exclude_index > -1) {
exclude_opts = process.argv[exclude_index + 1].split(",");
if (exclude_opts.length > 0 && exclude_opts[0] !== '') {
_.each(exclude_opts, function (opt) {
exclude_opts.forEach(function (opt) {
jslint_options[opt] = false;
});
}
}
if (include_index > -1) {
include_opts = process.argv[include_index + 1].split(",");
if (include_opts.length > 0 && include_opts[0] !== '') {
_.each(include_opts, function (opt) {
include_opts.forEach(function (opt) {
jslint_options[opt] = true;
});
}
}
if (set_index > -1) {
set_opts = process.argv[set_index + 1].split(",");
if (set_opts.length > 0 && set_opts[0] !== '') {
_.each(set_opts, function (opt) {
set_opts.forEach(function (opt) {
if (opt.indexOf(":") > -1) {
set_pair = opt.split(":");
if (set_pair[1] === "true") {
Expand All @@ -142,19 +162,45 @@ function parseCommandLine() {
});
}
}
properties = "";
_.each(jslint_options, function (value, opt) {
properties = properties + opt + ": " + value + ", ";
});
return properties.substring(0, properties.length-2);
if (quiet_index > -1) {
quiet = true;
}
if (help_index > -1) {
console.error('Usuage:', process.argv[1], '[--port <port>] [--exclude <option,option,...>] [--include <option,option,...>] [--set <option:value,option:value,...>] [--quiet] [--help]');
console.error('\t--port <port>');
console.error('\t\tSet the port the server will listen on');
console.error('\t--exclude <option,option,...>');
console.error('\t\tShorthand for option:false,option:false,...');
console.error('\t--include <option,option,...>');
console.error('\t\tShorthand for option:true,option:true,...');
console.error('\t--set <option:value,option:value,...>');
console.error('\t\tSet the options like /*jslint option:value*/');
console.error('\t--quiet');
console.error('\t\tDon\'t output diagnostics');
console.error('\t--help');
console.error('\t\tThis help');
process.exit(0);
}
}

process.on('SIGINT', function () {
console.log("\n[lintnode] received SIGINT, shutting down");
if (!quiet) {
console.log("\n[lintnode] received SIGINT, shutting down");
}
process.exit(0);
});

console.log("[lintnode]", parseCommandLine());
app.listen(jslint_port, function () {
console.log("[lintnode] server running on port", jslint_port);
});
parseCommandLine();

if (!quiet) {
console.log('[lintnode] version:', package_info.version);
console.log('[lintnode] jslint edition:', jslint.edition);
console.log("[lintnode]", getOptionString());
}

var http_server = http.createServer(app);
http_server.listen(jslint_port, function () {
if (!quiet) {
console.log("[lintnode] server running on port", jslint_port);
}
});
9 changes: 6 additions & 3 deletions flymake-jslint.el
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ Uses `lintnode-node-program' and `lintnode-location'."
(mapconcat 'identity (mapcar 'symbol-name lintnode-jslint-excludes) ",")))
(lintnode-includes (if (not lintnode-jslint-includes)
""
(mapconcat 'identity (mapcar 'symbol-name lintnode-jslint-includes) ","))))

(mapconcat 'identity (mapcar 'symbol-name lintnode-jslint-includes) ",")))
(lintnode-set (if (not lintnode-jslint-set)
""
lintnode-jslint-set)))

(start-process "lintnode-server" "*lintnode*"
lintnode-node-program
lintnode-location
"--port" (number-to-string lintnode-port)
"--exclude" lintnode-excludes
"--include" lintnode-includes
"--set" lintnode-jslint-set)))
"--set" lintnode-set)))

(defun lintnode-stop ()
"stop the lintnode server process"
Expand Down
Loading