diff --git a/extras/jsl.conf b/extras/jsl.conf new file mode 100644 index 00000000..a1ae872d --- /dev/null +++ b/extras/jsl.conf @@ -0,0 +1,44 @@ +# JavaScriptLint configuration file for CoffeeScript. + ++no_return_value # function {0} does not always return a value ++duplicate_formal # duplicate formal argument {0} ++equal_as_assign # test for equality (==) mistyped as assignment (=)?{0} ++var_hides_arg # variable {0} hides argument ++redeclared_var # redeclaration of {0} {1} ++anon_no_return_value # anonymous function does not always return a value ++missing_semicolon # missing semicolon ++meaningless_block # meaningless block; curly braces have no impact ++comma_separated_stmts # multiple statements separated by commas (use semicolons?) ++unreachable_code # unreachable code ++missing_break # missing break statement ++missing_break_for_last_case # missing break statement for last case in switch +-comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==) ++inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement ++useless_void # use of the void type may be unnecessary (void is always undefined) ++multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs ++use_of_label # use of label +-block_without_braces # block statement without curly braces ++leading_decimal_point # leading decimal point may indicate a number or an object member ++trailing_decimal_point # trailing decimal point may indicate a number or an object member ++octal_number # leading zeros make an octal number ++nested_comment # nested comment ++misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma ++ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement ++empty_statement # empty statement or extra semicolon +-missing_option_explicit # the "option explicit" control comment is missing ++partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag ++dup_option_explicit # duplicate "option explicit" control comment ++useless_assign # useless assignment ++ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity ++ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent) ++missing_default_case # missing default case in switch statement ++duplicate_case_in_switch # duplicate case in switch statements ++default_not_at_end # the default case is not at the end of the switch statement ++legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax ++jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax ++useless_comparison # useless comparison; comparing identical expressions ++with_statement # with statement hides undeclared variables; use temporary variable instead ++trailing_comma_in_array # extra comma is not recommended in array initializers ++assign_to_function_call # assignment to a function call ++parseint_missing_radix # parseInt missing radix parameter ++lambda_assign_requires_semicolon diff --git a/lib/command.js b/lib/command.js index 7b081da5..df7311ca 100644 --- a/lib/command.js +++ b/lib/command.js @@ -188,11 +188,12 @@ }); }; lint = function(js) { - var jsl, printIt; + var conf, jsl, printIt; printIt = function(buffer) { - return print(buffer.toString()); + return puts(buffer.toString().trim()); }; - jsl = spawn('jsl', ['-nologo', '-stdin']); + conf = __dirname + '/../extras/jsl.conf'; + jsl = spawn('jsl', ['-nologo', '-stdin', '-conf', conf]); jsl.stdout.on('data', printIt); jsl.stderr.on('data', printIt); jsl.stdin.write(js); diff --git a/lib/nodes.js b/lib/nodes.js index 24f81ee2..2e95793d 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -402,7 +402,7 @@ temp = o.scope.freeVariable(); complete = ("(" + (baseline = temp) + " = (" + (complete) + "))"); } - complete = i === 0 ? ("(typeof " + (complete) + " === \"undefined\" || " + (baseline) + " === null) ? undefined : ") : ("" + (complete) + " == undefined ? undefined : "); + complete = i === 0 ? ("(typeof " + (complete) + " === \"undefined\" || " + (baseline) + " === null) ? undefined : ") : ("" + (complete) + " == null ? undefined : "); return complete += (baseline += prop.compile(o)); } else { part = prop.compile(o); @@ -1643,10 +1643,10 @@ return true; }; IfNode.prototype.bodyNode = function() { - return this.body == undefined ? undefined : this.body.unwrap(); + return this.body == null ? undefined : this.body.unwrap(); }; IfNode.prototype.elseBodyNode = function() { - return this.elseBody == undefined ? undefined : this.elseBody.unwrap(); + return this.elseBody == null ? undefined : this.elseBody.unwrap(); }; IfNode.prototype.forceStatement = function() { this.tags.statement = true; diff --git a/lib/rewriter.js b/lib/rewriter.js index 5412d6ef..c228c82a 100644 --- a/lib/rewriter.js +++ b/lib/rewriter.js @@ -328,7 +328,7 @@ } debt[mtag] += 1; val = [oppos, mtag === 'INDENT' ? match[1] : oppos]; - if ((this.tokens[i + 2] == undefined ? undefined : this.tokens[i + 2][0]) === mtag) { + if ((this.tokens[i + 2] == null ? undefined : this.tokens[i + 2][0]) === mtag) { this.tokens.splice(i + 3, 0, val); stack.push(match); } else { diff --git a/src/command.coffee b/src/command.coffee index 2b2acaee..0ec180cf 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -153,8 +153,9 @@ writeJs = (source, js, base) -> # Pipe compiled JS through JSLint (requires a working `jsl` command), printing # any errors or warnings that arise. lint = (js) -> - printIt = (buffer) -> print buffer.toString() - jsl = spawn 'jsl', ['-nologo', '-stdin'] + printIt = (buffer) -> puts buffer.toString().trim() + conf = __dirname + '/../extras/jsl.conf' + jsl = spawn 'jsl', ['-nologo', '-stdin', '-conf', conf] jsl.stdout.on 'data', printIt jsl.stderr.on 'data', printIt jsl.stdin.write js diff --git a/src/nodes.coffee b/src/nodes.coffee index 8bef9985..5e78d739 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -367,7 +367,7 @@ exports.ValueNode = class ValueNode extends BaseNode complete = if i is 0 "(typeof #{complete} === \"undefined\" || #{baseline} === null) ? undefined : " else - "#{complete} == undefined ? undefined : " + "#{complete} == null ? undefined : " complete += (baseline += prop.compile(o)) else part = prop.compile(o)