Repository navigation
Expand file tree
/
Copy patheslint.config.mjs
More file actions
130 lines (123 loc) · 3.5 KB
/
Copy patheslint.config.mjs
File metadata and controls
130 lines (123 loc) · 3.5 KB
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
import js from "@eslint/js";
import globals from "globals";
import tseslint from "typescript-eslint";
const HOST_FREE = "Model and webview code must not reach into the extension host; pass plain data across the boundary.";
const SPAWN_ONLY = "Only src/daemon/process.ts may spawn a child process.";
const vscodePath = { name: "vscode", message: HOST_FREE };
const childProcessPaths = [
{ name: "child_process", message: SPAWN_ONLY },
{ name: "node:child_process", message: SPAWN_ONLY },
];
const requireBan = (pattern, message) => ({
selector: `CallExpression[callee.name='require'] > Literal[value=${pattern}]`,
message,
});
const noRequireChildProcess = requireBan("/^(node:)?child_process$/", SPAWN_ONLY);
const noRequireVscode = requireBan("/^vscode$/", HOST_FREE);
const noInnerHtml = [
{
selector: "MemberExpression[property.name='innerHTML']",
message: "innerHTML belongs in src/webview only, and only downstream of DOMPurify.",
},
{
selector: "MemberExpression[computed=true] > Literal[value='innerHTML']",
message: "innerHTML belongs in src/webview only, and only downstream of DOMPurify.",
},
];
const securityRules = {
"no-eval": "error",
"no-new-func": "error",
"no-console": "error",
};
export default tseslint.config(
{
ignores: [
"dist/**",
"out/**",
"coverage/**",
".vscode-test/**",
"src/protocol/generated.ts",
],
},
js.configs.recommended,
{
files: ["**/*.ts"],
extends: [tseslint.configs.recommendedTypeChecked],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
...securityRules,
"@typescript-eslint/no-implied-eval": "error",
"no-restricted-imports": ["error", { paths: childProcessPaths }],
"no-restricted-syntax": ["error", noRequireChildProcess],
},
},
{
files: ["src/**/*.ts"],
ignores: ["src/webview/**"],
rules: {
"no-restricted-syntax": ["error", ...noInnerHtml, noRequireChildProcess],
},
},
{
files: ["src/model/**/*.ts"],
rules: {
"no-restricted-imports": ["error", { paths: [vscodePath, ...childProcessPaths] }],
"no-restricted-syntax": ["error", ...noInnerHtml, noRequireChildProcess, noRequireVscode],
},
},
{
files: ["src/webview/**/*.ts"],
languageOptions: {
globals: globals.browser,
parserOptions: {
projectService: false,
project: ["./tsconfig.webview.json"],
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
"no-restricted-imports": ["error", { paths: [vscodePath, ...childProcessPaths] }],
"no-restricted-syntax": ["error", noRequireChildProcess, noRequireVscode],
},
},
{
files: ["src/daemon/process.ts"],
rules: {
"no-restricted-imports": "off",
"no-restricted-syntax": ["error", ...noInnerHtml],
},
},
{
files: ["test/**/*.ts"],
languageOptions: {
globals: { ...globals.node, ...globals.mocha },
parserOptions: {
projectService: false,
project: ["./tsconfig.test.json"],
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
"no-console": "off",
"no-restricted-imports": "off",
},
},
{
files: ["**/*.js", "**/*.mjs", "**/*.cjs"],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
globals: globals.node,
},
rules: {
...securityRules,
"no-console": "off",
"no-implied-eval": "error",
},
},
);