diff --git a/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.spec.ts b/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.spec.ts index 6f72c9d7443f9..d39970c561796 100644 --- a/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.spec.ts +++ b/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.spec.ts @@ -59,4 +59,27 @@ describe('update-16-0-0-add-nx-packages', () => { } `); }); + + it('should replace eslint-ignore comments', async () => { + tree.write( + 'ignored-file.ts', + '// eslint-disable-next-line @nrwl/nx/enforce-module-boundaries\n /*\n* eslint-disable @nrwl/nx/enforce-module-boundaries\n*/\n // eslint-disable-line @nrwl/nx/enforce-module-boundaries' + ); + tree.write('plugin.ts', `import * as p from '@nrwl/nx-plugin'`); + + await replacePackage(tree); + + expect(tree.read('ignored-file.ts').toString()).toMatchInlineSnapshot(` + "// eslint-disable-next-line @nx/enforce-module-boundaries + /* + * eslint-disable @nx/enforce-module-boundaries + */ + // eslint-disable-line @nx/enforce-module-boundaries + " + `); + expect(tree.read('plugin.ts').toString()).toMatchInlineSnapshot(` + "import * as p from '@nrwl/nx-plugin'; + " + `); + }); }); diff --git a/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.ts b/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.ts index 43558164d854e..3004b05837432 100644 --- a/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.ts +++ b/packages/eslint-plugin/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.ts @@ -20,18 +20,26 @@ export default async function replacePackage(tree: Tree): Promise { '@nx/eslint-plugin' ); + /** + * Matches: + * * // eslint-disable-next-line @nrwl/nx/... + * * // eslint-disable-line @nrwl/nx/... + * * /* eslint-disable @nrwl/nx/... + */ + const ignoreLineRegex = /(eslint-disable(?:(?:-next)?-line)?\s*)@nrwl\/nx/g; visitNotIgnoredFiles(tree, '.', (path) => { - if (!eslintFileNames.includes(basename(path))) { - return; - } - - const contents = tree.read(path).toString(); + let contents = tree.read(path).toString(); + if (eslintFileNames.includes(basename(path))) { + if (!contents.includes('@nrwl/nx')) { + return; + } - if (!contents.includes('@nrwl/nx')) { - return; + contents = contents.replace(new RegExp('@nrwl/nx', 'g'), '@nx'); } - - tree.write(path, contents.replace(new RegExp('@nrwl/nx', 'g'), '@nx')); + if (ignoreLineRegex.test(contents)) { + contents = contents.replace(ignoreLineRegex, '$1@nx'); + } + tree.write(path, contents); }); await formatFiles(tree);