Skip to content

Commit 590fba3

Browse files
committed
Make it run better as an external process.
1 parent 55a13a0 commit 590fba3

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

JSLint.coffee

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ VERBOSE = false
1212

1313
try
1414
if process.argv.length < 3
15-
throw new Error "No file specified"
15+
console.error JSON.stringify {errors:[{id:"INVALID"}]}
16+
process.exit 1
1617
filename = process.argv[2]
1718
script = fs.readFileSync filename, 'utf8'
1819
catch e
19-
console.log "File could not be read"
20+
console.error JSON.stringify {errors:[{id:"NOTFOUND"}]}
2021
process.exit 1
2122

2223
details = null
@@ -28,7 +29,7 @@ script = script.replace re, (header) ->
2829
details = JSON.parse matches[1]
2930
return ""
3031
unless details?
31-
console.error "There are no details!"
32+
console.error JSON.stringify {errors:[{id:"NOHEADER"}]}
3233
process.exit 1
3334

3435
details.id = 2
@@ -225,8 +226,9 @@ walk = (ast) ->
225226
]
226227
]
227228
else
228-
console.error "Unknown type: '#{type}'"
229-
console.error util.inspect ast, false, null, true
229+
if VERBOSE
230+
console.error "Unknown type: '#{type}'"
231+
console.error util.inspect ast, false, null, true
230232
return ast
231233
ast = parser.parse script
232234
if VERBOSE
@@ -264,9 +266,20 @@ ok = JSLINT script, {
264266
plugin: false
265267
}
266268
unless ok
267-
console.error "FAIL"
268269
result = JSLINT.data()
269-
console.error util.inspect result, false, 3, true
270+
if VERBOSE
271+
console.error util.inspect result, false, 3, true
272+
else
273+
out = {errors:[]}
274+
for error in result.errors
275+
out.errors.push
276+
raw:error.raw
277+
reason:error.reason
278+
line:error.line
279+
character:error.character
280+
evidence:error.evidence
281+
console.error JSON.stringify out
282+
process.exit 1
270283
else
271284
script = script.substr(head.length, script.length - (head.length+foot.length))
272285
script = "new ADSAFE_APP(#{id}, \"#{adsafeId}\", #{JSON.stringify(details)}, function(ADSAFE){\n#{script}\n});"

0 commit comments

Comments
 (0)