-
Notifications
You must be signed in to change notification settings - Fork 2
/
.eslintrc.cjs
158 lines (149 loc) · 4.46 KB
/
.eslintrc.cjs
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
// this is a pre-flatconfig setup
// the goal is to use overrides in a way that maps neatly to files/ignores in
// eslint 9
/**
* Create a set of default eslint configs for a typescript project
* @param {string} dir
* @returns
*/
const tsProject = (dir) => ({
plugins: ["@typescript-eslint", "import", "node"],
parser: "@typescript-eslint/parser",
parserOptions: {
tsconfigRootDir: __dirname,
project: [`${dir}/tsconfig.json`],
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
typescript: {
alwaysTryTypes: true,
project: [`${dir}/tsconfig.json`],
},
},
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier",
],
rules: {
// False positives. There be dragons here. Most common culprits are
// optional chaining and nullish coalesce.
// Using it causes typescript-eslint to believe it is
// of type "any" and trigger these eslint errors. We'd like to safely
// turn these on, and would appreciate any help in solving.
// https://github.com/typescript-eslint/typescript-eslint/issues/2728
// https://github.com/typescript-eslint/typescript-eslint/issues/4912
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/restrict-template-expressions": "off",
// https://typescript-eslint.io/rules/no-unused-vars/
// https://eslint.org/docs/rules/no-unused-vars
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ ignoreRestSiblings: true },
],
},
});
/**
* Get a list of all lintable files in a directory
* @param {string} dir
* @returns
*/
const lintableFiles = (dir) => [
`${dir}/**/*.+(t|j)s?(x)`,
`${dir}/**/*.+(c|m)js`,
];
/** A set of import rules that ensure files are imported in a way webpack and vscode both understand */
const nextJsImportRules = {
"import/extensions": ["error", "never", { json: "always", css: "always" }],
"node/file-extension-in-import": [
"error",
"never",
{ ".json": "always", ".css": "always" },
],
"node/no-missing-import": "off",
};
module.exports = {
root: true,
rules: {},
// baseline js parsing options set env for CJS files and skip known builds
env: {
es6: true,
es2018: true,
node: true,
},
ignorePatterns: [
"**/dist/*",
"**/build/*",
"**/.swc/*",
"**/.next/*",
"**/__generated__/*",
"**/*.config.js",
],
overrides: [
// check yourself before you wreck yourself
{
files: ["**/.eslintrc.cjs", ".lintstagedrc.cjs", "commitlint.config.cjs"],
extends: ["eslint:recommended", "prettier"],
},
// docs-site - Doc Preview, a next.js project
{
files: lintableFiles("./docs-site"),
excludedFiles: ["**/__generated__/*", "**.d.ts"],
...tsProject("./docs-site"),
extends: [...tsProject("./docs-site").extends, "next"],
settings: {
...tsProject("./docs-site").settings,
next: {
rootDir: "docs-site/",
},
},
rules: {
...tsProject("./docs-site").rules,
...nextJsImportRules,
},
},
// dev - Taskless Dev Server, a next.js project
{
files: lintableFiles("./packages/dev"),
excludedFiles: ["**/__generated__/*", "**.d.ts"],
...tsProject("./packages/dev"),
extends: [...tsProject("./packages/dev").extends, "next"],
settings: {
...tsProject("./packages/dev").settings,
next: {
rootDir: "packages/dev/",
},
},
rules: {
...tsProject("./packages/dev").rules,
...nextJsImportRules,
},
},
// client, express, graphinql, next, types, ui
...["client", "express", "graphinql", "next", "types", "ui"].map((p) => ({
files: lintableFiles(`./packages/${p}`),
// excludedFiles: ["**/dist/**", "**/__generated__/*", "**/*.d.ts"],
...tsProject(`./packages/${p}`),
rules: {
...tsProject(`./packages/${p}`).rules,
"no-restricted-imports": [
"error",
{
patterns: ["src/*"],
},
],
"node/file-extension-in-import": ["error", "always"],
},
})),
],
};