-
Notifications
You must be signed in to change notification settings - Fork 27.4k
style: enforce spaces after keywords, add spaces #9677
Conversation
@@ -1048,14 +1048,14 @@ function startingTag(element) { | |||
// turns out IE does not let you set .html() on elements which | |||
// are not allowed to have children. So we just ignore it. | |||
element.empty(); | |||
} catch(e) {} | |||
} catch (e) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch (e)
always looks weird to me, I'm not a fan of that style =\
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it :)
The only thing left that I would change in Angular's style is adding a space after function (in anonynous functions) =)
@@ -1184,7 +1184,7 @@ function $ParseProvider() { | |||
} | |||
if (isAllDefined(value)) { | |||
scope.$$postDigest(function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, that sounds like a good setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 =) |
@@ -1855,7 +1855,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { | |||
isolateBindingContext[scopeName] = value; | |||
}); | |||
attrs.$$observers[attrName].$$scope = scope; | |||
if( attrs[attrName] ) { | |||
if ( attrs[attrName] ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to enforce no whitespace after (
and before )
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
requireSpaceAfterKeywords
rule to jscs with associated changes.Is it preferred to explicitly specify the keywords in an array?
Or use
requireSpaceAfterKeywords = true
which 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