'typeof(x)' vs. 'typeof x'

182 views
Skip to first unread message

Tyler Breisacher

unread,
Mar 22, 2012, 9:10:52 PM3/22/12
to closure-lin...@googlegroups.com, Dan Beam
From the Google JavaScript style guide: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Parentheses

"Parentheses: Only where required
Use sparingly and in general only where required by the syntax and semantics.
Never use parentheses for unary operators such as delete, typeof and void or after keywords such as return, throw as well as others (case, in or new)."

Currently, the linter will yell at you if you do "return(x)" or "if(x)" etc. The error is "Missing space before '('". But if you do "typeof(x)" or "delete(x)" it will not. I realize that it's not actually checking for extra parens, it's just checking for missing spaces. But I suspect that "delete (x)" is a less common mistake. The parens probably indicate that someone was mistakenly thinking that typeof/delete was a function, rather than an operator.

Do you think this is something that Closure Linter could/should support? How hard would it be to add it?

(By the way, we are running Closure Linter as a PRESUBMIT check on an increasingly large amount of the JavaScript code in Chrome, and it is a big help! Thanks!)
Reply all
Reply to author
Forward
0 new messages