@whoj/eslint-config 1.5.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +210 -0
- package/bin/index.js +2 -0
- package/dist/chunk-3P3JBQLJ.js +5191 -0
- package/dist/chunk-5NT2OOQW.js +29719 -0
- package/dist/chunk-7F5ASJF4.js +1962 -0
- package/dist/chunk-DLJMV7EV.js +626 -0
- package/dist/chunk-G5WGJHBR.js +149 -0
- package/dist/chunk-IDB36RF3.js +353 -0
- package/dist/chunk-IKAXXATW.js +6400 -0
- package/dist/chunk-MKKAXXPL.js +5769 -0
- package/dist/chunk-MKNYKNDN.js +65 -0
- package/dist/chunk-PVCENCBM.js +1053 -0
- package/dist/chunk-QT5XME2Q.js +209134 -0
- package/dist/chunk-THBKBMVU.js +8352 -0
- package/dist/chunk-VSLGWZT6.js +115 -0
- package/dist/chunk-XZGWRL6X.js +1520 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +567 -0
- package/dist/dist-MYXPM6TG.js +4953 -0
- package/dist/dist-ZJ2E2ITJ.js +26233 -0
- package/dist/eslint-plugin-react-hooks-BV2CYKDG.js +2559 -0
- package/dist/eslint-plugin-react-refresh-N5P3A37Z.js +272 -0
- package/dist/index.d.ts +16956 -0
- package/dist/index.js +2729 -0
- package/dist/lib-C6BFP32Q.js +24437 -0
- package/dist/lib-FENTQ4WJ.js +10106 -0
- package/dist/lib-WKUBBNE4.js +26 -0
- package/dist/lib-XQB7MXK6.js +9 -0
- package/dist/sass.node-L3JPZGSW.js +125580 -0
- package/dist/typescript-LG2A6BNW.js +5 -0
- package/package.json +129 -29
- package/index.js +0 -5
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS,
|
|
3
|
+
init_esm_shims
|
|
4
|
+
} from "./chunk-MKNYKNDN.js";
|
|
5
|
+
|
|
6
|
+
// node_modules/.pnpm/eslint-plugin-react-refresh@0.4.18_eslint@9.19.0_jiti@2.4.2_/node_modules/eslint-plugin-react-refresh/index.js
|
|
7
|
+
var require_eslint_plugin_react_refresh = __commonJS({
|
|
8
|
+
"node_modules/.pnpm/eslint-plugin-react-refresh@0.4.18_eslint@9.19.0_jiti@2.4.2_/node_modules/eslint-plugin-react-refresh/index.js"(exports, module) {
|
|
9
|
+
init_esm_shims();
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var src_exports = {};
|
|
28
|
+
__export(src_exports, {
|
|
29
|
+
configs: () => configs,
|
|
30
|
+
default: () => src_default,
|
|
31
|
+
rules: () => rules
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
var reactComponentNameRE = /^[A-Z][a-zA-Z0-9]*$/u;
|
|
35
|
+
var onlyExportComponents = {
|
|
36
|
+
meta: {
|
|
37
|
+
messages: {
|
|
38
|
+
exportAll: "This rule can't verify that `export *` only exports components.",
|
|
39
|
+
namedExport: "Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.",
|
|
40
|
+
anonymousExport: "Fast refresh can't handle anonymous components. Add a name to your export.",
|
|
41
|
+
localComponents: "Fast refresh only works when a file only exports components. Move your component(s) to a separate file.",
|
|
42
|
+
noExport: "Fast refresh only works when a file has exports. Move your component(s) to a separate file.",
|
|
43
|
+
reactContext: "Fast refresh only works when a file only exports components. Move your React context(s) to a separate file."
|
|
44
|
+
},
|
|
45
|
+
type: "problem",
|
|
46
|
+
schema: [
|
|
47
|
+
{
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: {
|
|
50
|
+
allowExportNames: { type: "array", items: { type: "string" } },
|
|
51
|
+
allowConstantExport: { type: "boolean" },
|
|
52
|
+
customHOCs: { type: "array", items: { type: "string" } },
|
|
53
|
+
checkJS: { type: "boolean" }
|
|
54
|
+
},
|
|
55
|
+
additionalProperties: false
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
defaultOptions: [],
|
|
60
|
+
create: (context) => {
|
|
61
|
+
const {
|
|
62
|
+
allowExportNames,
|
|
63
|
+
allowConstantExport = false,
|
|
64
|
+
customHOCs = [],
|
|
65
|
+
checkJS = false
|
|
66
|
+
} = context.options[0] ?? {};
|
|
67
|
+
const filename = context.filename;
|
|
68
|
+
if (filename.includes(".test.") || filename.includes(".spec.") || filename.includes(".cy.") || filename.includes(".stories.")) {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
const shouldScan = filename.endsWith(".jsx") || filename.endsWith(".tsx") || checkJS && filename.endsWith(".js");
|
|
72
|
+
if (!shouldScan)
|
|
73
|
+
return {};
|
|
74
|
+
const allowExportNamesSet = allowExportNames ? new Set(allowExportNames) : void 0;
|
|
75
|
+
const reactHOCs = ["memo", "forwardRef", ...customHOCs];
|
|
76
|
+
const canBeReactFunctionComponent = (init) => {
|
|
77
|
+
if (!init)
|
|
78
|
+
return false;
|
|
79
|
+
if (init.type === "ArrowFunctionExpression")
|
|
80
|
+
return true;
|
|
81
|
+
if (init.type === "CallExpression" && init.callee.type === "Identifier") {
|
|
82
|
+
return reactHOCs.includes(init.callee.name);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
Program(program) {
|
|
88
|
+
let hasExports = false;
|
|
89
|
+
let hasReactExport = false;
|
|
90
|
+
let reactIsInScope = false;
|
|
91
|
+
const localComponents = [];
|
|
92
|
+
const nonComponentExports = [];
|
|
93
|
+
const reactContextExports = [];
|
|
94
|
+
const handleExportIdentifier = (identifierNode, isFunction, init) => {
|
|
95
|
+
if (identifierNode.type !== "Identifier") {
|
|
96
|
+
nonComponentExports.push(identifierNode);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (allowExportNamesSet == null ? void 0 : allowExportNamesSet.has(identifierNode.name))
|
|
100
|
+
return;
|
|
101
|
+
if (allowConstantExport && init && (init.type === "Literal" || // 1, "foo"
|
|
102
|
+
init.type === "UnaryExpression" || // -1
|
|
103
|
+
init.type === "TemplateLiteral" || // `Some ${template}`
|
|
104
|
+
init.type === "BinaryExpression")) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (isFunction) {
|
|
108
|
+
if (reactComponentNameRE.test(identifierNode.name)) {
|
|
109
|
+
hasReactExport = true;
|
|
110
|
+
} else {
|
|
111
|
+
nonComponentExports.push(identifierNode);
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
if (init && init.type === "CallExpression" && // createContext || React.createContext
|
|
115
|
+
(init.callee.type === "Identifier" && init.callee.name === "createContext" || init.callee.type === "MemberExpression" && init.callee.property.type === "Identifier" && init.callee.property.name === "createContext")) {
|
|
116
|
+
reactContextExports.push(identifierNode);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (init && // Switch to allowList?
|
|
120
|
+
notReactComponentExpression.has(init.type)) {
|
|
121
|
+
nonComponentExports.push(identifierNode);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (reactComponentNameRE.test(identifierNode.name)) {
|
|
125
|
+
hasReactExport = true;
|
|
126
|
+
} else {
|
|
127
|
+
nonComponentExports.push(identifierNode);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const handleExportDeclaration = (node) => {
|
|
132
|
+
var _a, _b;
|
|
133
|
+
if (node.type === "VariableDeclaration") {
|
|
134
|
+
for (const variable of node.declarations) {
|
|
135
|
+
handleExportIdentifier(
|
|
136
|
+
variable.id,
|
|
137
|
+
canBeReactFunctionComponent(variable.init),
|
|
138
|
+
variable.init
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
} else if (node.type === "FunctionDeclaration") {
|
|
142
|
+
if (node.id === null) {
|
|
143
|
+
context.report({ messageId: "anonymousExport", node });
|
|
144
|
+
} else {
|
|
145
|
+
handleExportIdentifier(node.id, true);
|
|
146
|
+
}
|
|
147
|
+
} else if (node.type === "CallExpression") {
|
|
148
|
+
if (node.callee.type === "CallExpression" && node.callee.callee.type === "Identifier" && node.callee.callee.name === "connect") {
|
|
149
|
+
hasReactExport = true;
|
|
150
|
+
} else if (node.callee.type !== "Identifier") {
|
|
151
|
+
if (node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && reactHOCs.includes(node.callee.property.name)) {
|
|
152
|
+
hasReactExport = true;
|
|
153
|
+
} else {
|
|
154
|
+
context.report({ messageId: "anonymousExport", node });
|
|
155
|
+
}
|
|
156
|
+
} else if (!reactHOCs.includes(node.callee.name)) {
|
|
157
|
+
context.report({ messageId: "anonymousExport", node });
|
|
158
|
+
} else if (((_a = node.arguments[0]) == null ? void 0 : _a.type) === "FunctionExpression" && node.arguments[0].id) {
|
|
159
|
+
handleExportIdentifier(node.arguments[0].id, true);
|
|
160
|
+
} else if (((_b = node.arguments[0]) == null ? void 0 : _b.type) === "Identifier") {
|
|
161
|
+
hasReactExport = true;
|
|
162
|
+
} else {
|
|
163
|
+
context.report({ messageId: "anonymousExport", node });
|
|
164
|
+
}
|
|
165
|
+
} else if (node.type === "TSEnumDeclaration") {
|
|
166
|
+
nonComponentExports.push(node.id);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
for (const node of program.body) {
|
|
170
|
+
if (node.type === "ExportAllDeclaration") {
|
|
171
|
+
if (node.exportKind === "type")
|
|
172
|
+
continue;
|
|
173
|
+
hasExports = true;
|
|
174
|
+
context.report({ messageId: "exportAll", node });
|
|
175
|
+
} else if (node.type === "ExportDefaultDeclaration") {
|
|
176
|
+
hasExports = true;
|
|
177
|
+
const declaration = node.declaration.type === "TSAsExpression" || node.declaration.type === "TSSatisfiesExpression" ? node.declaration.expression : node.declaration;
|
|
178
|
+
if (declaration.type === "VariableDeclaration" || declaration.type === "FunctionDeclaration" || declaration.type === "CallExpression") {
|
|
179
|
+
handleExportDeclaration(declaration);
|
|
180
|
+
}
|
|
181
|
+
if (declaration.type === "Identifier") {
|
|
182
|
+
handleExportIdentifier(declaration);
|
|
183
|
+
}
|
|
184
|
+
if (declaration.type === "ArrowFunctionExpression") {
|
|
185
|
+
context.report({ messageId: "anonymousExport", node });
|
|
186
|
+
}
|
|
187
|
+
} else if (node.type === "ExportNamedDeclaration") {
|
|
188
|
+
if (node.exportKind === "type")
|
|
189
|
+
continue;
|
|
190
|
+
hasExports = true;
|
|
191
|
+
if (node.declaration)
|
|
192
|
+
handleExportDeclaration(node.declaration);
|
|
193
|
+
for (const specifier of node.specifiers) {
|
|
194
|
+
handleExportIdentifier(
|
|
195
|
+
specifier.exported.type === "Identifier" && specifier.exported.name === "default" ? specifier.local : specifier.exported
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
} else if (node.type === "VariableDeclaration") {
|
|
199
|
+
for (const variable of node.declarations) {
|
|
200
|
+
if (variable.id.type === "Identifier" && reactComponentNameRE.test(variable.id.name) && canBeReactFunctionComponent(variable.init)) {
|
|
201
|
+
localComponents.push(variable.id);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} else if (node.type === "FunctionDeclaration") {
|
|
205
|
+
if (reactComponentNameRE.test(node.id.name)) {
|
|
206
|
+
localComponents.push(node.id);
|
|
207
|
+
}
|
|
208
|
+
} else if (node.type === "ImportDeclaration" && node.source.value === "react") {
|
|
209
|
+
reactIsInScope = true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (checkJS && !reactIsInScope)
|
|
213
|
+
return;
|
|
214
|
+
if (hasExports) {
|
|
215
|
+
if (hasReactExport) {
|
|
216
|
+
for (const node of nonComponentExports) {
|
|
217
|
+
context.report({ messageId: "namedExport", node });
|
|
218
|
+
}
|
|
219
|
+
for (const node of reactContextExports) {
|
|
220
|
+
context.report({ messageId: "reactContext", node });
|
|
221
|
+
}
|
|
222
|
+
} else if (localComponents.length) {
|
|
223
|
+
for (const node of localComponents) {
|
|
224
|
+
context.report({ messageId: "localComponents", node });
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} else if (localComponents.length) {
|
|
228
|
+
for (const node of localComponents) {
|
|
229
|
+
context.report({ messageId: "noExport", node });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
var notReactComponentExpression = /* @__PURE__ */ new Set([
|
|
237
|
+
"ArrayExpression",
|
|
238
|
+
"AwaitExpression",
|
|
239
|
+
"BinaryExpression",
|
|
240
|
+
"ChainExpression",
|
|
241
|
+
"ConditionalExpression",
|
|
242
|
+
"Literal",
|
|
243
|
+
"LogicalExpression",
|
|
244
|
+
"ObjectExpression",
|
|
245
|
+
"TemplateLiteral",
|
|
246
|
+
"ThisExpression",
|
|
247
|
+
"UnaryExpression",
|
|
248
|
+
"UpdateExpression"
|
|
249
|
+
]);
|
|
250
|
+
var rules = {
|
|
251
|
+
"only-export-components": onlyExportComponents
|
|
252
|
+
};
|
|
253
|
+
var plugin = { rules };
|
|
254
|
+
var configs = {
|
|
255
|
+
recommended: {
|
|
256
|
+
plugins: { "react-refresh": plugin },
|
|
257
|
+
rules: { "react-refresh/only-export-components": "error" }
|
|
258
|
+
},
|
|
259
|
+
vite: {
|
|
260
|
+
plugins: { "react-refresh": plugin },
|
|
261
|
+
rules: {
|
|
262
|
+
"react-refresh/only-export-components": [
|
|
263
|
+
"error",
|
|
264
|
+
{ allowConstantExport: true }
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
var src_default = { rules, configs };
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
export default require_eslint_plugin_react_refresh();
|