style: enforce spaces after keywords, add spaces#9677
Conversation
There was a problem hiding this comment.
catch (e) always looks weird to me, I'm not a fan of that style =\
There was a problem hiding this comment.
Yeah I agree. Similar to function (e), switch (e), void (e), so keywords that have parens right after.
There was a problem hiding this comment.
I like it :)
The only thing left that I would change in Angular's style is adding a space after function (in anonynous functions) =)
There was a problem hiding this comment.
I'd rather function were trailed immediately by parentheses*, unless it's a named function --- can jscs enforce that?
(I meant parentheses, not braces**)
There was a problem hiding this comment.
Yeah can be done.
For all functions (declaration, named expression, anon expression)
"disallowSpacesInFunction": {
"beforeOpeningRoundBrace": true
}
If you want to be specific:
disallowSpacesInFunctionDeclaration
disallowSpacesInNamedFunctionExpression
disallowSpacesInAnonymousFunctionExpression
You can also enforce a space before the parentheses.
"requireSpacesInFunction": {
"beforeOpeningCurlyBrace": true
}
So with both rules it should be
function a() {
}
var a = function() {
}
var a = function a() {
}
There was a problem hiding this comment.
cool, that sounds like a good setup
There was a problem hiding this comment.
People, save the space in anonymous functions !!!
|
lgtm |
Yes, this is fine |
|
If you care to adjust the jscs rules to implement the comments I suggested above, please send another one =) |
There was a problem hiding this comment.
Is there a way to enforce no whitespace after ( and before ) ?
There was a problem hiding this comment.
Yeah using "disallowSpacesInsideParentheses": true.
Valid
if (attrs[attrName]) {
Invalid
if ( attrs[attrName]) {
if (attrs[attrName] ) {
if ( attrs[attrName] ) {
|
Truthfully I'd really prefer to always have a space after reserved words, including |
|
If I remember correctly, last time I checked the |
|
After doing some testing with jscs, Checking only function declarations: for Checking only anonymous function expressions: for Checking only named function expressions: for So based on majority it would be But yeah could go either way for anon func expressions since dropping the name in a named function expression would leave the space still there. |
Moving the
requireSpaceAfterKeywordsrule to jscs with associated changes.Is it preferred to explicitly specify the keywords in an array?
Or use
requireSpaceAfterKeywords = truewhich is equivalent to
requireSpaceAfterKeywords = [ 'do', 'for', 'if', 'else', 'switch', 'case', 'try', 'catch', 'void', 'while', 'with', 'return', 'typeof', 'function'];Although it doesn't make sense for
function.cc: @caitp