closure-linter icon indicating copy to clipboard operation
closure-linter copied to clipboard

fixjsstyle incorrectly adding semicolon to specific function args...

Open GoogleCodeExporter opened this issue 10 years ago • 2 comments

The following code will be broken after fixjsstyle:

alert(callback || function() {});

Gets 'fixed' to:

alert(callback || function() {};);


Original issue reported on code.google.com by [email protected] on 3 Oct 2012 at 6:00

GoogleCodeExporter avatar Jun 17 '15 06:06 GoogleCodeExporter

The resulting change to the code is correct per the style guide that gjslint 
and fixjsstyle enforce. You are assigning one of two possible values based on 
the condition evaluation, the linter sees that and asserts that an expression 
should end with a semicolon per the ECMAScript rules for ASI.

While fixjsstyle 'breaks' the code, is this a case of a broken implementation? 
I don't think so, look at it like this: If you are truly trying to stringify a 
function then why not use a function expression?

var someMethod = function() {
  return 'in someMethod';
};

alert(callback || someMethod);

http://ecma-international.org/ecma-262/5.1/#sec-7.9

Original comment by [email protected] on 24 Feb 2013 at 5:00

GoogleCodeExporter avatar Jun 17 '15 06:06 GoogleCodeExporter

Issue 57 has been merged into this issue.

Original comment by [email protected] on 15 Jan 2015 at 8:56

GoogleCodeExporter avatar Jun 17 '15 06:06 GoogleCodeExporter