From c0664e8946ba3263cfb564aa245e45aad1eeefe3 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Wed, 10 Nov 2021 15:59:25 +0100 Subject: [PATCH] feat(tools): remove ts-ignore pragmas from stories during migration --- .../migrate-converged-pkg/index.spec.ts | 35 ++++++++++++++++++- .../generators/migrate-converged-pkg/index.ts | 33 +++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/tools/generators/migrate-converged-pkg/index.spec.ts b/tools/generators/migrate-converged-pkg/index.spec.ts index 404e6b703b48d4..0ffb76f89abf0d 100644 --- a/tools/generators/migrate-converged-pkg/index.spec.ts +++ b/tools/generators/migrate-converged-pkg/index.spec.ts @@ -641,6 +641,39 @@ describe('migrate-converged-pkg generator', () => { ]), ); }); + + it(`should remove @ts-ignore pragmas from all stories`, async () => { + const { paths } = setup({ createDummyStories: true }); + append( + tree, + paths.storyOne, + stripIndents` + // https://github.com/microsoft/fluentui/pull/18695#issuecomment-868432982 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + import { Button } from '@fluentui/react-button'; + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + import { Text } from '@fluentui/react-text'; + `, + ); + + await generator(tree, options); + + expect(tree.read(paths.storyOne)?.toString('utf-8')).toMatchInlineSnapshot(` + "import * as Implementation from './index'; + export const Foo = (props: FooProps) => { return
Foo
; }\\\\n + + + + import { Button } from '@fluentui/react-button'; + + + + import { Text } from '@fluentui/react-text';" + `); + }); }); describe(`e2e config`, () => { @@ -1254,7 +1287,7 @@ function append(tree: Tree, filePath: string, content: string) { filePath, stripIndents` ${tree.read(filePath)?.toString('utf-8')}\n - ${content}; + ${content} `, ); diff --git a/tools/generators/migrate-converged-pkg/index.ts b/tools/generators/migrate-converged-pkg/index.ts index 3c5ab08e87a26b..864b80e541dae3 100644 --- a/tools/generators/migrate-converged-pkg/index.ts +++ b/tools/generators/migrate-converged-pkg/index.ts @@ -587,6 +587,8 @@ function setupStorybook(tree: Tree, options: NormalizedSchema) { return json; }); + + removeTsIgnorePragmas(); } if (sbAction === 'remove') { @@ -621,6 +623,37 @@ function setupStorybook(tree: Tree, options: NormalizedSchema) { }); } + function removeTsIgnorePragmas() { + const stories: string[] = []; + visitNotIgnoredFiles(tree, options.paths.sourceRoot, treePath => { + if (treePath.includes('.stories.')) { + stories.push(treePath); + } + }); + + stories.forEach(storyPath => { + const content = tree.read(storyPath)?.toString('utf-8'); + + if (!content) { + throw new Error('story file has no code'); + } + + let updatedContent = content.replace(/\/\/\s+@ts-ignore/g, ''); + updatedContent = updatedContent.replace( + /\/\/\s+eslint-disable-next-line\s+@typescript-eslint\/ban-ts-comment/g, + '', + ); + updatedContent = updatedContent.replace( + /\/\/\s+https:\/\/github\.com\/microsoft\/fluentui\/pull\/18695#issuecomment-868432982/g, + '', + ); + + tree.write(storyPath, updatedContent); + }); + + return tree; + } + return tree; }