From 4d7ce40469c22a52f58c81ac7d5bfb7b15c0bd69 Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Thu, 4 Jun 2026 17:00:56 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20newline=20being=20removed?= =?UTF-8?q?=20for=20existing=20import=20&=20fix=20transform=20errors=20for?= =?UTF-8?q?=20a11y=20ignores=20codemod=20(#3183)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 newline being removed for existing import & fix errors * fix: 🐛 avoid testName being undefined --- support/ember-a11y-ignore.mjs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/support/ember-a11y-ignore.mjs b/support/ember-a11y-ignore.mjs index fcc7e95f0..89b00a454 100644 --- a/support/ember-a11y-ignore.mjs +++ b/support/ember-a11y-ignore.mjs @@ -90,10 +90,10 @@ export default function transformer(file, api) { } else { // if an array is provided and it's argument is a literal (number, boolean, string) then this is used for the test name // otherwise if it's an object the index in the array is what is used for the test name - eachTestNames = testArguments[1].elements.map((element, i) => element.type.endsWith('Literal') ? element.value : i); + eachTestNames = testArguments[1].elements?.map((element, i) => element.type.endsWith('Literal') ? element.value : i); } - testName = eachTestNames.map(eachTestName => `${testName} [${eachTestName}]`); + testName = eachTestNames?.map(eachTestName => `${testName} [${eachTestName}]`) ?? []; } else { testName = [testName]; } @@ -270,16 +270,27 @@ export default function transformer(file, api) { } }; + const existingEmberA11yImport = f.find(j.ImportDeclaration, { + source: { + value: 'ember-a11y-testing/test-support', + }, + }); + tests.forEach(testHandler); testsEach.forEach(testHandler); const code = f.toSource(); - // the codemod will insert a newline between existing import statements, - // this regex removes the extra new line - // - return code.replace( - /(?\n)(import .*ember-a11y-testing\/test-support.*)/g, - '$2', - ); + + + if (existingEmberA11yImport.length > 0) { + return code; + } else { + // the codemod will insert a newline between existing import statements, + // this regex removes the extra new line + return code.replace( + /(?\n)(import .*ember-a11y-testing\/test-support.*)/g, + '$2', + ); + } }