forked from OKEAMAH/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-eslint-config.js
More file actions
123 lines (111 loc) · 2.88 KB
/
Copy pathbundle-eslint-config.js
File metadata and controls
123 lines (111 loc) · 2.88 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
import fs from "node:fs/promises";
import eslintPluginCompat from "eslint-plugin-compat";
const { browserslist: targets } = JSON.parse(
await fs.readFile(new URL("../package.json", import.meta.url)),
);
const browserFiles = [
"doc.js",
"doc.mjs",
"standalone.js",
"standalone.mjs",
"plugins/*",
];
const nodejsFiles = ["index.cjs", "index.mjs", "bin/*", "internal/*"];
const restrictedSyntaxes = [
{
selector: String.raw`CallExpression[callee.name="require"][arguments.0.value=/^\..*?\.mjs$/]`,
message: ".mjs file can't be `require()`d",
},
];
const browserRestrictedSyntaxes = [
{
selector: 'CallExpression[callee.name="require"]',
message: "Universal bundles should not include any `require()` call.",
},
{
selector: "ImportDeclaration",
message: "Universal bundles should not include any `import` declaration.",
},
{
selector:
":matches(ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration)[source]",
message: "Universal bundles should not `export` from other files.",
},
{
selector: "ImportExpression",
message: "Universal bundles should not include any `import()`.",
},
];
const nodejsRestrictedSyntaxes = [
// Forbid top level `require()` parsers
{
selector:
'CallExpression:not(:function *)[callee.name="require"][arguments.0.value=/plugins/]',
message: "Parsers should be inline `require()`d.",
},
// Forbid top level `import()` parsers
{
selector: "ImportExpression:not(:function *)[source.value=/plugins/]",
message: "Parsers should be inline `import()`ed.",
},
// Forbid `import`/`export` parsers
{
selector:
":matches(ImportDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration)[source.value=/plugins/]",
message: "Parsers should be inline `import()`ed.",
},
];
/* TODO[@fisker]: Fix `no-restricted-syntax` */
export default [
{
plugins: {
compat: eslintPluginCompat,
},
settings: {
targets,
lintAllEsApis: true,
polyfills: [
// These are not really polyfilled, but seems safe to use in target browsers
"BigInt",
"Symbol.asyncIterator",
],
},
linterOptions: {
noInlineConfig: true,
reportUnusedDisableDirectives: "off",
},
rules: {
"compat/compat": "error",
"no-restricted-syntax": ["error", ...restrictedSyntaxes],
},
},
{
files: browserFiles,
rules: {
"no-restricted-syntax": [
"error",
...restrictedSyntaxes,
...browserRestrictedSyntaxes,
],
},
},
{
files: nodejsFiles,
rules: {
"no-restricted-syntax": [
"error",
...restrictedSyntaxes,
...nodejsRestrictedSyntaxes,
],
},
},
{
files: ["bin/prettier.cjs"],
languageOptions: {
ecmaVersion: 5,
},
rules: {
"compat/compat": "error",
},
},
];