From fac246521934558265242f27c3f8b46184bbba1e Mon Sep 17 00:00:00 2001 From: Kasper Peulen Date: Tue, 29 Nov 2022 16:28:00 +0100 Subject: [PATCH] No unused locals in tsconfig to disable deepscan Deep scan is not compatible with TS 4.9 yet. And the only issues it seems to find that are not covered yet by TS or ESLint are unused imports. TSC can catch those by enabling noUnusedLocals in tsconfig. --- .../actions/src/containers/ActionLogger/index.tsx | 1 + .../toolbars/src/components/ToolbarMenuList.tsx | 10 +--------- .../src/client/angular-beta/RendererFactory.test.ts | 5 +---- .../src/server/framework-preset-angular-cli.test.ts | 11 ----------- code/frameworks/angular/tsconfig.build.json | 3 ++- code/lib/cli/src/generators/baseGenerator.ts | 1 - .../convert/__testfixtures__/typescript/optionals.tsx | 2 +- code/lib/manager-api/src/tests/stories.test.ts | 1 - .../preview-api/src/modules/core-client/start.test.ts | 2 +- .../src/modules/preview-web/PreviewWeb.test.ts | 2 +- .../preview-api/src/modules/store/StoryStore.test.ts | 2 +- code/renderers/svelte/src/public-types.test.ts | 2 ++ code/renderers/vue3/src/public-types.test.ts | 1 + .../web-components/src/docs/custom-elements.ts | 8 -------- code/tsconfig.json | 3 ++- code/ui/manager/src/runtime.ts | 1 + scripts/tsconfig.json | 4 ++-- 17 files changed, 17 insertions(+), 42 deletions(-) diff --git a/code/addons/actions/src/containers/ActionLogger/index.tsx b/code/addons/actions/src/containers/ActionLogger/index.tsx index ab3fc51ab3cf..5f3a07941a89 100644 --- a/code/addons/actions/src/containers/ActionLogger/index.tsx +++ b/code/addons/actions/src/containers/ActionLogger/index.tsx @@ -26,6 +26,7 @@ const safeDeepEqual = (a: any, b: any): boolean => { }; export default class ActionLogger extends Component { + // @ts-expect-error Unused, possibly remove, leaving, because it could be accessed even though it is private private mounted: boolean; constructor(props: ActionLoggerProps) { diff --git a/code/addons/toolbars/src/components/ToolbarMenuList.tsx b/code/addons/toolbars/src/components/ToolbarMenuList.tsx index 55a3d4358d14..95bd0c205dff 100644 --- a/code/addons/toolbars/src/components/ToolbarMenuList.tsx +++ b/code/addons/toolbars/src/components/ToolbarMenuList.tsx @@ -1,4 +1,4 @@ -import type { FC, ReactNode } from 'react'; +import type { FC } from 'react'; import React, { useCallback } from 'react'; import { useGlobals } from '@storybook/manager-api'; import { deprecate } from '@storybook/client-logger'; @@ -10,14 +10,6 @@ import { getSelectedIcon, getSelectedTitle } from '../utils/get-selected'; import type { ToolbarMenuProps } from '../types'; import { ToolbarMenuListItem } from './ToolbarMenuListItem'; -type ItemProps = { - left?: ReactNode; - title?: ReactNode; - right?: ReactNode; - active?: boolean; - onClick?: () => void; -}; - type ToolbarMenuListProps = ToolbarMenuProps & WithKeyboardCycleProps; export const ToolbarMenuList: FC = withKeyboardCycle( diff --git a/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts b/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts index a50a8c5ff80c..7ad36c281979 100644 --- a/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts +++ b/code/frameworks/angular/src/client/angular-beta/RendererFactory.test.ts @@ -306,10 +306,7 @@ describe('RendererFactory', () => { .appendChild(global.document.createElement('👾')); expect(global.document.getElementById('storybook-root').innerHTML).toContain('Canvas 🖼'); - const render = await rendererFactory.getRendererInstance( - 'my-story-in-docs', - rootDocstargetDOMNode - ); + await rendererFactory.getRendererInstance('my-story-in-docs', rootDocstargetDOMNode); expect(global.document.getElementById('storybook-root').innerHTML).toBe(''); }); }); diff --git a/code/frameworks/angular/src/server/framework-preset-angular-cli.test.ts b/code/frameworks/angular/src/server/framework-preset-angular-cli.test.ts index 6dfbdd7123bd..3581d656088e 100644 --- a/code/frameworks/angular/src/server/framework-preset-angular-cli.test.ts +++ b/code/frameworks/angular/src/server/framework-preset-angular-cli.test.ts @@ -34,11 +34,8 @@ describe('framework-preset-angular-cli', () => { }); describe('without angular.json', () => { - let consoleErrorSpy: jest.SpyInstance; - beforeEach(() => { initMockWorkspace(''); - consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); }); it('should return webpack base config and display log error', async () => { const webpackBaseConfig = newWebpackConfiguration(); @@ -421,10 +418,6 @@ describe('framework-preset-angular-cli', () => { it('should set webpack "module.rules"', async () => { const baseWebpackConfig = newWebpackConfiguration(); const webpackFinalConfig = await webpackFinal(baseWebpackConfig, options); - const stylePaths = [ - path.join(workspaceRoot, 'src', 'styles.css'), - path.join(workspaceRoot, 'src', 'styles.scss'), - ]; const expectedRules: any = [ { @@ -507,10 +500,6 @@ describe('framework-preset-angular-cli', () => { it('should set webpack "module.rules"', async () => { const baseWebpackConfig = newWebpackConfiguration(); const webpackFinalConfig = await webpackFinal(baseWebpackConfig, options); - const stylePaths = [ - path.join(workspaceRoot, 'src', 'styles.css'), - path.join(workspaceRoot, 'src', 'styles.scss'), - ]; const expectedRules: any = [ { diff --git a/code/frameworks/angular/tsconfig.build.json b/code/frameworks/angular/tsconfig.build.json index e6ebc0167a55..6aa09e55adac 100644 --- a/code/frameworks/angular/tsconfig.build.json +++ b/code/frameworks/angular/tsconfig.build.json @@ -15,7 +15,8 @@ "allowJs": true, "pretty": true, "noErrorTruncation": true, - "listEmittedFiles": false + "listEmittedFiles": false, + "noUnusedLocals": false }, "include": ["src/**/*", "src/**/*.json"] } diff --git a/code/lib/cli/src/generators/baseGenerator.ts b/code/lib/cli/src/generators/baseGenerator.ts index 193d9114a961..027a45df129b 100644 --- a/code/lib/cli/src/generators/baseGenerator.ts +++ b/code/lib/cli/src/generators/baseGenerator.ts @@ -129,7 +129,6 @@ export async function baseGenerator( const { packages: frameworkPackages, type, - renderer: rendererInclude, // deepscan-disable-line UNUSED_DECL rendererId, framework: frameworkInclude, builder: builderInclude, diff --git a/code/lib/docs-tools/src/argTypes/convert/__testfixtures__/typescript/optionals.tsx b/code/lib/docs-tools/src/argTypes/convert/__testfixtures__/typescript/optionals.tsx index 16ac1e11b88c..b5a3e7d65647 100644 --- a/code/lib/docs-tools/src/argTypes/convert/__testfixtures__/typescript/optionals.tsx +++ b/code/lib/docs-tools/src/argTypes/convert/__testfixtures__/typescript/optionals.tsx @@ -17,5 +17,5 @@ export const Component: FC = ({ ...rest }: Props) => { const props = { any, string, bool, number, ...rest }; - return <>JSON.stringify(props); + return <>{JSON.stringify(props)}; }; diff --git a/code/lib/manager-api/src/tests/stories.test.ts b/code/lib/manager-api/src/tests/stories.test.ts index e0e0159439f9..072527e8eb50 100644 --- a/code/lib/manager-api/src/tests/stories.test.ts +++ b/code/lib/manager-api/src/tests/stories.test.ts @@ -876,7 +876,6 @@ describe('stories API', () => { const { api: { setIndex, jumpToStory }, - state, } = initStories({ store, navigate, provider } as any); setIndex({ v: 4, entries: navigationEntries }); diff --git a/code/lib/preview-api/src/modules/core-client/start.test.ts b/code/lib/preview-api/src/modules/core-client/start.test.ts index cee6e19bbe58..96158c8e92a4 100644 --- a/code/lib/preview-api/src/modules/core-client/start.test.ts +++ b/code/lib/preview-api/src/modules/core-client/start.test.ts @@ -386,7 +386,7 @@ describe('start', () => { it('re-emits SET_INDEX when a story is added', async () => { const renderToCanvas = jest.fn(({ storyFn }) => storyFn()); - const { configure, clientApi, forceReRender } = start(renderToCanvas); + const { configure, clientApi } = start(renderToCanvas); let disposeCallback: () => void = () => {}; const module = { diff --git a/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts b/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts index ad533c6debc1..79e9769c728d 100644 --- a/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts +++ b/code/lib/preview-api/src/modules/preview-web/PreviewWeb.test.ts @@ -775,7 +775,7 @@ describe('PreviewWeb', () => { it('passes globals in context to renderToCanvas', async () => { document.location.search = '?id=component-one--a'; - const preview = await createAndRenderPreview(); + await createAndRenderPreview(); mockChannel.emit.mockClear(); projectAnnotations.renderToCanvas.mockClear(); diff --git a/code/lib/preview-api/src/modules/store/StoryStore.test.ts b/code/lib/preview-api/src/modules/store/StoryStore.test.ts index 86fe210bb1f1..3beb34f11d62 100644 --- a/code/lib/preview-api/src/modules/store/StoryStore.test.ts +++ b/code/lib/preview-api/src/modules/store/StoryStore.test.ts @@ -208,7 +208,7 @@ describe('StoryStore', () => { store.setProjectAnnotations(projectAnnotations); store.initialize({ storyIndex, importFn, cache: false }); - const story = await store.loadStory({ storyId: 'component-one--a' }); + await store.loadStory({ storyId: 'component-one--a' }); expect(processCSFFile).toHaveBeenCalledTimes(1); expect(prepareStory).toHaveBeenCalledTimes(1); diff --git a/code/renderers/svelte/src/public-types.test.ts b/code/renderers/svelte/src/public-types.test.ts index 72855a7bd519..8aadbc61740b 100644 --- a/code/renderers/svelte/src/public-types.test.ts +++ b/code/renderers/svelte/src/public-types.test.ts @@ -59,6 +59,7 @@ describe('Meta', () => { }, }), }; + expectTypeOf(meta).toMatchTypeOf>(); }); test('Events fallback to custom events when no component is specified', () => { @@ -75,6 +76,7 @@ describe('Meta', () => { }, }), }; + expectTypeOf(meta).toMatchTypeOf>(); }); }); diff --git a/code/renderers/vue3/src/public-types.test.ts b/code/renderers/vue3/src/public-types.test.ts index 6114137c9478..8c184047e098 100644 --- a/code/renderers/vue3/src/public-types.test.ts +++ b/code/renderers/vue3/src/public-types.test.ts @@ -60,6 +60,7 @@ describe('Meta', () => { }); }, }; + expectTypeOf(meta).toMatchTypeOf>(); }); }); diff --git a/code/renderers/web-components/src/docs/custom-elements.ts b/code/renderers/web-components/src/docs/custom-elements.ts index fe8cbc633a65..66743bfdd7a8 100644 --- a/code/renderers/web-components/src/docs/custom-elements.ts +++ b/code/renderers/web-components/src/docs/custom-elements.ts @@ -37,14 +37,6 @@ interface Module { interface Declaration { tagName: string; } -interface Sections { - attributes?: any; - properties?: any; - events?: any; - slots?: any; - cssCustomProperties?: any; - cssShadowParts?: any; -} function mapItem(item: TagItem, category: string): InputType { const type = diff --git a/code/tsconfig.json b/code/tsconfig.json index 645fbb05c512..b8f48b0d7ead 100644 --- a/code/tsconfig.json +++ b/code/tsconfig.json @@ -14,7 +14,8 @@ "esModuleInterop": true, "isolatedModules": true, "strictBindCallApply": true, - "lib": ["dom", "esnext"] + "lib": ["dom", "esnext"], + "noUnusedLocals": true }, "exclude": ["dist", "**/dist", "node_modules", "**/node_modules", "**/setup-jest.ts"], "ts-node": { diff --git a/code/ui/manager/src/runtime.ts b/code/ui/manager/src/runtime.ts index 55b35f7c3927..ebe5f040457f 100644 --- a/code/ui/manager/src/runtime.ts +++ b/code/ui/manager/src/runtime.ts @@ -18,6 +18,7 @@ const { FEATURES, SERVER_CHANNEL_URL } = global; class ReactProvider extends Provider { private addons: AddonStore; + // @ts-expect-error Unused, possibly remove, leaving, because it could be accessed even though it is private private channel: Channel; private serverChannel?: Channel; diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 4c508e21aac4..a65f7f5b06f8 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -24,7 +24,7 @@ "strict": false, "strictNullChecks": false, "forceConsistentCasingInFileNames": true, - "noUnusedLocals": false, + "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, @@ -33,7 +33,7 @@ "verdaccio": [ "./typings.d.ts" ] - } + }, }, "exclude": [ "dist",