diff --git a/src/rules/spacing_after_comma.coffee b/src/rules/spacing_after_comma.coffee index 009fd2b5..c661da98 100644 --- a/src/rules/spacing_after_comma.coffee +++ b/src/rules/spacing_after_comma.coffee @@ -22,10 +22,26 @@ module.exports = class SpacingAfterComma @inRegex = false return - unless token.spaced or token.newLine or token.generated or + unless token.spaced or token.newLine or @isGenerated(token, tokenApi) or @isRegexFlag(token, tokenApi) return true + # Coffeescript does some weird code generation when using CSX syntax, and it inserts + # brackets and commas that are not marked as generated. The only way to check for + # these is to see if the comma has the same column number as the last token. + isGenerated: (token, tokenApi) -> + return true if token.generated + + prevToken = tokenApi.peek(-1) + while prevToken.generated + prevToken = tokenApi.peek(-1) + pos = token[2] + prevPos = prevToken[2] + if pos.first_line == prevPos.first_line and pos.first_column == prevPos.first_column + return true + + return maybeEnd?[0] is 'REGEX_END' + # When generating a regex (///${whatever}///i) CoffeeScript generates tokens # for RegEx(whatever, "i") but doesn't bother to mark that comma as # generated or spaced. Looking 3 tokens ahead skips the STRING and CALL_END