-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy path.eslintrc.js
More file actions
155 lines (151 loc) · 5.07 KB
/
Copy path.eslintrc.js
File metadata and controls
155 lines (151 loc) · 5.07 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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 = {
// root: true stops ESLint from walking up the directory tree looking for
// ancestor configs. Required for `git worktree`-based dev flows
// (orchestrator's worktrees live under `migration-runs/<date>/<comp>/worktree/`,
// and without `root: true`, ESLint walks up from the worktree's source
// through `migration-runs/`, eventually re-discovering this same config in
// the main repo via a different filesystem path. That double-load registers
// `eslint-plugin-ssr-friendly` from two node_modules paths and fails with
// "ESLint couldn't determine the plugin uniquely". Fixed 2026-05-07.)
root: true,
extends: [
require.resolve('@toptal/davinci-syntax/src/configs/.eslintrc.cjs'),
'plugin:ssr-friendly/recommended',
],
plugins: ['ssr-friendly', 'eslint-plugin-local-rules'],
rules: {
// When a deprecation warning hook is used, it must be preceded by a comment. Having a ticket
// reference in the comment is enforced by the next rule.
'local-rules/future-proof-deprecation-warning': 'warn',
// When @deprecated is used, it must be followed by a Jira issue either in a short form [ABC-1234] or a full URL
'todo-plz/ticket-ref': [
'warn',
{
terms: ['TODO', 'FIXME', '@deprecated'],
commentPattern:
'(TODO:|FIXME:|@deprecated) ((\\n|.)*(\\[([A-Z]+-\\d+)+]|https:\\/\\/toptal-core\\.atlassian\\.net\\/browse\\/([A-Z]+-\\d+)))+',
description:
'Please add either a full URL to Jira issue or a short form: [ABC-1234] ',
},
],
'@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/base/Icons/src/Icon/index.ts'],
rules: {
'max-lines': 'off',
},
},
// Top-level cypress tests and Stories can have extraneous dependencies
{
files: [
'*.spec.tsx',
'*.example.tsx',
'test.tsx',
'test.ts',
'*.test.tsx',
'*.test.ts',
],
rules: {
'import/no-extraneous-dependencies': 'off',
},
},
// Disallow importing from aggregate picasso package within individual sub-packages
{
files: ['packages/*/src/**'],
excludedFiles: ['*.example.jsx', '*.example.tsx'],
rules: {
'no-restricted-imports': [
'error',
{
name: '@toptal/picasso',
message:
'Do not import from the aggregate @toptal/picasso package. Import directly from the specific sub-package.',
},
],
},
},
...generateConfig(),
],
}