Skip to content

Commit 2d0a49b

Browse files
ajafffadidahiya
authored andcommitted
object-literal-sort-keys: don't consider \r\n as two line breaks (palantir#3427)
[bugfix] `object-literal-sort-keys` fixed regression that effectively disabled the rule with `\r\n` line breaks Fixes: palantir#3426
1 parent 9632094 commit 2d0a49b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
/test/rules/linebreak-style/**/CRLF/*.lint text eol=crlf
88
/test/rules/linebreak-style/**/LF/*.fix text eol=crlf
99
/test/rules/jsdoc-format/**/jsdoc-windows.ts.lint text eol=crlf
10+
/test/rules/object-literal-sort-keys/default/crlf.ts.lint eol=crlf

src/rules/objectLiteralSortKeysRule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ function hasBlankLineBefore(sourceFile: ts.SourceFile, element: ts.ObjectLiteral
208208
}
209209

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

214214
function getTypeName(t: TypeLike): string | undefined {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// ensure that we don't treat \r\n as two line breaks
2+
let obj = {
3+
foo: 1,
4+
bar: 2,
5+
~~~ [The key 'bar' is not sorted alphabetically]
6+
}

0 commit comments

Comments
 (0)