Skip to content

Commit

Permalink
fix: support CRLF line breaks in generic-spacing (#485) (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
avi-moskoff committed Jul 22, 2021
1 parent 417068c commit 79267bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/rules/genericSpacing.js
Expand Up @@ -31,7 +31,8 @@ const create = (context) => {

if (never) {
if (spacesBefore) {
if (sourceCode.text[opener.range[1]] !== '\n') {
const whiteSpaceBefore = sourceCode.text[opener.range[1]];
if (whiteSpaceBefore !== '\n' && whiteSpaceBefore !== '\r') {
context.report({
data: {name: node.id.name},
fix: spacingFixers.stripSpacesAfter(opener, spacesBefore),
Expand All @@ -42,7 +43,8 @@ const create = (context) => {
}

if (spacesAfter) {
if (sourceCode.text[closer.range[0] - 1] !== '\n') {
const whiteSpaceAfter = sourceCode.text[closer.range[0] - 1];
if (whiteSpaceAfter !== '\n' && whiteSpaceAfter !== '\r') {
context.report({
data: {name: node.id.name},
fix: spacingFixers.stripSpacesAfter(lastInnerToken, spacesAfter),
Expand Down
3 changes: 2 additions & 1 deletion tests/rules/assertions/genericSpacing.js
Expand Up @@ -133,8 +133,9 @@ export default {
`type X = Promise<
(foo),
bar,
(((baz))),
(((baz)))
>`},
{code: 'type X = Promise<\r\n (foo),\r\n bar,\r\n (((baz)))\r\n>'},

// Always

Expand Down

0 comments on commit 79267bb

Please sign in to comment.