Skip to content

Commit a0dc5cd

Browse files
authored
Merge pull request #1 from marklearst/pr/01-eslint
chore(tooling): migrate eslint config
2 parents 1f88524 + d07de4a commit a0dc5cd

3 files changed

Lines changed: 209 additions & 71 deletions

File tree

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.cjs

Lines changed: 0 additions & 70 deletions
This file was deleted.

eslint.config.js

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
import { FlatCompat } from '@eslint/eslintrc'
2+
import { fileURLToPath } from 'node:url'
3+
import path from 'node:path'
4+
import js from '@eslint/js'
5+
import globals from 'globals'
6+
import tsParser from '@typescript-eslint/parser'
7+
import tsPlugin from '@typescript-eslint/eslint-plugin'
8+
import reactPlugin from 'eslint-plugin-react'
9+
import reactHooksPlugin from 'eslint-plugin-react-hooks'
10+
import importPlugin from 'eslint-plugin-import'
11+
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y'
12+
import prettierPlugin from 'eslint-plugin-prettier'
13+
14+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
15+
const compat = new FlatCompat({
16+
baseDirectory: __dirname,
17+
resolvePluginsRelativeTo: __dirname,
18+
recommendedConfig: js.configs.recommended,
19+
allConfig: js.configs.all,
20+
})
21+
22+
export default [
23+
{
24+
ignores: [
25+
'dist/**',
26+
'**/dist/**',
27+
'node_modules/**',
28+
'**/node_modules/**',
29+
'storybook-static/**',
30+
'**/storybook-static/**',
31+
'coverage/**',
32+
'**/coverage/**',
33+
'.pnpm-store/**',
34+
'**/.pnpm-store/**',
35+
],
36+
linterOptions: {
37+
reportUnusedDisableDirectives: 'off',
38+
},
39+
},
40+
{
41+
settings: {
42+
react: {
43+
version: 'detect',
44+
},
45+
'import/resolver': {
46+
node: {
47+
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs'],
48+
},
49+
},
50+
},
51+
},
52+
...compat.extends(
53+
'eslint:recommended',
54+
'plugin:react/recommended',
55+
'plugin:react-hooks/recommended',
56+
'plugin:@typescript-eslint/recommended',
57+
'plugin:import/recommended',
58+
'plugin:import/typescript',
59+
'plugin:jsx-a11y/recommended',
60+
'plugin:storybook/recommended',
61+
'plugin:prettier/recommended',
62+
),
63+
{
64+
files: ['**/*.{ts,tsx}'],
65+
languageOptions: {
66+
parser: tsParser,
67+
parserOptions: {
68+
ecmaVersion: 'latest',
69+
sourceType: 'module',
70+
project: './tsconfig.json',
71+
tsconfigRootDir: __dirname,
72+
warnOnUnsupportedTypeScriptVersion: false,
73+
},
74+
globals: {
75+
...globals.browser,
76+
...globals.es2021,
77+
},
78+
},
79+
plugins: {
80+
'@typescript-eslint': tsPlugin,
81+
react: reactPlugin,
82+
'react-hooks': reactHooksPlugin,
83+
import: importPlugin,
84+
'jsx-a11y': jsxA11yPlugin,
85+
prettier: prettierPlugin,
86+
},
87+
rules: {
88+
'import/prefer-default-export': 'off',
89+
'no-restricted-exports': [
90+
'error',
91+
{ restrictDefaultExports: { direct: true } },
92+
],
93+
'import/extensions': [
94+
'error',
95+
'ignorePackages',
96+
{
97+
js: 'never',
98+
jsx: 'never',
99+
ts: 'never',
100+
tsx: 'never',
101+
},
102+
],
103+
'no-use-before-define': 'off',
104+
'@typescript-eslint/no-use-before-define': ['error'],
105+
'react/react-in-jsx-scope': 'off',
106+
'react/require-default-props': 'off',
107+
'react/jsx-filename-extension': [
108+
'error',
109+
{ extensions: ['.jsx', '.tsx'] },
110+
],
111+
'no-alert': 'off',
112+
'react/function-component-definition': [
113+
'error',
114+
{
115+
namedComponents: ['arrow-function'],
116+
unnamedComponents: ['arrow-function'],
117+
},
118+
],
119+
'react/display-name': 'off',
120+
'react-hooks/incompatible-library': 'off',
121+
'import/no-extraneous-dependencies': [
122+
'error',
123+
{
124+
devDependencies: [
125+
'**/*.stories.tsx',
126+
'**/*.test.tsx',
127+
'**/*.test.ts',
128+
'vitest.config.ts',
129+
],
130+
},
131+
],
132+
'react/jsx-props-no-spreading': 'off',
133+
'react/prop-types': 'off',
134+
},
135+
},
136+
{
137+
files: ['**/*.stories.tsx'],
138+
rules: {
139+
'no-plusplus': 'off',
140+
'no-restricted-exports': 'off',
141+
'react/no-unstable-nested-components': 'off',
142+
'react/jsx-props-no-spreading': 'off',
143+
},
144+
},
145+
{
146+
files: ['src/icons/**/*.tsx'],
147+
rules: {
148+
'no-restricted-exports': 'off',
149+
'react/jsx-props-no-spreading': 'off',
150+
'import/prefer-default-export': 'off',
151+
},
152+
},
153+
{
154+
files: ['.storybook/**/*.{ts,tsx}'],
155+
rules: {
156+
'import/no-unresolved': 'off',
157+
'no-restricted-exports': 'off',
158+
'import/no-extraneous-dependencies': 'off',
159+
},
160+
},
161+
{
162+
files: ['src/util/class-names.tsx'],
163+
rules: {
164+
'import/no-extraneous-dependencies': 'off',
165+
},
166+
},
167+
{
168+
files: [
169+
'*.js',
170+
'*.mjs',
171+
'scripts/**/*.{js,mjs}',
172+
'.storybook/main.ts',
173+
'vite.config.ts',
174+
],
175+
languageOptions: {
176+
ecmaVersion: 'latest',
177+
sourceType: 'module',
178+
globals: {
179+
...globals.node,
180+
...globals.es2021,
181+
},
182+
},
183+
rules: {
184+
'import/no-unresolved': 'off',
185+
'import/no-extraneous-dependencies': 'off',
186+
'no-restricted-exports': 'off',
187+
},
188+
},
189+
{
190+
files: ['vitest.config.ts'],
191+
rules: {
192+
'import/no-unresolved': 'off',
193+
'no-restricted-exports': 'off',
194+
},
195+
},
196+
{
197+
files: ['eslint.config.js'],
198+
languageOptions: {
199+
ecmaVersion: 'latest',
200+
sourceType: 'module',
201+
globals: {
202+
...globals.node,
203+
},
204+
},
205+
rules: {
206+
'import/no-unresolved': 'off',
207+
},
208+
},
209+
]

0 commit comments

Comments
 (0)