Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
object-literal-sort-keys: don't consider \r\n as two line breaks (#3427)
Browse files Browse the repository at this point in the history
[bugfix] `object-literal-sort-keys` fixed regression that effectively disabled the rule with `\r\n` line breaks
Fixes: #3426
  • Loading branch information
ajafff authored and adidahiya committed Oct 31, 2017
1 parent 9632094 commit 2d0a49b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/test/rules/linebreak-style/**/CRLF/*.lint text eol=crlf
/test/rules/linebreak-style/**/LF/*.fix text eol=crlf
/test/rules/jsdoc-format/**/jsdoc-windows.ts.lint text eol=crlf
/test/rules/object-literal-sort-keys/default/crlf.ts.lint eol=crlf
2 changes: 1 addition & 1 deletion src/rules/objectLiteralSortKeysRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function hasBlankLineBefore(sourceFile: ts.SourceFile, element: ts.ObjectLiteral
}

function hasDoubleNewLine(sourceFile: ts.SourceFile, position: number) {
return /(\r\n|\r|\n){2}/.test(sourceFile.text.slice(position, position + 4));
return /(\r?\n){2}/.test(sourceFile.text.slice(position, position + 4));
}

function getTypeName(t: TypeLike): string | undefined {
Expand Down
6 changes: 6 additions & 0 deletions test/rules/object-literal-sort-keys/default/crlf.ts.lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// ensure that we don't treat \r\n as two line breaks
let obj = {
foo: 1,
bar: 2,
~~~ [The key 'bar' is not sorted alphabetically]
}

0 comments on commit 2d0a49b

Please sign in to comment.