-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
85 lines (81 loc) · 2.25 KB
/
index.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
// eslint-disable-next-line @typescript-eslint/no-var-requires
const readPkgUp = require("read-pkg-up");
let hasPrettier = false;
let hasJest = false;
let hasJestDom = false;
let hasTestingLibrary = false;
try {
const { packageJson } = readPkgUp.sync({ normalize: true });
const allDeps = Object.keys({
...packageJson.peerDependencies,
...packageJson.devDependencies,
...packageJson.dependencies,
});
hasPrettier = allDeps.includes("prettier");
hasJest = allDeps.includes("jest");
hasJestDom = allDeps.includes("@testing-library/jest-dom");
hasTestingLibrary =
allDeps.includes("@testing-library/react") ||
allDeps.includes("@testing-library/react-hooks");
} catch (error) {
// ignore error
}
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: { jsx: true },
},
plugins: ["@typescript-eslint", "promise", hasJestDom && "jest-dom"].filter(
Boolean
),
extends: [
"airbnb",
"airbnb/hooks",
"plugin:@typescript-eslint/recommended",
"plugin:promise/recommended",
"plugin:compat/recommended",
hasJestDom && "plugin:jest-dom/recommended",
hasPrettier && "prettier",
].filter(Boolean),
overrides: [
// Run jest and testing-library only against test files
{
files: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
plugins: [
hasJest && "jest",
hasTestingLibrary && "testing-library",
].filter(Boolean),
extends: [
hasJest && "plugin:jest/all",
hasTestingLibrary && "plugin:testing-library/react",
].filter(Boolean),
},
],
settings: {
"import/resolver": {
typescript: {},
},
},
env: {
browser: true,
node: true,
es6: true,
...(hasJest ? { "jest/globals": true } : {}),
},
rules: {
"import/extensions": "off",
"react/function-component-definition": "off",
"react/jsx-props-no-spreading": "off",
"react/jsx-filename-extension": [
"error",
{
extensions: [".js", "jsx", ".ts", ".tsx"],
},
],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
},
};