From 916fb69e7b0b75f79b1f617b37682899a4f91ddf Mon Sep 17 00:00:00 2001 From: Steven Rathbauer Date: Fri, 23 Jun 2023 14:22:51 +0000 Subject: [PATCH] fix(storybook): fix 6.1.0 migration to prevent wiping out root eslintrc closed #17748 --- .../eslint-ignore-react-plugin.spec.ts | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/storybook/src/migrations/update-16-1-0/eslint-ignore-react-plugin.spec.ts b/packages/storybook/src/migrations/update-16-1-0/eslint-ignore-react-plugin.spec.ts index 58c9ed5a4e514e..b222e60e5fb546 100644 --- a/packages/storybook/src/migrations/update-16-1-0/eslint-ignore-react-plugin.spec.ts +++ b/packages/storybook/src/migrations/update-16-1-0/eslint-ignore-react-plugin.spec.ts @@ -40,18 +40,37 @@ describe('Ignore @nx/react/plugins/storybook in Storybook eslint plugin', () => ); if (!tree.exists('.eslintrc.json')) { - tree.write('.eslintrc.json', '{}'); + tree.write('.eslintrc.json', `{}`); } - updateJson(tree, '.eslintrc.json', (json) => { - json.extends ??= []; - json.extends.push('plugin:storybook/recommended'); - return json; - }); }); it('should not ignore the plugin if it is not used', async () => { await eslintIgnoreReactPlugin(tree); const eslintConfig = readJson(tree, '.eslintrc.json'); + expect(eslintConfig).toEqual({}); + expect(eslintConfig.rules).toBeUndefined(); + }); + + it('should not ignore the plugin if "plugin:storybook/recommended" is not included', async () => { + tree.write('apps/main-webpack/tsconfig.json', `{}`); + tree.write( + `apps/main-webpack/.storybook/main.js`, + ` + module.exports = { + stories: ['../src/lib/**/*.stories.@(mdx|js|jsx|ts|tsx)'], + addons: ['@storybook/addon-essentials', '@nx/react/plugins/storybook'], + framework: { + name: '@storybook/react-webpack5', + options: {}, + }, + }; + ` + ); + + await eslintIgnoreReactPlugin(tree); + + const eslintConfig = readJson(tree, '.eslintrc.json'); + expect(eslintConfig).toEqual({}); expect(eslintConfig.rules).toBeUndefined(); }); @@ -71,6 +90,12 @@ describe('Ignore @nx/react/plugins/storybook in Storybook eslint plugin', () => ` ); + updateJson(tree, '.eslintrc.json', (json) => { + json.extends ??= []; + json.extends.push('plugin:storybook/recommended'); + return json; + }); + await eslintIgnoreReactPlugin(tree); const eslintConfig = readJson(tree, '.eslintrc.json');