-
Notifications
You must be signed in to change notification settings - Fork 47.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put comma after any non-whitespace non-comment characters in XJSExpression #3129
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! |
Re: the TravisCI failure: Hmm; that test passed locally; I'll check if I'm missing anything from the commit, and update. |
Added in the missing change, and signed cla. |
Hmm, can you run |
Ah, |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
The tests seem to think that for:
The comma ought go immediately after bar. That surprises me; does anyone happen to know why this is the case? I can sort-of see putting the comma after the last non-whitespace item in the braces, but putting it before comments seems rather odd to me. |
The reason for them being inlined into the sub visitors is to have control over where they end up. Moving it out like that works, but you then end up with commas after newlines/whitespace rather than before as you would write yourself. |
@syranide Starting to get a bit off topic, but as far as "as you would write yourself." you probably wouldn't put a space right before a newline, so that becomes a question of how far you want to take it. I'm testing a patch that fixes #1673 without changing any existing output; it's a lot more complicated than this one though. |
@jasom
|
@syranide I meant the |
@jasom Ah :) |
Okay, I fixed the same issue in a completely different way; it should change not at all any whitespace placement. I also added a unit test for the issue I fixed. |
@jasom Your commit is broken (it includes git comments). |
var commaPos = 0; | ||
//console.log('"'+value+'"') | ||
for (var i=0;i<value.length;++i) { | ||
switch (state) { |
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.
My vote goes to if
instead of this nested switch
nightmare.
@syranide Sorry, I pushed the wrong branch |
@syranide Fixed up git garbage, converted switch to if/else. I have to go to work now so any other changes will have to wait until tonight. |
cc @jeffmo |
var state = "normal"; | ||
var commaPos = 0; | ||
for (var i=0;i<value.length;++i) { | ||
if (state === "normal") { |
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.
You have 3 else-branches with the same commaPos = i+1;
, it should be possible to reduce and flatten this unless there's a very good reason for this verbosity.
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, the state machine started out a bit differently, I'll clean that up. Also, if you know a better way of checking for whitespace than (foo.trim() === "") let me know.
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.
Couple small style nits (can fixup later with anything else that might come):
- 2 space indent (match the rest of the files)
- spaces around operators (
for (var i = 0; i < value.length; ++i)
) - use
===
and semicolons consistently. The line below this is missing the former. Line 28 the latter.
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.
@zpao I fixed those in all the places I found; is there a style linter I can use to check for this in the future?
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.
You can run eslint with grunt eslint
or grunt lint
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.
@hzoo Yeah, I did that, but it didn't flag any of the style issues zpao pointed out.
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.
Oh then it's probably because it's not being processed - yeah src/vendor
is in the eslintignore
.
# We can probably lint these later but not important at this point
src/vendor
So instead you could try installing it globally and run it on a single file or remove the ignore from the file temporarily.
Is there anything else I need do to get this PR ready for merge? |
There are still a few stylistic things. I'm in the process of enabling eslint here so that these files get linted and can tell you what's going on (namely use single quotes, match other styles with indentation, else bracing). If you rebase on top of #3206 (or it will be in master shortly I think) then you can see this yourself with |
The changes I made should be clean to eslint now (I ran it directly on -Jason
|
@@ -84,11 +121,13 @@ function renderXJSExpressionContainer(traverse, object, isLast, path, state) { | |||
if (!isLast && object.expression.type !== Syntax.XJSEmptyExpression) { | |||
// If we need to append a comma, make sure to do so after the expression. | |||
utils.catchup(object.expression.range[1], state, trimLeft); | |||
utils.append(', ', state); | |||
utils.catchup(object.range[1] -1, state, commaAfterLastParen) | |||
//utils.append(', ', state); |
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.
Lint doesn't catch it but please remove this.
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.
How embarrassing! I removed it now.
Thanks @zpao after rebase fixing the lint issues was easy. |
Let me know if you want me to squash some of these cleanup commits together |
var commaPos = 0; | ||
for (var i = 0; i < value.length; ++i) { | ||
if (state === 'normal') { | ||
if (value.charAt(i) === '/') { |
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.
State-machine type of deal and all that... but this could be reduced to value.substr(i, 2) === '//'
, etc. @zpao?
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.
I suppose it wouldn't surprise you that my day job uses mostly C...
Any other changes needed? |
Just checking in on the status of this. |
Just checking in to see if any action is needed by me on this. |
Sorry, been focused on shipping 0.13. This won't make that cut but I'll come back to it after. In the mean time, this doesn't merge cleanly (probably mostly just because xjs.js is now jsx.js) so getting it back into a mergable state will help. |
Requested by @syranide
This flattens the if/else structure quite a bit.
Also now ran eslint on this. The part that I added is now clean on eslint (the rest of the file not so much)
Now rebased on top of master |
0.13 is out now. @zpao: Let me know if I'm being too annoying. |
Put comma after any non-whitespace non-comment characters in JSXExpression
Squashed and landed as ef79679. Thanks and I'm sorry it took as long as it did! |
For some reason the comma was emitted in renderXJSExpressionContainer if
it was an XJSExpressionContainer, and in the caller of the function
otherwise. This made getting things like
<Foo bar=(baz) quux={biff} />
hard.
This should fix issue #1673