-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patheslint.config.mjs
148 lines (139 loc) · 4.45 KB
/
eslint.config.mjs
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
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import globals from "globals";
import reactPlugin from "eslint-plugin-react";
import reactHooksPlugin from "eslint-plugin-react-hooks";
import eslintPluginAstro from "eslint-plugin-astro";
import jsxA11y from "eslint-plugin-jsx-a11y";
import eslintConfigPrettier from "eslint-config-prettier";
const typescriptEslint = tseslint.plugin;
const tsParser = tseslint.parser;
export default tseslint.config(
{
ignores: [
// recursively ignore all dirs named node_modules by prepending **/
"**/node_modules",
"**/dist",
".git/",
".astro/",
".prettierrc.mjs",
],
},
// General setup base with type-aware linting
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
{
languageOptions: {
parser: tsParser,
parserOptions: {
// prefer projectServer over setting project manually: https://typescript-eslint.io/getting-started/typed-linting#can-i-customize-the-tsconfig-used-for-typed-linting
// but using projectService causes an error in .astro files of: 1. Parsing error: Type expected.
// https://github.com/ota-meshi/astro-eslint-parser/issues/331
// projectService: true,
project: ["./tsconfig.json"],
// @ts-expect-error investigate how to solve and keep tscheck
tsconfigRootDir: import.meta.dirname,
},
},
plugins: {
"@typescript-eslint": typescriptEslint,
},
},
// React
{
files: ["**/*.{jsx,mjsx,tsx,mtsx}"],
...reactPlugin.configs.flat.recommended, // This is not a plugin object, but a shareable config object
...reactPlugin.configs.flat["jsx-runtime"], // Add this if you are using React 17+
languageOptions: {
...reactPlugin.configs.flat.recommended.languageOptions,
globals: {
...globals.serviceworker,
...globals.browser,
},
},
plugins: {
...reactPlugin.configs.flat.recommended.plugins,
"react-hooks": reactHooksPlugin,
},
rules: {
...reactPlugin.configs.flat.recommended.rules,
...reactPlugin.configs.flat["jsx-runtime"].rules,
...reactHooksPlugin.configs.recommended.rules,
"react/hook-use-state": ["warn", { allowDestructuredState: true }],
"react/jsx-fragments": ["warn", "element"],
"react/prop-types": "off"
},
},
// jsx a11y
{
files: ["**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}"],
plugins: {
"jsx-a11y": jsxA11y,
},
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
},
// Astro
...eslintPluginAstro.configs.recommended,
...eslintPluginAstro.configs["jsx-a11y-recommended"],
// Disable typed rules for scripts inside Astro files
// https://github.com/ota-meshi/eslint-plugin-astro/issues/240
{
files: ["**/*.astro/*.ts", "**/*.js", "**/*.jsx"],
languageOptions: {
parserOptions: {
project: null,
},
},
...tseslint.configs.disableTypeChecked,
},
// Remove some safety rules because not all code is perfectly typed
{
files: [
"**/*.astro", // eslint-plugin-astro doesn't type Astro.props correctly in some contexts, so a bunch of things ends up being any
"eslint.config.mjs",
],
rules: {
"@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",
"@typescript-eslint/no-unsafe-argument": "off",
},
},
// General rules
{
rules: {
"prefer-const": "warn",
"astro/no-unused-css-selector": "error",
"astro/prefer-object-class-list": "error",
"astro/jsx-a11y/lang": "error",
"jsx-a11y/lang": "error",
// Note: you must disable the base rule as it can report incorrect errors
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
vars: "all",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
// Escape hatch
"@typescript-eslint/no-explicit-any": "off",
},
},
// turn off rules that conflict with the prettier formatter
eslintConfigPrettier,
);