diff --git a/.gitattributes b/.gitattributes index 0734f3c7a7f..8bba692ab81 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/src/rules/objectLiteralSortKeysRule.ts b/src/rules/objectLiteralSortKeysRule.ts index a2be46ecb43..eb72e978bdc 100644 --- a/src/rules/objectLiteralSortKeysRule.ts +++ b/src/rules/objectLiteralSortKeysRule.ts @@ -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 { diff --git a/test/rules/object-literal-sort-keys/default/crlf.ts.lint b/test/rules/object-literal-sort-keys/default/crlf.ts.lint new file mode 100644 index 00000000000..1aea24abe6f --- /dev/null +++ b/test/rules/object-literal-sort-keys/default/crlf.ts.lint @@ -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] +}