From 14ae2802a2b8ed17cf628bfd103599e547ccac0b Mon Sep 17 00:00:00 2001 From: Amin Mirzaee Date: Tue, 16 Jan 2018 22:02:41 -0500 Subject: [PATCH] Fix Space after Comma rule with CSX format described in #629 --- src/rules/spacing_after_comma.coffee | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/rules/spacing_after_comma.coffee b/src/rules/spacing_after_comma.coffee index 009fd2b5..bf926e3a 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 false + # 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