forked from toptal/picasso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
103 lines (99 loc) · 2.93 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const forbiddenImports = {
picasso: ['picasso', 'picasso-forms', 'picasso-charts'],
'picasso-charts': ['picasso-charts'],
'picasso-forms': ['picasso-forms'],
'picasso-provider': ['picasso-provider', 'picasso-shared'],
}
const generateConfig = () =>
Object.entries(forbiddenImports).map(
([srcPackageName, forbiddenPackageNames]) => {
return {
files: [`packages/${srcPackageName}/src/**`],
excludedFiles: ['*.example.jsx', '*.example.tsx'],
rules: {
'no-restricted-imports': [
'error',
...forbiddenPackageNames.map(name => `@toptal/${name}`),
{
name: 'react',
importNames: ['useLayoutEffect'],
message:
'`useLayoutEffect` causes a warning in SSR. Use `useIsomorphicLayoutEffect` from `@toptal/picasso-shared`',
},
],
},
}
}
)
const ssrFriendlyRuleNames = [
'ssr-friendly/no-dom-globals-in-module-scope',
'ssr-friendly/no-dom-globals-in-constructor',
'ssr-friendly/no-dom-globals-in-react-cc-render',
'ssr-friendly/no-dom-globals-in-react-fc',
]
const generateSameSettingRules = (ruleNames, setting) => {
return Object.fromEntries(ruleNames.map(ruleName => [ruleName, setting]))
}
module.exports = {
extends: [
'./node_modules/@toptal/davinci-syntax/src/configs/.eslintrc',
'plugin:ssr-friendly/recommended',
],
plugins: ['ssr-friendly'],
rules: {
'@toptal/davinci/no-private-package-imports': 'off',
'@toptal/davinci/no-package-self-imports': [
'error',
{
excludeFiles: ['**/*.example.jsx', '**/*.example.tsx'],
excludePaths: ['@toptal/picasso/test-utils'],
},
],
...generateSameSettingRules(ssrFriendlyRuleNames, 'warn'),
},
ignorePatterns: ['*.output.tsx', '*.input.tsx'],
overrides: [
{
files: ['*.example.jsx', '*.example.tsx'],
rules: {
'react/no-multi-comp': 'off',
'react/require-optimization': 'off',
'import/no-named-default': 'off',
'no-console': 'off',
'no-inline-styles/no-inline-styles': 'off',
'@toptal/davinci/no-private-package-imports': 'error',
...generateSameSettingRules(ssrFriendlyRuleNames, 'off'),
},
},
// tests
{
files: ['test.ts', 'test.tsx', '*.spec.ts', '*.spec.tsx'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'no-inline-styles/no-inline-styles': 'off',
'max-lines': 'off',
...generateSameSettingRules(ssrFriendlyRuleNames, 'off'),
},
},
// codemod fixtures
{
files: ['packages/picasso-codemod/src/**'],
rules: {
'id-length': [
'error',
{
exceptions: ['e', '_', 'j'],
},
],
},
},
// Generated files
{
files: ['packages/picasso/src/Icon/index.ts'],
rules: {
'max-lines': 'off',
},
},
...generateConfig(),
],
}