-
Notifications
You must be signed in to change notification settings - Fork 2
/
eslint.config.js
171 lines (162 loc) · 5.31 KB
/
eslint.config.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
import vitest from "@vitest/eslint-plugin";
import { FlatCompat } from "@eslint/eslintrc";
import eslint from "@eslint/js";
import globals from "globals";
import react from "eslint-plugin-react";
import jsxA11y from "eslint-plugin-jsx-a11y";
import importPlugin from "eslint-plugin-import";
import tseslint from "typescript-eslint";
import sonarjs from "eslint-plugin-sonarjs";
import { fileURLToPath } from "url";
import path from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
export default tseslint.config(
eslint.configs.recommended,
// Global ignores
{
ignores: ["**/*", "!app/**", "!tests/**", "!scripts/**"],
},
// Global overrides
{
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
globals: {
...globals.browser,
...globals.commonjs,
...globals.es6,
...globals.node,
},
},
},
// React
{
files: ["**/*.{js,jsx,ts,tsx}"],
extends: [
react.configs.flat.recommended,
react.configs.flat["jsx-runtime"],
/**
* TODO: flat config of this plugin isn't available yet https://github.com/facebook/react/pull/30774
*/
...compat.extends("plugin:react-hooks/recommended"),
jsxA11y.flatConfigs.recommended,
],
plugins: {
react,
},
settings: {
react: { version: "detect" },
formComponents: ["Form"],
linkComponents: [
{ name: "Link", linkAttribute: "to" },
{ name: "NavLink", linkAttribute: "to" },
],
},
rules: {
"react/jsx-no-leaked-render": ["off", { validStrategies: ["ternary"] }], // TODO: enable later
"react/jsx-no-constructed-context-values": "warn",
"react/no-array-index-key": "warn",
"react/no-unstable-nested-components": "warn",
},
},
// Typescript
{
files: ["**/*.{ts,tsx}"],
extends: [
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
sonarjs.configs.recommended,
],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
"import/internal-regex": "^~/",
"import/resolver": {
node: { extensions: [".ts", ".tsx"] },
typescript: { alwaysTryTypes: true },
},
},
rules: {
// eslint
"no-console": "warn",
// import
"import/no-cycle": "off", // VERY slow, only enable if needed
"import/namespace": "off", // slow and unneeded
"import/order": [
"warn",
{
alphabetize: { caseInsensitive: true, order: "asc" },
groups: ["builtin", "external", "internal"],
"newlines-between": "never",
},
],
// sonarjs
"sonarjs/no-duplicate-string": "off",
"sonarjs/todo-tag": "warn",
"sonarjs/function-return-type": "off",
"sonarjs/aws-restricted-ip-admin-access": "off", // slow and unneeded
"sonarjs/no-async-constructor": "off", // slow and unneeded
// duplicates of typescript-eslint rules (prefer typescript-eslint as their rule pages are clearer)
"sonarjs/sonar-no-unused-vars": "off",
"sonarjs/no-misused-promises": "off",
"sonarjs/different-types-comparison": "off",
"sonarjs/sonar-prefer-regexp-exec": "off",
"sonarjs/sonar-prefer-optional-chain": "off",
"sonarjs/no-dead-store": "off",
"sonarjs/anchor-has-content": "off",
"sonarjs/no-invalid-await": "off",
// TODO: to be enabled later
"sonarjs/deprecation": "off", // enable after remix upgrades to react router v7 and we move to Single Fetch
// typescript-eslint
"@typescript-eslint/only-throw-error": "off", // disabled, as remix/react-router can throw redirects
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_" },
],
"@typescript-eslint/consistent-type-definitions": ["warn", "type"],
"@typescript-eslint/array-type": ["warn", { default: "array-simple" }],
// enable gradually for full type safety
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"no-restricted-syntax": [
"error",
{
selector:
"Literal[value=/(a\u0308)|(o\u0308)|(u\u0308)|(A\u0308)|(O\u0308)|(U\u0308)/]",
message:
"German umlauts must be written as NFC (normalized form canonical composition) and not NFD (normalized form canonical decomposition). E.g. use 'ä' instead of the character 'a' followed by the combining diacritical marks ' ̈'.",
},
],
},
},
// Vitest
{
files: ["app/**/*.test.{js,jsx,ts,tsx}"],
plugins: {
vitest,
},
rules: {
...vitest.configs.recommended.rules,
"vitest/valid-title": "off", // TODO: enable later
"@typescript-eslint/unbound-method": "off",
"require-await": "error",
},
},
);