From 2d0a49b4053020ca15f0189748da811c5e516fc3 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Tue, 31 Oct 2017 23:06:20 +0100 Subject: [PATCH] object-literal-sort-keys: don't consider \r\n as two line breaks (#3427) [bugfix] `object-literal-sort-keys` fixed regression that effectively disabled the rule with `\r\n` line breaks Fixes: #3426 --- .gitattributes | 1 + src/rules/objectLiteralSortKeysRule.ts | 2 +- test/rules/object-literal-sort-keys/default/crlf.ts.lint | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/rules/object-literal-sort-keys/default/crlf.ts.lint 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] +}