From 9eee88ac3eba44ac05ed376f6c7395eff6ea788d Mon Sep 17 00:00:00 2001 From: Uriel Van Date: Mon, 15 Apr 2024 23:24:09 +0800 Subject: [PATCH] fix: incorrect newline --- src/newline.ts | 6 +++++- test/newline.test.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/newline.ts b/src/newline.ts index bb7f911..2b35af0 100644 --- a/src/newline.ts +++ b/src/newline.ts @@ -342,7 +342,11 @@ const rule: Rule.RuleModule = { }, fix: getFixer(source, node, false), }); - } else if (inSameLine) { + } else if ( + inSameLine + || isSameLine(openBrace, source.getTokenAfter(openBrace) as Token) + || isSameLine(source.getTokenBefore(closeBrace) as Token, closeBrace) + ) { ctx.report({ node, messageId: CONSIST_NEWLINE, diff --git a/test/newline.test.ts b/test/newline.test.ts index 0ffb46d..e4069fa 100644 --- a/test/newline.test.ts +++ b/test/newline.test.ts @@ -305,6 +305,14 @@ runner.run('option `allowAllPropertiesOnSameLine`', newline, { errors: [{ messageId: CONSIST_NEWLINE }], output: 'const {\na,\nb,\nc\n} = foo;', }, + { + code: 'const {a,\nb} = foo;', + options: [{ + allowAllPropertiesOnSameLine: true, + }], + errors: [{ messageId: CONSIST_NEWLINE }], + output: 'const {\na,\nb\n} = foo;', + }, ], });