From c9226613d98ee0a5ac5959a9dde2a276d84c2233 Mon Sep 17 00:00:00 2001 From: Andreas Kohn Date: Fri, 2 Oct 2020 14:08:51 +0200 Subject: [PATCH] Update the eslint configuration to allow editors to understand it Explicitly listing the .storybook/stories path in the package.json's `test:lint` invocation works for ensuring that things get linted as part of the CI process, but VSCode (or any other editor, for that matter) isn't aware of that and won't flag issues in these files. This leads to multiple "fix warnings" commits and releases that are not working. Instead this commit changes the .eslintignore file to explicitly un-ignore the .storybook directory as advised by https://github.com/eslint/eslint/issues/12348#issuecomment-536946429. Note that this commit also fixes a bunch of now-reported warnings in other files that previously got excluded. --- .eslintignore | 2 ++ .storybook/typings.d.ts | 1 - .storybook/utils.ts | 10 ++++++++-- package.json | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.eslintignore b/.eslintignore index 045ab4f..15374d2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -4,3 +4,5 @@ node_modules/ storybook-static/ .snapshots/ *.min.js +# See https://github.com/eslint/eslint/issues/12348#issuecomment-536946429 +!.storybook diff --git a/.storybook/typings.d.ts b/.storybook/typings.d.ts index 9b9c211..f98b3ea 100644 --- a/.storybook/typings.d.ts +++ b/.storybook/typings.d.ts @@ -1,4 +1,3 @@ - interface SvgrComponent extends React.StatelessComponent> {} diff --git a/.storybook/utils.ts b/.storybook/utils.ts index 751f6ab..ce9cc93 100644 --- a/.storybook/utils.ts +++ b/.storybook/utils.ts @@ -1,8 +1,14 @@ import { StoryFn, Annotations, Args } from '@storybook/addons'; -type OptionalStoryInterface = Annotations & { storyName?: string }; +type OptionalStoryInterface = Annotations< + Args, + ReturnType +> & { storyName?: string }; -export function withDescription & OptionalStoryInterface, R>(storyDescription: string, story: T): T & OptionalStoryInterface { +export function withDescription< + T extends StoryFn & OptionalStoryInterface, + R +>(storyDescription: string, story: T): T & OptionalStoryInterface { story.parameters = { ...story.parameters, docs: { diff --git a/package.json b/package.json index 85a0ca5..14147d2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "build": "tsc --noEmit false", "test": "run-s test:lint test:build test:unit", "test:build": "tsc --noEmit -p tsconfig.test.json", - "test:lint": "eslint '*/**/*.{js,ts,tsx}' '.storybook/stories/**/*.{js,ts,tsx}'", + "test:lint": "eslint '*/**/*.{js,ts,tsx}'", "test:unit": "cross-env CI=1 SKIP_PREFLIGHT_CHECK=true react-scripts test --env=jsdom --passWithNoTests", "test:watch": "cross-env SKIP_PREFLIGHT_CHECK=true react-scripts test --env=jsdom", "predeploy": "run-s storybook:build",