1
1
_ = window ? ._ ? self ? ._ ? global ? ._ ? require ' lodash' # rely on lodash existing, since it busts CodeCombat to browserify it--TODO
2
2
3
- # jshintHolder = {}
3
+ jshintHolder = {}
4
4
escodegen = require ' escodegen'
5
5
6
6
Language = require ' ./language'
@@ -16,7 +16,8 @@ module.exports = class JavaScript extends Language
16
16
17
17
constructor : ->
18
18
super arguments ...
19
- # jshintHolder.jshint ?= (self?.aetherJSHint ? require('jshint')).JSHINT
19
+ { JSHINT } = require (' jshint' )
20
+ jshintHolder .jshint ?= JSHINT
20
21
21
22
# Return true if we can very quickly identify a syntax error.
22
23
obviouslyCannotTranspile : (rawCode ) ->
@@ -58,21 +59,21 @@ module.exports = class JavaScript extends Language
58
59
# return lintProblems unless jshintHolder.jshint
59
60
wrappedCode = @ wrap rawCode, aether
60
61
61
- # # Run it through JSHint first, because that doesn't rely on Esprima
62
- # # See also how ACE does it: https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/javascript_worker.js
63
- # # TODO: make JSHint stop providing these globals somehow; the below doesn't work
64
- # jshintOptions = browser: false, couch: false, devel: false, dojo: false, jquery: false, mootools: false, node: false, nonstandard: false, phantom: false, prototypejs: false, rhino: false, worker: false, wsh: false, yui: false
65
- # jshintGlobals = _.zipObject jshintGlobals, (false for g in aether.allGlobals) # JSHint expects {key: writable} globals
66
- # # Doesn't work; can't find a way to skip warnings from JSHint programmatic options instead of in code comments.
67
- # # for problemID, problem of @originalOptions.problems when problem.level is 'ignore' and /jshint/.test problemID
68
- # # console.log 'gotta ignore', problem, '-' + problemID.replace('jshint_', '')
69
- # # jshintOptions['-' + problemID.replace('jshint_', '')] = true
70
- # try
71
- # jshintSuccess = jshintHolder.jshint(wrappedCode, jshintOptions, jshintGlobals)
72
- # catch e
73
- # console.warn "JSHint died with error", e #, "on code\n", wrappedCode
74
- # for error in jshintHolder.jshint.errors
75
- # lintProblems.push aether.createUserCodeProblem type: 'transpile', reporter: 'jshint', error: error, code: wrappedCode, codePrefix: @wrappedCodePrefix
62
+ # Run it through JSHint first, because that doesn't rely on Esprima
63
+ # See also how ACE does it: https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/javascript_worker.js
64
+ # TODO: make JSHint stop providing these globals somehow; the below doesn't work
65
+ jshintOptions = browser : false , couch : false , devel : false , dojo : false , jquery : false , mootools : false , node : false , nonstandard : false , phantom : false , prototypejs : false , rhino : false , worker : false , wsh : false , yui : false
66
+ jshintGlobals = _ .zipObject jshintGlobals, (false for g in aether .allGlobals ) # JSHint expects {key: writable} globals
67
+ # Doesn't work; can't find a way to skip warnings from JSHint programmatic options instead of in code comments.
68
+ # for problemID, problem of @originalOptions.problems when problem.level is 'ignore' and /jshint/.test problemID
69
+ # console.log 'gotta ignore', problem, '-' + problemID.replace('jshint_', '')
70
+ # jshintOptions['-' + problemID.replace('jshint_', '')] = true
71
+ try
72
+ jshintSuccess = jshintHolder .jshint (wrappedCode, jshintOptions, jshintGlobals)
73
+ catch e
74
+ console .warn " JSHint died with error" , e # , "on code\n", wrappedCode
75
+ for error in jshintHolder .jshint .errors
76
+ lintProblems .push aether .createUserCodeProblem type : ' transpile' , reporter : ' jshint' , error : error, code : wrappedCode, codePrefix : @wrappedCodePrefix
76
77
77
78
# Check for stray semi-colon on 1st line of if statement
78
79
# E.g. "if (parsely);"
0 commit comments