]>
git.r.bdr.sh - rbdr/dotfiles/blob - vim/ftplugin/javascript/jslint/runjslint.js
1 /*jslint laxbreak: true */
3 var fs
, vm
, sandbox
, jslintCore
= 'jslint-core.js';
5 if (typeof require
!== 'undefined') {
6 print
= require('util').puts
;
10 res
= vm
.runInNewContext(fs
.readFileSync(jslintCore
), sandbox
, jslintCore
);
11 JSLINT
= sandbox
.JSLINT
;
13 load('jslint-core.js');
16 // Import extra libraries if running in Rhino.
17 if (typeof importPackage
!= 'undefined') {
18 importPackage(java
.io
);
19 importPackage(java
.lang
);
22 var readSTDIN
= (function() {
23 // readSTDIN() definition for nodejs
24 if (typeof process
!= 'undefined' && process
.openStdin
) {
25 return function readSTDIN(callback
) {
26 var stdin
= process
.openStdin()
29 stdin
.on('data', function(chunk
) {
33 stdin
.on('end', function(chunk
) {
34 callback(body
.join('\n'));
38 // readSTDIN() definition for Rhino
39 } else if (typeof BufferedReader
!= 'undefined') {
40 return function readSTDIN(callback
) {
41 // setup the input buffer and output buffer
42 var stdin
= new BufferedReader(new InputStreamReader(System
['in'])),
45 // read stdin buffer until EOF (or skip)
46 while (stdin
.ready()){
47 lines
.push(stdin
.readLine());
50 callback(lines
.join('\n'));
53 // readSTDIN() definition for Spidermonkey
54 } else if (typeof readline
!= 'undefined') {
55 return function readSTDIN(callback
) {
62 while (emptyCount
< 25) {
72 input
.splice(-emptyCount
);
73 callback(input
.join('\n'));
78 readSTDIN(function(body
) {
89 errorCount
= JSLINT
.errors
.length
;
90 for (i
= 0; i
< errorCount
; i
+= 1) {
91 error
= JSLINT
.errors
[i
];
93 nextError
= i
< errorCount
? JSLINT
.errors
[i
+1] : null;
94 if (error
&& error
.reason
&& error
.reason
.match(/^Stopping/) === null) {
95 // If jslint stops next, this was an actual error
96 if (nextError
&& nextError
.reason
&& nextError
.reason
.match(/^Stopping/) !== null) {
99 print([error
.line
, error
.character
, errorType
, error
.reason
].join(":"));