This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
.eslintrc.cjs
125 lines (116 loc) · 2.99 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
// @ts-check
const { pwd } = require("shelljs");
const shell = require("shelljs");
const path = require("path");
let root = __dirname;
let packages = String(
shell.exec("pnpm m ls --depth -1 --porcelain", { silent: true })
)
.split("\n")
.map((p) => path.relative(root, p))
.filter((file) => file !== "" && file !== root)
.filter((file) => file.startsWith("@starbeam"));
module.exports = /** @type {import("eslint").Linter.Config} */ ({
root: true,
parser: "@typescript-eslint/parser",
ignorePatterns: ["jest/**"],
parserOptions: {
sourceType: "module",
},
plugins: ["@typescript-eslint"],
settings: {
"import/resolver": {
typescript: {
alwaysTryTypes: true,
},
},
},
overrides: [
...packages.map((p) => pkg(p)),
{
files: "./guides/**/*.ts",
extends: [
// "plugin:import/recommended",
// "plugin:import/typescript",
// "plugin:@typescript-eslint/recommended",
],
rules: {
"no-inner-declarations": "off",
},
},
],
});
/**
* @param {string} dir
* @returns {import("eslint").Linter.ConfigOverride}
*/
function pkg(dir) {
/** @type {import("eslint").Linter.ConfigOverride} */
const pkg = {
files: path.join(".", dir, "**/*.ts"),
excludedFiles: [
path.join(".", dir, "node_modules/**"),
path.join(".", dir, "**/*.d.ts"),
],
extends: [
"eslint:recommended",
"plugin:import/recommended",
"plugin:import/typescript",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
rules: {
"prefer-const": "off",
"no-unused-vars": "off",
"no-empty": "warn",
"no-fallthrough": "off",
"import/no-cycle": "warn",
"import/no-self-import": "error",
"import/no-restricted-paths": [
"error",
{
zones: packages
.filter((p) => p !== dir)
.map((p) => restricted(dir, p)),
},
],
"import/no-extraneous-dependencies": [
"error",
{
packageDir: [path.join(__dirname, dir)],
},
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
},
],
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-explicit-any": [
"error",
{
ignoreRestArgs: true,
fixToUnknown: true,
},
],
},
};
// console.log(require("util").inspect(pkg, { depth: null, colors: true }));
return pkg;
}
/**
* @param {string} source
* @param {string} restricted
*/
function restricted(source, restricted) {
let message =
restricted.startsWith("@starbeam") && source.startsWith("@starbeam")
? `Import files from ${restricted} through its package`
: `Don't import files from ${restricted} from @starbeam pacakges`;
return {
target: source,
from: restricted,
message: `Import files from ${restricted} through its package`,
};
}