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 d02c815
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/rules/spacing_after_comma.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,28 @@ 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 code generation when using CSX syntax, and it adds
# brackets & commas that are not marked as generated. The only way to check
# these is to see if the comma has the same column number as the last token.
isGenerated: (token, tokenApi) ->
return true if token.generated
offset = -1
prevToken = tokenApi.peek(offset)
while prevToken.generated
offset -= 1
prevToken = tokenApi.peek(offset)
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 d02c815

Please sign in to comment.