-
Notifications
You must be signed in to change notification settings - Fork 510
New Rule: requireSpacesInsideParenthesizedExpression #1254
New Rule: requireSpacesInsideParenthesizedExpression #1254
Conversation
@jscs-dev is there something more to do for feedback on this? |
- This effectively implements our "Embrace HTML5" option - Related: http://goo.gl/GcQAtn Fixes gh-2257
@gibson042 Sorry this slipped through the cracks. This needs to be rebased and the coverage needs to be increased. @hzoo Does this look good aside from the above issues? I see it's holding up the Idiomatic Preset PR: #1069. Would like to land both (this and Idiomatic) prs. |
e04a4a9
to
ace28ea
Compare
Rebase complete. Why did the coverage report not pick up use of the new util functions by rules requiring them, though? But at any rate, they are now specifically tested. |
That's a feature, not a bug. The unit coverage runner, written by @mdevils, explains the philosophy here: https://github.com/unit-coverage/unit-coverage#the-idea |
Where does this PR stand? The missing coverage seemed reasonable to me (and consistent with preexisting files), but I can extend it if there's a non-decrease requirement. More than that, though, I want feedback on the approach and the ideas... as noted, this is a POC. |
var value = nextToken.value; | ||
|
||
// Skip empty parentheses and explicit exceptions | ||
if (value === ')' || value in exceptions) { |
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.
Why not set ')' as a default part of the exceptions object? You can then simplify this if
statement.
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.
Because it's only an exception in one direction—if I universally except ")", then the immediately following close-parenthesis logic would erroneously allow "((…))".
This is really great work, @gibson042. Bravo. |
Thanks for the review. Am I correct in assuming that this has legs and that I should round it out with the above |
(and then the SpacesInsideParenthesizedArguments [function call], /SpacesInsideParenthesizedParameters [function definition], and SpacesInsideParenthesizedStatement [ |
Sounds like a plan to me. Maybe wait for the second go ahead from
|
'(((function(){ function f(){} if(0) return((f)(0, (1), ((2)))+0); throw(f()+(0)); })))' | ||
); | ||
var closeParens = []; | ||
sharedFile.iterateTokenByValue(')', function(token) { |
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 believe it should be wrapped to before
statement inside this describe
.
ace28ea
to
02404f1
Compare
Ok, I believe this is ready. Points for special consideration:
|
How would we enforce (options || { x: true } ).x but disallow (options || { x: true }).x ? |
assert(checker.checkString('(//comment\n foo //comment\n)').getErrorCount() === 1); | ||
}); | ||
|
||
it('should not look inside comments', 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.
is this description correct?
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.
Yes. These rules should look only at the characters beginning or ending comments, not at their contents.
Did you run it on core source?
It is for me, don't see any better way
What would those rules do? Could you give me couple examples? |
I'm not sure I understand... can you provide an English explanation of desired behavior? I've followed the other JSCS patterns, so it's possible to require spaces with a finite set of exceptions and also possible to disallow spaces with a finite set of exceptions, but AFAIK not possible to require spaces only for a finite set of "inside" characters.
For jQuery? Not yet.
ParenthesizedArguments or CallArguments or CallExpressionArguments: |
I stand corrected... disallowSpacesInsideParentheses has an
I checked master-branch jquery.js with |
errors.assert.noWhitespaceBetween({ | ||
token: token, | ||
nextToken: nextToken, | ||
message: 'Illegal space after opening grouping round bracket' |
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 suppose this is also worth calling out. "Round bracket" reads weird to me, but it seems to be the terminology used here.
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.
We had a discussion about it somewhere, for standardizing error output and rule names, in the new approach it would be cool to follow common terminology - https://en.wikipedia.org/wiki/Bracket.
In other words, i think it would be okay to call it "parentheses".
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 think it was #698 (comment).
()
- parentheses, []
- square brackets/brackets, {}
- braces, <>
- angle brackets
Totally
Wow! That would be great to see it in the new release, i guess another PR would be best. If no one has any objections, i will land this a bit later today. Awesomely done Richard! |
e97c8eb
to
5b98b26
Compare
"Round bracket" references replaced and |
Hooray! |
A proof of concept for distinguishing the several parenthetical productions (statement affix, function definition parameters, function call arguments, and arbitrary expressions), inspired by https://github.com/jquery/sizzle/pull/330/files#r27985694 . This PR implements only requireSpacesInsideParenthesizedExpression, but if you like the concepts herein I will add disallowSpacesInsideParenthesizedExpression so it can merge.
The obvious next step is to introduce similar pairs for SpacesInsideParenthesizedArguments, SpacesInsideParenthesizedParameters, and SpacesInsideParenthesizedStatement (names subject to change, but chosen for convenient alphabetic grouping) in a pattern analogous to that embodied by the "SpacesInFunction" rules but rooted at "SpacesInsideParentheses".
I believe this also relates to existing work:
Ref #1069 (comment)
Ref gh-812
Ref gh-431