From cedbd9f41305b97e0e4e0c224f98609d2f3b7ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Sch=C3=BCrch?= Date: Wed, 12 Jun 2024 13:10:42 +0200 Subject: [PATCH] chore(documentation): add linting for documentation package (#3128) --- .../post-card-control/post-card-control.tsx | 3 +- packages/documentation/.eslintrc.js | 55 + packages/documentation/package.json | 9 +- .../src/shared/tile/tile.component.ts | 2 +- .../components/accordion/accordion.stories.ts | 4 +- .../alert/standard-html/alert.stories.ts | 3 +- .../button-group/button-group.stories.ts | 2 +- .../components/button/button.stories.ts | 14 +- .../cards/card-button/card-button.stories.ts | 2 +- .../components/cards/card/card.stories.ts | 16 +- .../product-card/product-card.stories.ts | 24 +- .../stories/components/chip/chip.stories.ts | 6 +- .../collapsible.snapshot.stories.ts | 2 +- .../card-control.snapshot.stories.ts | 4 +- .../standard-html/card-control.stories.ts | 6 +- .../web-component/card-control.stories.ts | 15 +- .../forms/checkbox/checkbox.stories.ts | 2 +- .../forms/input/input.snapshot.stories.ts | 2 +- .../components/forms/switch/switch.stories.ts | 2 +- .../textarea/textarea.snapshot.stories.ts | 2 +- .../stories/components/icons/icon.stories.ts | 47 +- .../breadcrumbs/breadcrumbs.stories.ts | 6 +- .../internet-header/footer/footer.stories.ts | 6 +- .../components/spinner/spinner.stories.ts | 8 +- .../subnavigation/subnavigation.stories.ts | 11 +- .../stories/components/tabs/tabs.stories.ts | 4 +- .../tag/standard-html/tag.stories.ts | 1 + .../tag/web-component/post-tag.stories.ts | 17 +- .../stories/components/toast/toast.stories.ts | 6 +- .../stories/foundation/color/color.blocks.tsx | 1 + .../stories/foundation/color/color.docs.mdx | 32 +- .../foundation/elevation/elevation.blocks.tsx | 3 +- .../foundation/elevation/elevation.docs.mdx | 4 +- .../layout/breakpoints/breakpoints.blocks.tsx | 21 +- .../layout/containers/containers.blocks.tsx | 25 +- .../foundation/layout/grid/grid.blocks.tsx | 19 +- .../foundation/layout/grid/grid.docs.mdx | 8 +- .../foundation/layout/shared.blocks.tsx | 20 +- .../typography/typography.blocks.tsx | 39 +- .../stories/getting-started/list-component.ts | 2 +- .../migrationv4-5-manual-list.component.ts | 2 +- .../getting-started/migration-guide/types.ts | 2 +- .../migration-guide/util/persist.util.ts | 15 +- .../error-page/error-page.stories.ts | 4 +- .../utilities/background/background.docs.mdx | 16 +- .../utilities/spacing/spacing.docs.mdx | 6 +- .../utilities/spacing/spacing.stories.ts | 11 +- .../stories/utilities/text/text.blocks.tsx | 5 +- packages/documentation/src/utils/bomb-args.ts | 10 +- .../src/utils/codeOrSourceMdx.tsx | 1 + .../documentation/src/utils/get-attributes.ts | 6 +- .../utils/inputComponentsGetCombinations.ts | 8 +- packages/documentation/src/utils/react.ts | 12 +- .../documentation/src/utils/spread-args.ts | 34 +- packages/documentation/src/utils/version.ts | 41 +- packages/documentation/tsconfig.eslint.json | 5 + packages/documentation/types/json.ts | 2 +- packages/documentation/types/storybook.ts | 2 +- pnpm-lock.yaml | 987 ++++++++++++++++++ 59 files changed, 1364 insertions(+), 260 deletions(-) create mode 100644 packages/documentation/.eslintrc.js create mode 100644 packages/documentation/tsconfig.eslint.json diff --git a/packages/components/src/components/post-card-control/post-card-control.tsx b/packages/components/src/components/post-card-control/post-card-control.tsx index 99def9d09a..1f42eb8397 100644 --- a/packages/components/src/components/post-card-control/post-card-control.tsx +++ b/packages/components/src/components/post-card-control/post-card-control.tsx @@ -19,7 +19,8 @@ import { version } from '@root/package.json'; import scss from './post-card-control.module.scss'; import { parse } from '@/utils/sass-export'; -const SCSS_VARIABLES = parse(scss); +/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ +const SCSS_VARIABLES: any = parse(scss); let cardControlIds = 0; diff --git a/packages/documentation/.eslintrc.js b/packages/documentation/.eslintrc.js new file mode 100644 index 0000000000..fa4c32c3f8 --- /dev/null +++ b/packages/documentation/.eslintrc.js @@ -0,0 +1,55 @@ +module.exports = { + env: { + browser: true, + node: true, + es2021: true, + }, + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + tsconfigRootDir: __dirname, + project: 'tsconfig.eslint.json', + extraFileExtensions: ['.mdx'], + }, + ignorePatterns: [ + 'src/**/*.sample.*', + '.eslintrc.js', + 'cypress', + 'cypress.config.js', + 'cypress.snapshot.config.js', + 'public', + 'storybook-static', + 'vite.config.js', + ], + overrides: [ + { + files: ['*.{js,ts,tsx}'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'plugin:storybook/recommended', + 'prettier', + ], + parser: '@typescript-eslint/parser', + plugins: ['@typescript-eslint'], + rules: { + '@typescript-eslint/no-unused-vars': [ + 'error', + { + caughtErrors: 'none', + destructuredArrayIgnorePattern: '^_', + ignoreRestSiblings: true, + }, + ], + }, + }, + { + files: ['*.mdx'], + extends: ['plugin:mdx/recommended'], + parser: 'eslint-mdx', + settings: { + 'mdx/code-blocks': true, + }, + }, + ], +}; diff --git a/packages/documentation/package.json b/packages/documentation/package.json index 08c891e483..3836b90633 100644 --- a/packages/documentation/package.json +++ b/packages/documentation/package.json @@ -23,7 +23,8 @@ "e2e": "cypress run", "e2e:ci": "xvfb-run -a cypress run", "e2e:watch": "cypress open", - "snapshots": "percy exec -- cypress run --config-file ./cypress.snapshot.config.js --record --key 0995e768-43ec-42bd-a127-ff944a2ad8c9" + "snapshots": "percy exec -- cypress run --config-file ./cypress.snapshot.config.js --record --key 0995e768-43ec-42bd-a127-ff944a2ad8c9", + "lint": "eslint **/*.{js,ts,tsx,mdx}" }, "dependencies": { "@swisspost/design-system-components": "workspace:7.1.0", @@ -60,8 +61,14 @@ "@types/mdx": "2.0.13", "@types/react": "18.3.2", "@types/react-syntax-highlighter": "15.5.13", + "@typescript-eslint/eslint-plugin": "5.62.0", + "@typescript-eslint/parser": "5.62.0", "cypress": "13.9.0", "cypress-axe": "1.5.0", + "eslint": "8.57.0", + "eslint-config-prettier": "9.1.0", + "eslint-plugin-mdx": "3.1.5", + "eslint-plugin-storybook": "0.8.0", "lit": "3.1.3", "lit-html": "3.1.3", "prettier": "2.8.8", diff --git a/packages/documentation/src/shared/tile/tile.component.ts b/packages/documentation/src/shared/tile/tile.component.ts index fa089a52cc..414de33eff 100644 --- a/packages/documentation/src/shared/tile/tile.component.ts +++ b/packages/documentation/src/shared/tile/tile.component.ts @@ -6,7 +6,7 @@ import Styles from './tile.component.scss?inline'; @customElement('ti-le') export class TileComponent extends LitElement { - @property({ type: String }) title: string = ''; + @property({ type: String }) title = ''; @property({ type: String }) ariaLabel: string | null = null; @property({ type: String }) href: string | null = null; diff --git a/packages/documentation/src/stories/components/accordion/accordion.stories.ts b/packages/documentation/src/stories/components/accordion/accordion.stories.ts index 25add90f97..8ada6bd988 100644 --- a/packages/documentation/src/stories/components/accordion/accordion.stories.ts +++ b/packages/documentation/src/stories/components/accordion/accordion.stories.ts @@ -1,6 +1,6 @@ import type { StoryObj } from '@storybook/web-components'; import { html, nothing, TemplateResult } from 'lit'; -import { MetaComponent } from '@root/types'; +import { MetaComponent, HeadingLevel } from '@root/types'; import { ifDefined } from 'lit/directives/if-defined.js'; const meta: MetaComponent = { @@ -72,7 +72,7 @@ type Story = StoryObj; export const Default: Story = { args: { - headingLevel: '3' as any, // needs to be a string for the control to properly initialize + headingLevel: '3' as HeadingLevel, // needs to be a string for the control to properly initialize }, }; diff --git a/packages/documentation/src/stories/components/alert/standard-html/alert.stories.ts b/packages/documentation/src/stories/components/alert/standard-html/alert.stories.ts index 4bd38f6f59..f360875213 100644 --- a/packages/documentation/src/stories/components/alert/standard-html/alert.stories.ts +++ b/packages/documentation/src/stories/components/alert/standard-html/alert.stories.ts @@ -1,4 +1,3 @@ -// @ts-ignore import { useArgs } from '@storybook/preview-api'; import { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components'; import { html, nothing } from 'lit'; @@ -111,7 +110,7 @@ export default meta; function externalControl(story: StoryFn, { args, context }: StoryContext) { const [_, updateArgs] = useArgs(); - const toggleAlert = (e: MouseEvent, args: Args, updateArgs: Function) => { + const toggleAlert = (e: MouseEvent, args: Args, updateArgs: (newArgs: Partial) => void) => { e.preventDefault(); updateArgs({ show: !args.show }); }; diff --git a/packages/documentation/src/stories/components/button-group/button-group.stories.ts b/packages/documentation/src/stories/components/button-group/button-group.stories.ts index b53e5a614c..74526f62ef 100644 --- a/packages/documentation/src/stories/components/button-group/button-group.stories.ts +++ b/packages/documentation/src/stories/components/button-group/button-group.stories.ts @@ -193,7 +193,7 @@ function createButtonTemplate(args: Args, context: StoryContext, index: number) autocomplete="off" ?checked="${isChecked}" .checked="${isChecked}" - @change="${(e: Event) => { + @change="${() => { updateArgs({ checked: position }); }}" /> diff --git a/packages/documentation/src/stories/components/button/button.stories.ts b/packages/documentation/src/stories/components/button/button.stories.ts index e245c9efc9..09739ace2f 100644 --- a/packages/documentation/src/stories/components/button/button.stories.ts +++ b/packages/documentation/src/stories/components/button/button.stories.ts @@ -1,4 +1,4 @@ -import type { Args, StoryObj } from '@storybook/web-components'; +import type { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components'; import { html, unsafeStatic } from 'lit/static-html.js'; import { spread } from '@open-wc/lit-helpers'; import { repeat } from 'lit/directives/repeat.js'; @@ -222,7 +222,7 @@ const Template = { render: (args: Args) => { const tagName = unsafeStatic(args.tag); const isAnimated = args.tag !== 'input' && args.animated !== 'none'; - const props = createProps(args, isAnimated); + const props = createProps(args); if (args.tag === 'input') { return html` <${tagName} ${spread(props)} /> `; @@ -243,7 +243,7 @@ const Template = { }, }; -function createProps(args: Args, isAnimated: boolean) { +function createProps(args: Args) { const additionalClasses = args.additionalClasses ?? []; return { class: [ @@ -269,7 +269,10 @@ export const Default: Story = { export const Inverted: Story = { ...Template, - decorators: [(story: Function) => html`
${story()}
`], + decorators: [ + (story: StoryFn, context: StoryContext) => + html`
${story(context.args, context)}
`, + ], }; const VariantsTemplate = { @@ -279,7 +282,8 @@ const VariantsTemplate = { }, }, decorators: [ - (story: Function) => html`
${story()}
`, + (story: StoryFn, context: StoryContext) => + html`
${story(context.args, context)}
`, ], render: (args: Args) => html` diff --git a/packages/documentation/src/stories/components/cards/card-button/card-button.stories.ts b/packages/documentation/src/stories/components/cards/card-button/card-button.stories.ts index 999d758953..5e1dd4c118 100644 --- a/packages/documentation/src/stories/components/cards/card-button/card-button.stories.ts +++ b/packages/documentation/src/stories/components/cards/card-button/card-button.stories.ts @@ -76,7 +76,7 @@ const meta: MetaComponent = { }, }; export default meta; -function cardButtonRender(args: Args, count: number = 42) { +function cardButtonRender(args: Args, count = 42) { const [_, updateArgs] = useArgs(); return html`
diff --git a/packages/documentation/src/stories/components/cards/card/card.stories.ts b/packages/documentation/src/stories/components/cards/card/card.stories.ts index 237ab769ac..bdbdc7bfbb 100644 --- a/packages/documentation/src/stories/components/cards/card/card.stories.ts +++ b/packages/documentation/src/stories/components/cards/card/card.stories.ts @@ -1,4 +1,4 @@ -import type { Args, StoryObj } from '@storybook/web-components'; +import type { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components'; import { html, nothing } from 'lit'; import { choose } from 'lit/directives/choose.js'; import { unsafeHTML } from 'lit/directives/unsafe-html.js'; @@ -206,18 +206,20 @@ const meta: MetaComponent = { export default meta; // DECORATORS -function clickBlocker(story: any) { - return html`
e.preventDefault()}>${story()}
`; +function clickBlocker(story: StoryFn, context: StoryContext) { + return html` +
e.preventDefault()}>${story(context.args, context)}
+ `; } -function paddedContainer(story: any) { - return html`
${story()}
`; +function paddedContainer(story: StoryFn, context: StoryContext) { + return html`
${story(context.args, context)}
`; } -function gridContainer(story: any) { +function gridContainer(story: StoryFn, context: StoryContext) { return html`
-
${story()}
+
${story(context.args, context)}
`; } diff --git a/packages/documentation/src/stories/components/cards/product-card/product-card.stories.ts b/packages/documentation/src/stories/components/cards/product-card/product-card.stories.ts index 8411bf230d..d3905c65a8 100644 --- a/packages/documentation/src/stories/components/cards/product-card/product-card.stories.ts +++ b/packages/documentation/src/stories/components/cards/product-card/product-card.stories.ts @@ -1,4 +1,4 @@ -import type { Args, StoryObj } from '@storybook/web-components'; +import type { Args, StoryContext, StoryFn, StoryObj } from '@storybook/web-components'; import { html, unsafeStatic } from 'lit/static-html.js'; import { nothing } from 'lit'; import { MetaComponent } from '@root/types'; @@ -59,18 +59,20 @@ const meta: MetaComponent = { export default meta; // DECORATORS -function clickBlocker(story: any) { - return html`
e.preventDefault()}>${story()}
`; +function clickBlocker(story: StoryFn, context: StoryContext) { + return html` +
e.preventDefault()}>${story(context.args, context)}
+ `; } -function paddedContainer(story: any) { - return html`
${story()}
`; +function paddedContainer(story: StoryFn, context: StoryContext) { + return html`
${story(context.args, context)}
`; } -function gridContainer(story: any) { +function gridContainer(story: StoryFn, context: StoryContext) { return html`
-
${story()}
+
${story(context.args, context)}
`; } @@ -322,12 +324,12 @@ export const Multipart: Story = {
`, decorators: [ - (story: any) => { - let timer; - + (story: StoryFn, context: StoryContext) => { return html` - ${story()} + ${story(context.args, context)}