-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (91 loc) · 2.71 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import tsPlugin from "@typescript-eslint/eslint-plugin";
import tsParser from "@typescript-eslint/parser";
import js from "@eslint/js";
import importPlugin from "eslint-plugin-import";
import prettierPlugin from "eslint-plugin-prettier";
import reactPlugin from "eslint-plugin-react";
const allFiles = ["**/*.js", "**/*.jsx", "**/*.cjs", "**/*.cjsx", "**/*.mjs", "**/*.mjsx", "**/*.ts", "**/*.tsx"];
const reactFiles = allFiles.filter((f) => f.endsWith("x"));
const tsFiles = allFiles.filter((f) => f.includes("ts"));
export default [
// files to ignore across all projects
{
ignores: [
// type definitions for styles
"**/*.scss.d.ts",
// dependencies and package manager components
"node_modules/*",
".yarn/*",
".pnp.cjs",
".pnp.loader.mjs",
],
},
// apply to all: eslint recommended, prettier and import
{
files: allFiles,
plugins: {
js: js,
prettier: prettierPlugin,
import: importPlugin,
},
settings: {
// ensure that Yarn PnP dependencies are also treated as external
"import/external-module-folders": ["node_modules", ".yarn"],
},
rules: {
// customise prettier behaviour
"prettier/prettier": [
"error",
{
printWidth: 120,
semi: true,
trailingComma: "all",
arrowParens: "always",
},
],
// enable some stricter rules on import/export formatting
"import/group-exports": ["warn"],
"import/newline-after-import": ["warn"],
"import/no-useless-path-segments": ["warn"],
"import/order": ["warn"],
},
},
// apply react-specific rules
{
files: reactFiles,
settings: {
react: {
version: "detect",
},
},
plugins: {
react: reactPlugin,
},
},
// apply type-aware rules
{
files: tsFiles,
languageOptions: {
parser: tsParser,
// lines below are fair assumptions but may be overwritten by the consumer
sourceType: "module",
parserOptions: {
project: "./tsconfig.json",
},
},
plugins: {
"@typescript-eslint": tsPlugin,
},
rules: {
...tsPlugin.configs["eslint-recommended"].rules,
...tsPlugin.configs["recommended-type-checked"].rules,
...tsPlugin.configs["stylistic-type-checked"].rules,
...importPlugin.configs.typescript.rules,
// the no-unresolved rule doesn't understand the fully-specified *.js paths for TS ES modules
// unresolvable paths will cause parser and compiler errors anyway, so we can turn off the rule
"import/no-unresolved": "off",
// prefer types over interfaces
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
},
},
];