-
Notifications
You must be signed in to change notification settings - Fork 42
/
.eslintrc.js
183 lines (181 loc) · 5.17 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
* TODO:
* - Convert to new format (v9): https://eslint.org/docs/latest/use/configure/migration-guide
* - Look into opinionated stylistic plugin
* - Replace @typescript-eslint/recommended with @typescript-eslint/recommended-type-checked
* - We should add "plugin:react/jsx-runtime", but not sure if this will cause problems for projects not using the new JSX transform
* - Consider adding the rule "id-length"
*/
/**
* V9 migration WIP
* - eslint-plugin-storybook does not support v9 yet: https://github.com/storybookjs/eslint-plugin-storybook/issues/157
* - eslint-plugin-testing-library does not support v9 yet: https://github.com/testing-library/eslint-plugin-testing-library/issues?q=is%3Aissue+is%3Aopen+v9
* - @vitest/eslint-plugin supports v9, just need to replace @vitest/legacy-recommended: https://github.com/vitest-dev/eslint-plugin-vitest?tab=readme-ov-file#usage
* - Looks like @typescript-eslint/eslint-plugin and @typescript-eslint/parser can both be replaced by just typescript-eslint in v9: https://typescript-eslint.io/getting-started#step-2-configuration
*/
module.exports = {
env: {
browser: true,
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:storybook/recommended",
],
/* Allows eslint-plugin-react to detect installed react-version */
settings: { react: { version: "detect" } },
rules: {
"import/no-unresolved": "off",
"react/jsx-curly-brace-presence": [
"error",
{ propElementValues: "always" },
],
"array-callback-return": "error",
"object-shorthand": "error",
"no-else-return": "error",
"no-console": [
"warn",
{
allow: [
"info",
"warn",
"error",
"group",
"groupEnd",
"table",
"assert",
"countReset",
"count",
"dir",
"time",
"timeEnd",
"timeStamp",
],
},
],
/* Temporarily turned off until code is updated */
"react/prop-types": "off",
"react/display-name": "off",
"import/no-named-as-default": "off",
},
/* https://eslint.org/docs/latest/use/configure/rules#report-unused-eslint-disable-comments */
reportUnusedDisableDirectives: true,
overrides: [
{
files: ["**/*.stories.ts?(x)"],
rules: {
"no-console": "off",
},
},
{
files: ["**/*.ts?(x)"],
extends: ["plugin:@typescript-eslint/recommended"],
rules: {
/*
* TODO:
* - Consider { builtinGlobals: true }
*/
"@typescript-eslint/no-shadow": ["error", { hoist: "all" }],
"@typescript-eslint/no-explicit-any": "off", // Temporary
"@typescript-eslint/array-type": "error",
"@typescript-eslint/no-unused-expressions": [
"error",
/* https://eslint.org/docs/latest/rules/no-unused-expressions#allowshortcircuit-and-allowternary */
{ allowShortCircuit: true, allowTernary: true },
],
},
},
{
files: ["**/*.test.*", "**/__tests__/*"],
plugins: ["@vitest"],
extends: [
"plugin:testing-library/react",
/* Needed to support v8 eslint config-syntax */
"plugin:@vitest/legacy-recommended",
],
},
{
files: ["aksel.nav.no/website/**"],
env: {
browser: true,
es2021: true,
},
extends: ["plugin:@next/next/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: "module",
},
rules: {
"react/no-unknown-property": [2, { ignore: ["jsx", "global"] }],
"react/react-in-jsx-scope": "off",
"@next/next/no-html-link-for-pages": [
"error",
"aksel.nav.no/website/pages/",
],
},
},
{
files: ["aksel.nav.no/website/pages/eksempler/**"],
rules: {
"jsx-a11y/anchor-is-valid": "off",
},
},
{
files: [
"aksel.nav.no/website/pages/eksempler/**/*.tsx",
"aksel.nav.no/website/pages/templates/**/*.tsx",
],
plugins: ["aksel-local"],
rules: {
"aksel-local/comment-check": ["error"],
},
},
{
files: ["**/examples/__parts*/*.tsx"],
plugins: ["aksel-local"],
rules: {
"aksel-local/import-check": ["error"], // Only allow imports from @navikt and react
},
},
{
files: ["**/examples/__parts-inline/*.tsx"],
rules: {
"arrow-body-style": ["error", "never"],
"func-style": ["error", "expression"],
"import/no-named-export": "error",
},
},
{
files: ["examples/**"],
rules: {
"react/react-in-jsx-scope": "off",
},
},
],
globals: {
Locale: "readonly",
JSX: "readonly",
},
ignorePatterns: [
"node_modules",
"lib",
"public",
"esm",
"cjs",
"dist",
"**/codemod/**/*.js",
"!.storybook",
"**/playwright-report/**",
"**/tokens/**/plugin.js",
],
};