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
Created no-dangle rule. #87
Conversation
This regex is not going to be sufficient. You should be using the token stream and looking at the token right before the closing curly brace. |
I agree, can you use getTokens() instead? |
Thanks guys! I knew there had to be a better way to do that! I've rewritten and re-pushed the commit for the rule using the new approach. |
Very nice. So much better. |
Shouldn't you be able to apply this same rule to ArrayExpressions? |
@michaelficarra Yes! That's a good point. |
Created the no-dangle rule, which warns when it encounters a trailing comma in an object literal. The following will raise warnings: var foo = { bar: "baz", } Fixes issue eslint#13
... or we could just forget about them |
@nzakas ? |
@michaelficarra Checking ArrayExpressions for trailing commas was in the commit that was merged. |
Ah, I see. I did not see that you updated the pull request already. Thanks for the clarification! |
secondToLastToken = tokens[tokens.length - 2]; | ||
|
||
// The last token in an object/array literal will always be a closing | ||
// curly, so we check the second to last token for a comma. |
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.
always be a closing curly
or square bracket
This matches JSHint, so I'm happy. :) |
Created the
no-dangle
rule, which warns when it encounters a trailing comma in an object literal. The following will raise warnings:I've accomplished trailing comma detection by doing a regex match on the
ObjectExpression
node source. I investigated inspecting theObjectExpression
's properties, however they don't seem to contain any comma information. This seemed like the best possible way to get this rule, but I'd love to hear if there's a better approach.I've defaulted
no-dangle
to on, because trailing commas will cause errors in IE, so it seemed like a sane default.Fixes issue #13