Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Fix Space after Comma rule with CSX format described in clutchski#629
Browse files Browse the repository at this point in the history
  • Loading branch information
aminland committed Jan 17, 2018
1 parent 96aadf0 commit 14ae280
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/rules/spacing_after_comma.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14ae280

Please sign in to comment.