From 3533fee96f771655f0eaddc8d7469a0ed64ad122 Mon Sep 17 00:00:00 2001 From: shufo Date: Fri, 4 Mar 2022 04:02:20 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20formatted=20include=20dir?= =?UTF-8?q?ective=20adds=20unnecessary=20comma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: #504 --- __tests__/formatter.test.ts | 14 ++++++++++++++ src/formatter.ts | 1 + 2 files changed, 15 insertions(+) diff --git a/__tests__/formatter.test.ts b/__tests__/formatter.test.ts index 7d1d4200..190ba1ee 100644 --- a/__tests__/formatter.test.ts +++ b/__tests__/formatter.test.ts @@ -2555,4 +2555,18 @@ describe('formatter', () => { await util.doubleFormatCheck(content, expected); }); + + test('@include directive should not add an extra comma on long view name #504', async () => { + const content = [`@include('livewire.cx.equipment-list-internal.account', ['account' => $account])`].join('\n'); + + const expected = [ + `@include(`, + ` 'livewire.cx.equipment-list-internal.account',`, + ` ['account' => $account]`, + `)`, + ``, + ].join('\n'); + + await util.doubleFormatCheck(content, expected); + }); }); diff --git a/src/formatter.ts b/src/formatter.ts index 2f56d7a8..8dd7e522 100644 --- a/src/formatter.ts +++ b/src/formatter.ts @@ -968,6 +968,7 @@ export default class Formatter { const inside = util .formatRawStringAsPhp(`func_inline_for_${p3}${p4}`, 80, true) .replace(/([\n\s]*)->([\n\s]*)/gs, '->') + .replace(/,(\s*?\))/gis, (_match5, p5) => p5) .trim() // @ts-expect-error ts-migrate(2554) FIXME: Expected 0 arguments, but got 1. .trimRight('\n');