Skip to content

Commit

Permalink
fix(linter): replace eslint ignore comments during @nrwl -> @nx migra… (
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Apr 24, 2023
1 parent 6c613ce commit aeb5950
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
"
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ export default async function replacePackage(tree: Tree): Promise<void> {
'@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);
Expand Down

1 comment on commit aeb5950

@vercel
Copy link

@vercel vercel bot commented on aeb5950 Apr 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app

Please sign in to comment.