-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
144 lines (143 loc) · 4.61 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
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
module.exports = {
extends: [
"eslint-config-mitodl",
"eslint-config-mitodl/jest",
"plugin:styled-components-a11y/recommended",
"plugin:import/typescript",
"plugin:mdx/recommended",
"prettier",
],
plugins: ["testing-library", "import", "styled-components-a11y"],
ignorePatterns: ["**/build/**"],
settings: {
"jsx-a11y": {
components: {
"ListCard.Image": "img",
"Card.Image": "img",
Button: "button",
ButtonLink: "a",
ActionButton: "button",
ActionButtonLink: "a",
},
},
},
rules: {
...restrictedImports(),
"react/display-name": [2, {}],
// This rule is disabled in the default a11y config, but unclear why.
// It does catch useful errors, e.g., buttons with no text or label.
// If it proves to be flaky, we can find other ways to check for this.
// We need both rules below. One for normal elements, one for styled
"jsx-a11y/control-has-associated-label": ["error"],
"styled-components-a11y/control-has-associated-label": ["error"],
"@typescript-eslint/triple-slash-reference": [
"error",
{
path: "never",
types: "prefer-import",
lib: "never",
},
],
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: [
"**/*.test.ts",
"**/*.test.tsx",
"**/src/setupJest.ts",
"**/jest-setup.ts",
"**/jsdom-extended.ts",
"**/test-utils/**",
"**/test-utils/**",
"**/webpack.config.js",
"**/webpack.exports.js",
"**/postcss.config.js",
"**/*.stories.ts",
"**/*.stories.tsx",
"**/*.mdx",
".storybook/**",
],
},
],
"import/no-duplicates": "error",
quotes: ["error", "double", { avoidEscape: true }],
"no-restricted-syntax": [
"error",
/**
* See https://eslint.org/docs/latest/rules/no-restricted-syntax
*
* The selectors use "ES Query", a css-like syntax for AST querying. A
* useful tool is https://estools.github.io/esquery/
*/
{
selector:
"Property[key.name=fontWeight][value.raw=/\\d+/], TemplateElement[value.raw=/font-weight: \\d+/]",
message:
"Do not specify `fontWeight` manually. Prefer spreading `theme.typography.subtitle1` or similar. If you MUST use a fontWeight, refer to `fontWeights` theme object.",
},
{
selector:
"Property[key.name=fontFamily][value.raw=/Neue Haas/], TemplateElement[value.raw=/Neue Haas/]",
message:
"Do not specify `fontFamily` manually. Prefer spreading `theme.typography.subtitle1` or similar. If using neue-haas-grotesk-text, this is ThemeProvider's default fontFamily.",
},
],
},
overrides: [
{
files: ["./**/*.test.{ts,tsx}"],
plugins: ["testing-library"],
extends: ["plugin:testing-library/react"],
rules: {
"testing-library/no-node-access": "off",
},
},
],
}
function restrictedImports({ paths = [], patterns = [] } = {}) {
/**
* With the `no-restricted-imports` rule (and its typescript counterpart),
* it's difficult to restrict imports but allow a few exceptions.
*
* For example:
* - forbid importing `@mui/material/*`, EXCEPT within `ol-components`.
*
* It is possible to do this using overrides.
*
* This function exists to make it easier to share config between overrides.
*
* See also:
* - https://github.com/eslint/eslint/discussions/17047 no-restricted-imports: allow some specific imports in some specific directories
* - https://github.com/eslint/eslint/discussions/15011 Can a rule be specified multiple times without overriding itself?
*
* This may be easier if we swtich to ESLint's new "flat config" system.
*/
return {
"@typescript-eslint/no-restricted-imports": [
"error",
{
paths: [
/**
* No direct imports from large "barrel files". They make Jest slow.
*
* For more, see:
* - https://github.com/jestjs/jest/issues/11234
* - https://github.com/faker-js/faker/issues/1114#issuecomment-1169532948
*/
{
name: "@faker-js/faker",
message: "Please use @faker-js/faker/locale/en instead.",
allowTypeImports: true,
},
{
name: "@mui/material",
message: "Please use @mui/material/<COMPONENT_NAME> instead.",
allowTypeImports: true,
},
...paths,
],
patterns: [...patterns],
},
],
}
}