From b067c3ecca17c267df5c8b097c7a767f90de722e Mon Sep 17 00:00:00 2001 From: Leroy Korterink Date: Thu, 7 Nov 2024 09:41:07 +0100 Subject: [PATCH] Add eslint-plugin-storybook --- package-lock.json | 48 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/index.js | 31 ++++++++++++++++++++++-------- 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 15e70e9..92aaae1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "eslint-plugin-import": "^2.31.0", "eslint-plugin-jsx-a11y": "^6.10.2", "eslint-plugin-react": "^7.37.2", + "eslint-plugin-storybook": "^0.11.0", "eslint-plugin-unicorn": "^56.0.0", "typescript-eslint": "^8.13.0" }, @@ -1467,6 +1468,27 @@ "dev": true, "license": "MIT" }, + "node_modules/@storybook/csf": { + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/@storybook/csf/-/csf-0.1.11.tgz", + "integrity": "sha512-dHYFQH3mA+EtnCkHXzicbLgsvzYjcDJ1JWsogbItZogkPHgSJM/Wr71uMkcvw8v9mmCyP4NpXJuu6bPoVsOnzg==", + "license": "MIT", + "dependencies": { + "type-fest": "^2.19.0" + } + }, + "node_modules/@storybook/csf/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@tufjs/canonical-json": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tufjs/canonical-json/-/canonical-json-2.0.0.tgz", @@ -4069,6 +4091,23 @@ "semver": "bin/semver.js" } }, + "node_modules/eslint-plugin-storybook": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-storybook/-/eslint-plugin-storybook-0.11.0.tgz", + "integrity": "sha512-MvPJgF+ORwgK04a1CY5itO4pwdAOFIRqczlNEHL62+4Ocvj1d61GWRqIdeX1BNCKno6fdPC6TksUHCZMGsq26g==", + "license": "MIT", + "dependencies": { + "@storybook/csf": "^0.1.11", + "@typescript-eslint/utils": "^8.8.1", + "ts-dedent": "^2.2.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "eslint": ">=6" + } + }, "node_modules/eslint-plugin-unicorn": { "version": "56.0.0", "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-56.0.0.tgz", @@ -10571,6 +10610,15 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-dedent": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-2.2.0.tgz", + "integrity": "sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==", + "license": "MIT", + "engines": { + "node": ">=6.10" + } + }, "node_modules/tsconfig-paths": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", diff --git a/package.json b/package.json index dd53e53..554657d 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "eslint-plugin-import": "^2.31.0", "eslint-plugin-jsx-a11y": "^6.10.2", "eslint-plugin-react": "^7.37.2", + "eslint-plugin-storybook": "^0.11.0", "eslint-plugin-unicorn": "^56.0.0", "typescript-eslint": "^8.13.0" } diff --git a/src/index.js b/src/index.js index 319c1fe..698148f 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import eslint from '@eslint/js'; import eslintPluginImport from 'eslint-plugin-import'; import eslintPluginJsxA11y from 'eslint-plugin-jsx-a11y'; import eslintPluginReact from 'eslint-plugin-react'; +import eslintPluginStorybook from 'eslint-plugin-storybook'; import eslintPluginUnicorn from 'eslint-plugin-unicorn'; import typescriptEslint from 'typescript-eslint'; import { recommended as javascriptRecommended } from './javascript.js'; @@ -41,18 +42,26 @@ const react = [ version: 'detect', }, }, + files: ['**/*.jsx', '**/*.tsx'], name: '@mediamonks/eslint-config / react settings', }, { ...eslintPluginReact.configs.flat.recommended, + files: ['**/*.jsx', '**/*.tsx'], name: '@mediamonks/eslint-config / eslint-plugin-react / recommended configuration', }, { ...eslintPluginImport.flatConfigs.react, + files: ['**/*.jsx', '**/*.tsx'], name: '@mediamonks/eslint-config / eslint-plugin-import / recommended react configuration', }, + ...eslintPluginStorybook.configs['flat/recommended'].map((config) => ({ + ...config, + name: `@mediamonks/eslint-config / eslint-plugin-storybook / ${config.name}`, + })), { ...reactRecommended, + files: ['**/*.jsx', '**/*.tsx'], name: '@mediamonks/eslint-config / react recommended configuration', }, ]; @@ -60,19 +69,19 @@ const react = [ /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigFile} */ const typescript = [ // Recommended plugin configurations - ...typescriptEslint.configs.strictTypeChecked.map((config) => ({ + ...typescriptEslint.configs.strict.map((config) => ({ ...config, + files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'], name: `@mediamonks/eslint-config / ${config.name}`, })), - { ...eslintPluginImport.flatConfigs.typescript, - files: ['**/*.ts', '**/*.cts', '**/*.mts', '**/*.tsx'], + files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'], name: '@mediamonks/eslint-config / eslint-plugin-import / .ts configuration', }, { ...typescriptRecommended, - files: ['**/*.ts', '**/*.cts', '**/*.mts'], + files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'], name: '@mediamonks/eslint-config / typescript recommended configuration', }, ]; @@ -91,13 +100,19 @@ const typescriptReact = [ }, ]; +const overrides = { + rules: { + 'import/no-unresolved': 'off', + }, +}; + export const configs = { /** @type {import('eslint').Linter.Config} */ - javascript, + javascript: [...javascript, overrides], /** @type {import('eslint').Linter.Config} */ - react: [...javascript, ...react], + react: [...javascript, ...react, overrides], /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */ - typescript: [...javascript, ...typescript], + typescript: [...javascript, ...typescript, overrides], /** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigArray} */ - typescriptReact: [...javascript, ...react, ...typescript, ...typescriptReact], + typescriptReact: [...javascript, ...react, ...typescript, ...typescriptReact, overrides], };