@soujvnunes/eslint-config 0.7.1 → 0.9.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/README.md +67 -2
- package/dist/index.d.ts +15 -7
- package/dist/index.js +1359 -96
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -11,25 +11,1072 @@ import react from "eslint-plugin-react";
|
|
|
11
11
|
import reactHooks from "eslint-plugin-react-hooks";
|
|
12
12
|
import security from "eslint-plugin-security";
|
|
13
13
|
import unusedImports from "eslint-plugin-unused-imports";
|
|
14
|
-
import
|
|
14
|
+
import globals2 from "globals";
|
|
15
15
|
import tseslint from "typescript-eslint";
|
|
16
16
|
|
|
17
|
-
//
|
|
18
|
-
|
|
17
|
+
// needlessUseClient.ts
|
|
18
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
19
|
+
|
|
20
|
+
// findUseClientDirective.ts
|
|
21
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
|
|
22
|
+
var findUseClientDirective = (program) => {
|
|
23
|
+
for (const statement of program.body) {
|
|
24
|
+
if (statement.type !== AST_NODE_TYPES.ExpressionStatement || statement.directive === void 0)
|
|
25
|
+
return null;
|
|
26
|
+
if (statement.directive === "use client") return statement;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// needsClient.ts
|
|
32
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES12, TSESLint as TSESLint4 } from "@typescript-eslint/utils";
|
|
33
|
+
import globals from "globals";
|
|
34
|
+
|
|
35
|
+
// calleeName.ts
|
|
36
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/utils";
|
|
37
|
+
var calleeName = (callee) => {
|
|
38
|
+
if (callee.type === AST_NODE_TYPES2.Identifier) return callee.name;
|
|
39
|
+
if (callee.type === AST_NODE_TYPES2.MemberExpression && callee.property.type === AST_NODE_TYPES2.Identifier)
|
|
40
|
+
return callee.property.name;
|
|
41
|
+
return "";
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// childNodes.ts
|
|
45
|
+
var SKIPPED_KEYS = /* @__PURE__ */ new Set(["typeAnnotation", "typeArguments", "typeParameters", "returnType"]);
|
|
46
|
+
var isNode = (value) => typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
47
|
+
var childNodes = (node, visitorKeys) => (visitorKeys[node.type] ?? []).filter((key) => !SKIPPED_KEYS.has(key)).flatMap((key) => {
|
|
48
|
+
const value = Reflect.get(node, key);
|
|
49
|
+
return (Array.isArray(value) ? value : [value]).filter(isNode);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// createClassifier.ts
|
|
53
|
+
import { ASTUtils, AST_NODE_TYPES as AST_NODE_TYPES11, TSESLint as TSESLint3 } from "@typescript-eslint/utils";
|
|
54
|
+
|
|
55
|
+
// everyDef.ts
|
|
56
|
+
var everyDef = (variable, test) => !!variable && variable.defs.length > 0 && variable.defs.every(test);
|
|
57
|
+
|
|
58
|
+
// importedName.ts
|
|
59
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES3, TSESLint } from "@typescript-eslint/utils";
|
|
60
|
+
var { DefinitionType } = TSESLint.Scope;
|
|
61
|
+
var importedName = (variable) => {
|
|
62
|
+
const [def] = variable?.defs ?? [];
|
|
63
|
+
if (def?.type !== DefinitionType.ImportBinding || def.node.type !== AST_NODE_TYPES3.ImportSpecifier)
|
|
64
|
+
return "";
|
|
65
|
+
const { imported } = def.node;
|
|
66
|
+
return imported.type === AST_NODE_TYPES3.Identifier ? imported.name : imported.value;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// isComponentFunction.ts
|
|
70
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES6 } from "@typescript-eslint/utils";
|
|
71
|
+
|
|
72
|
+
// isComponentName.ts
|
|
73
|
+
var isComponentName = (name) => !!name && /^[A-Z]/u.test(name);
|
|
74
|
+
|
|
75
|
+
// isComponentWrapper.ts
|
|
76
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES5 } from "@typescript-eslint/utils";
|
|
77
|
+
|
|
78
|
+
// isComponentWrapperCall.ts
|
|
79
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES4 } from "@typescript-eslint/utils";
|
|
80
|
+
var WRAPPERS = /* @__PURE__ */ new Set(["memo", "forwardRef"]);
|
|
81
|
+
var isComponentWrapperCall = (node) => node.type === AST_NODE_TYPES4.CallExpression && WRAPPERS.has(calleeName(node.callee));
|
|
82
|
+
|
|
83
|
+
// isComponentWrapper.ts
|
|
84
|
+
var isComponentWrapper = (node) => isComponentWrapperCall(node) || node.type === AST_NODE_TYPES5.TSAsExpression || node.type === AST_NODE_TYPES5.TSSatisfiesExpression;
|
|
85
|
+
|
|
86
|
+
// isComponentFunction.ts
|
|
87
|
+
var MODULE_LEVEL = /* @__PURE__ */ new Set([
|
|
88
|
+
AST_NODE_TYPES6.Program,
|
|
89
|
+
AST_NODE_TYPES6.ExportNamedDeclaration,
|
|
90
|
+
AST_NODE_TYPES6.ExportDefaultDeclaration
|
|
91
|
+
]);
|
|
92
|
+
var isComponentFunction = (node) => {
|
|
93
|
+
if (node.type === AST_NODE_TYPES6.FunctionDeclaration)
|
|
94
|
+
return MODULE_LEVEL.has(node.parent.type) && (node.parent.type === AST_NODE_TYPES6.ExportDefaultDeclaration || isComponentName(node.id?.name));
|
|
95
|
+
if (node.type !== AST_NODE_TYPES6.ArrowFunctionExpression && node.type !== AST_NODE_TYPES6.FunctionExpression)
|
|
96
|
+
return false;
|
|
97
|
+
let holder = node.parent;
|
|
98
|
+
while (isComponentWrapper(holder) && holder.parent) holder = holder.parent;
|
|
99
|
+
if (holder.type === AST_NODE_TYPES6.ExportDefaultDeclaration) return true;
|
|
100
|
+
return holder.type === AST_NODE_TYPES6.VariableDeclarator && holder.id.type === AST_NODE_TYPES6.Identifier && isComponentName(holder.id.name) && MODULE_LEVEL.has(holder.parent.parent?.type ?? "");
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// isComponentInit.ts
|
|
104
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES8 } from "@typescript-eslint/utils";
|
|
105
|
+
|
|
106
|
+
// isFunctionNode.ts
|
|
107
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES7 } from "@typescript-eslint/utils";
|
|
108
|
+
var isFunctionNode = (node) => node.type === AST_NODE_TYPES7.ArrowFunctionExpression || node.type === AST_NODE_TYPES7.FunctionExpression || node.type === AST_NODE_TYPES7.FunctionDeclaration;
|
|
109
|
+
|
|
110
|
+
// isComponentInit.ts
|
|
111
|
+
var isComponentInit = (init) => {
|
|
112
|
+
if (!init) return false;
|
|
113
|
+
if (isFunctionNode(init)) return true;
|
|
114
|
+
if (!isComponentWrapper(init)) return false;
|
|
115
|
+
if (init.type !== AST_NODE_TYPES8.CallExpression) return isComponentInit(init.expression);
|
|
116
|
+
const [inner] = init.arguments;
|
|
117
|
+
if (inner?.type === AST_NODE_TYPES8.Identifier) return isComponentName(inner.name);
|
|
118
|
+
return isComponentInit(inner ?? null);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// isNamespaceImport.ts
|
|
122
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES9, TSESLint as TSESLint2 } from "@typescript-eslint/utils";
|
|
123
|
+
var { DefinitionType: DefinitionType2 } = TSESLint2.Scope;
|
|
124
|
+
var NAMESPACE_PACKAGES = /* @__PURE__ */ new Set(["radix-ui"]);
|
|
125
|
+
var isNamespaceImport = (variable) => everyDef(
|
|
126
|
+
variable,
|
|
127
|
+
(def) => def.type === DefinitionType2.ImportBinding && (def.node.type === AST_NODE_TYPES9.ImportNamespaceSpecifier || def.node.type === AST_NODE_TYPES9.ImportSpecifier && def.parent.type === AST_NODE_TYPES9.ImportDeclaration && NAMESPACE_PACKAGES.has(def.parent.source.value))
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// patternDefaults.ts
|
|
131
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES10 } from "@typescript-eslint/utils";
|
|
132
|
+
var patternDefaults = (name) => {
|
|
133
|
+
const defaults = [];
|
|
134
|
+
let current = name;
|
|
135
|
+
while (current.parent) {
|
|
136
|
+
const { parent } = current;
|
|
137
|
+
if (parent.type === AST_NODE_TYPES10.AssignmentPattern && parent.left === current)
|
|
138
|
+
defaults.push(parent.right);
|
|
139
|
+
else if (parent.type === AST_NODE_TYPES10.Property && parent.value === current) {
|
|
140
|
+
if (parent.parent.type !== AST_NODE_TYPES10.ObjectPattern) break;
|
|
141
|
+
current = parent.parent;
|
|
142
|
+
continue;
|
|
143
|
+
} else if (parent.type !== AST_NODE_TYPES10.ArrayPattern && parent.type !== AST_NODE_TYPES10.RestElement)
|
|
144
|
+
break;
|
|
145
|
+
current = parent;
|
|
146
|
+
}
|
|
147
|
+
return defaults;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// createClassifier.ts
|
|
151
|
+
var { DefinitionType: DefinitionType3, ScopeType } = TSESLint3.Scope;
|
|
152
|
+
var INTRINSIC = /^[a-z]/u;
|
|
153
|
+
var PROVIDER = /(?:Context|Ctx|Provider)$/u;
|
|
154
|
+
var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
155
|
+
"push",
|
|
156
|
+
"pop",
|
|
157
|
+
"shift",
|
|
158
|
+
"unshift",
|
|
159
|
+
"splice",
|
|
160
|
+
"sort",
|
|
161
|
+
"reverse",
|
|
162
|
+
"fill",
|
|
163
|
+
"copyWithin",
|
|
164
|
+
"set",
|
|
165
|
+
"add",
|
|
166
|
+
"delete",
|
|
167
|
+
"clear"
|
|
168
|
+
]);
|
|
169
|
+
var MODULE_SCOPES = /* @__PURE__ */ new Set([ScopeType.module, ScopeType.global]);
|
|
170
|
+
var LITERAL_INITS = /* @__PURE__ */ new Set([
|
|
171
|
+
AST_NODE_TYPES11.ArrayExpression,
|
|
172
|
+
AST_NODE_TYPES11.Literal,
|
|
173
|
+
AST_NODE_TYPES11.TemplateLiteral
|
|
174
|
+
]);
|
|
175
|
+
var METHOD_NAMES = new Set(
|
|
176
|
+
[String.prototype, Array.prototype, Number.prototype, Object.prototype].flatMap(
|
|
177
|
+
(prototype) => Object.getOwnPropertyNames(prototype).filter(
|
|
178
|
+
(name) => typeof Reflect.get(prototype, name) === "function"
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
var ALWAYS = { data: true, stable: true };
|
|
183
|
+
var NEVER = { data: false, stable: false };
|
|
184
|
+
var PER_RENDER = { data: true, stable: false };
|
|
185
|
+
var DECLARATION = { data: false, stable: true };
|
|
186
|
+
var both = (left, right) => ({
|
|
187
|
+
data: left.data && right.data,
|
|
188
|
+
stable: left.stable && right.stable
|
|
189
|
+
});
|
|
190
|
+
var all = (verdicts2) => verdicts2.reduce(both, ALWAYS);
|
|
191
|
+
var keyName = (key, computed) => {
|
|
192
|
+
if (!computed && key.type === AST_NODE_TYPES11.Identifier) return key.name;
|
|
193
|
+
if (key.type === AST_NODE_TYPES11.Literal && typeof key.value === "string") return key.value;
|
|
194
|
+
return void 0;
|
|
195
|
+
};
|
|
196
|
+
var isMutated = (variable) => variable.references.some(({ identifier }) => {
|
|
197
|
+
let current = identifier;
|
|
198
|
+
while (current.parent?.type === AST_NODE_TYPES11.MemberExpression && current.parent.object === current)
|
|
199
|
+
current = current.parent;
|
|
200
|
+
const { parent } = current;
|
|
201
|
+
if (current === identifier)
|
|
202
|
+
return parent?.type === AST_NODE_TYPES11.CallExpression && parent.callee !== current;
|
|
203
|
+
const method = current.type === AST_NODE_TYPES11.MemberExpression ? keyName(current.property, current.computed) : void 0;
|
|
204
|
+
return parent?.type === AST_NODE_TYPES11.AssignmentExpression && parent.left === current || parent?.type === AST_NODE_TYPES11.UpdateExpression || parent?.type === AST_NODE_TYPES11.UnaryExpression && parent.operator === "delete" || parent?.type === AST_NODE_TYPES11.CallExpression && parent.callee === current && MUTATING_METHODS.has(method ?? "");
|
|
205
|
+
});
|
|
206
|
+
var createClassifier = (sourceCode, importMembersAreData) => {
|
|
207
|
+
const variableOf = (node, name) => ASTUtils.findVariable(sourceCode.getScope(node), name);
|
|
208
|
+
const memo = /* @__PURE__ */ new Map();
|
|
209
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
210
|
+
let cycled = false;
|
|
211
|
+
const withDefault = (name, verdict) => all([verdict, ...patternDefaults(name).map((fallback) => classify2(fallback, "prop"))]);
|
|
212
|
+
const written = /* @__PURE__ */ new Map();
|
|
213
|
+
const isWritten = (variable, kind) => {
|
|
214
|
+
const cached = written.get(variable);
|
|
215
|
+
if (cached !== void 0) return cached;
|
|
216
|
+
const verdict = kind !== "const" && variable.references.some((reference) => reference.isWrite() && !reference.init) || isMutated(variable);
|
|
217
|
+
written.set(variable, verdict);
|
|
218
|
+
return verdict;
|
|
219
|
+
};
|
|
220
|
+
const ofBinding = (variable) => {
|
|
221
|
+
const cached = memo.get(variable);
|
|
222
|
+
if (cached) return cached;
|
|
223
|
+
if (resolving.has(variable)) {
|
|
224
|
+
cycled = true;
|
|
225
|
+
return NEVER;
|
|
226
|
+
}
|
|
227
|
+
const outermost = resolving.size === 0;
|
|
228
|
+
if (outermost) cycled = false;
|
|
229
|
+
resolving.add(variable);
|
|
230
|
+
const verdict = all(
|
|
231
|
+
variable.defs.map((def) => {
|
|
232
|
+
if (def.type === DefinitionType3.Parameter)
|
|
233
|
+
return isComponentFunction(def.node) ? withDefault(def.name, PER_RENDER) : NEVER;
|
|
234
|
+
if (def.type === DefinitionType3.FunctionName || def.type === DefinitionType3.ClassName)
|
|
235
|
+
return DECLARATION;
|
|
236
|
+
if (def.type !== DefinitionType3.Variable || !def.node.init) return NEVER;
|
|
237
|
+
if (isWritten(variable, def.parent.kind)) return NEVER;
|
|
238
|
+
const init = classify2(def.node.init, "prop");
|
|
239
|
+
return withDefault(def.name, {
|
|
240
|
+
data: init.data,
|
|
241
|
+
stable: init.stable && MODULE_SCOPES.has(variable.scope.type) && def.parent.kind === "const"
|
|
242
|
+
});
|
|
243
|
+
})
|
|
244
|
+
);
|
|
245
|
+
resolving.delete(variable);
|
|
246
|
+
if (outermost && !cycled) memo.set(variable, verdict);
|
|
247
|
+
return verdict;
|
|
248
|
+
};
|
|
249
|
+
const ofImport = (position, isDictionaryRead) => ({
|
|
250
|
+
data: position === "text" || isDictionaryRead && importMembersAreData,
|
|
251
|
+
stable: true
|
|
252
|
+
});
|
|
253
|
+
const isImport = (variable) => everyDef(variable, (def) => def.type === DefinitionType3.ImportBinding);
|
|
254
|
+
const ofIdentifier = (node, position) => {
|
|
255
|
+
if (node.name === "undefined") return ALWAYS;
|
|
256
|
+
const variable = variableOf(node, node.name);
|
|
257
|
+
if (!variable || variable.defs.length === 0) return NEVER;
|
|
258
|
+
if (isImport(variable)) return ofImport(position, false);
|
|
259
|
+
return ofBinding(variable);
|
|
260
|
+
};
|
|
261
|
+
const properties = /* @__PURE__ */ new Map();
|
|
262
|
+
const ofProperty = (object, name, position) => {
|
|
263
|
+
const memoKey = `${position} ${name ?? ""}`;
|
|
264
|
+
const cached = properties.get(object)?.get(memoKey);
|
|
265
|
+
if (cached) return cached;
|
|
266
|
+
let verdict = null;
|
|
267
|
+
for (const property of [...object.properties].reverse()) {
|
|
268
|
+
const isProperty = property.type === AST_NODE_TYPES11.Property;
|
|
269
|
+
const propertyName = isProperty ? keyName(property.key, property.computed) : void 0;
|
|
270
|
+
const isMatch = name !== void 0 && propertyName === name;
|
|
271
|
+
if (isMatch || name === void 0 || propertyName === void 0) {
|
|
272
|
+
const value = classify2(isProperty ? property.value : property.argument, position);
|
|
273
|
+
verdict = verdict ? both(verdict, value) : value;
|
|
274
|
+
if (isMatch) break;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const result = verdict ?? NEVER;
|
|
278
|
+
if (resolving.size === 0)
|
|
279
|
+
properties.set(object, (properties.get(object) ?? /* @__PURE__ */ new Map()).set(memoKey, result));
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
282
|
+
const ofMember = (node, position) => {
|
|
283
|
+
const name = keyName(node.property, node.computed);
|
|
284
|
+
const isMethod = name !== void 0 && METHOD_NAMES.has(name);
|
|
285
|
+
const key = node.computed ? classify2(node.property, position) : ALWAYS;
|
|
286
|
+
if (node.object.type !== AST_NODE_TYPES11.Identifier)
|
|
287
|
+
return isMethod ? NEVER : both(classify2(node.object, position), key);
|
|
288
|
+
const variable = variableOf(node.object, node.object.name);
|
|
289
|
+
if (isImport(variable)) return both(ofImport(position, !isNamespaceImport(variable)), key);
|
|
290
|
+
const [def] = variable?.defs ?? [];
|
|
291
|
+
if (!variable || def?.type !== DefinitionType3.Variable || !def.node.init || def.node.id.type !== AST_NODE_TYPES11.Identifier)
|
|
292
|
+
return isMethod ? NEVER : both(ofIdentifier(node.object, position), key);
|
|
293
|
+
if (isWritten(variable, def.parent.kind)) return NEVER;
|
|
294
|
+
const binding = ofBinding(variable);
|
|
295
|
+
const { init } = def.node;
|
|
296
|
+
if (init.type === AST_NODE_TYPES11.ObjectExpression) {
|
|
297
|
+
const value = ofProperty(init, name, position);
|
|
298
|
+
return { data: value.data && key.data, stable: value.stable && binding.stable && key.stable };
|
|
299
|
+
}
|
|
300
|
+
if (init.type === AST_NODE_TYPES11.ArrayExpression && node.computed) return both(binding, key);
|
|
301
|
+
if (LITERAL_INITS.has(init.type))
|
|
302
|
+
return name === "length" ? { data: true, stable: binding.stable } : NEVER;
|
|
303
|
+
return isMethod ? NEVER : both(binding, key);
|
|
304
|
+
};
|
|
305
|
+
const classify2 = (node, position) => {
|
|
306
|
+
if (!node) return NEVER;
|
|
307
|
+
switch (node.type) {
|
|
308
|
+
case AST_NODE_TYPES11.Literal:
|
|
309
|
+
return "regex" in node ? NEVER : ALWAYS;
|
|
310
|
+
case AST_NODE_TYPES11.JSXEmptyExpression:
|
|
311
|
+
return ALWAYS;
|
|
312
|
+
case AST_NODE_TYPES11.TemplateLiteral:
|
|
313
|
+
return {
|
|
314
|
+
data: true,
|
|
315
|
+
stable: all(node.expressions.map((part) => classify2(part, position))).stable
|
|
316
|
+
};
|
|
317
|
+
case AST_NODE_TYPES11.UnaryExpression:
|
|
318
|
+
return { data: true, stable: classify2(node.argument, position).stable };
|
|
319
|
+
case AST_NODE_TYPES11.BinaryExpression:
|
|
320
|
+
return {
|
|
321
|
+
data: true,
|
|
322
|
+
stable: both(classify2(node.left, position), classify2(node.right, position)).stable
|
|
323
|
+
};
|
|
324
|
+
case AST_NODE_TYPES11.LogicalExpression:
|
|
325
|
+
return both(classify2(node.left, position), classify2(node.right, position));
|
|
326
|
+
case AST_NODE_TYPES11.ConditionalExpression: {
|
|
327
|
+
const branches = both(classify2(node.consequent, position), classify2(node.alternate, position));
|
|
328
|
+
return { data: branches.data, stable: branches.stable && classify2(node.test, position).stable };
|
|
329
|
+
}
|
|
330
|
+
case AST_NODE_TYPES11.ArrayExpression:
|
|
331
|
+
return all(
|
|
332
|
+
node.elements.map((element) => {
|
|
333
|
+
if (!element) return ALWAYS;
|
|
334
|
+
return classify2(
|
|
335
|
+
element.type === AST_NODE_TYPES11.SpreadElement ? element.argument : element,
|
|
336
|
+
position
|
|
337
|
+
);
|
|
338
|
+
})
|
|
339
|
+
);
|
|
340
|
+
case AST_NODE_TYPES11.ObjectExpression:
|
|
341
|
+
return all(
|
|
342
|
+
node.properties.map((property) => {
|
|
343
|
+
if (property.type === AST_NODE_TYPES11.SpreadElement)
|
|
344
|
+
return classify2(property.argument, position);
|
|
345
|
+
if (property.kind !== "init" || property.method) return NEVER;
|
|
346
|
+
const value = classify2(property.value, position);
|
|
347
|
+
return property.computed ? both(value, classify2(property.key, position)) : value;
|
|
348
|
+
})
|
|
349
|
+
);
|
|
350
|
+
case AST_NODE_TYPES11.MemberExpression:
|
|
351
|
+
return ofMember(node, position);
|
|
352
|
+
case AST_NODE_TYPES11.ChainExpression:
|
|
353
|
+
case AST_NODE_TYPES11.TSAsExpression:
|
|
354
|
+
case AST_NODE_TYPES11.TSSatisfiesExpression:
|
|
355
|
+
case AST_NODE_TYPES11.TSNonNullExpression:
|
|
356
|
+
return classify2(node.expression, position);
|
|
357
|
+
case AST_NODE_TYPES11.JSXElement:
|
|
358
|
+
case AST_NODE_TYPES11.JSXFragment:
|
|
359
|
+
return PER_RENDER;
|
|
360
|
+
case AST_NODE_TYPES11.Identifier:
|
|
361
|
+
return ofIdentifier(node, position);
|
|
362
|
+
default:
|
|
363
|
+
return NEVER;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const ofTagExpression = (node) => {
|
|
367
|
+
if (node.type === AST_NODE_TYPES11.Literal) return typeof node.value === "string" ? ALWAYS : NEVER;
|
|
368
|
+
if (node.type === AST_NODE_TYPES11.Identifier) return ofTagBinding(variableOf(node, node.name));
|
|
369
|
+
if (node.type !== AST_NODE_TYPES11.MemberExpression || node.object.type !== AST_NODE_TYPES11.Identifier)
|
|
370
|
+
return NEVER;
|
|
371
|
+
return isNamespaceImport(variableOf(node.object, node.object.name)) ? ALWAYS : NEVER;
|
|
372
|
+
};
|
|
373
|
+
const resolvingTags = /* @__PURE__ */ new Set();
|
|
374
|
+
const ofTagBinding = (variable) => {
|
|
375
|
+
if (!variable || variable.defs.length === 0 || resolvingTags.has(variable)) return NEVER;
|
|
376
|
+
resolvingTags.add(variable);
|
|
377
|
+
const isModuleLevel = MODULE_SCOPES.has(variable.scope.type);
|
|
378
|
+
const verdict = all(
|
|
379
|
+
variable.defs.map((def) => {
|
|
380
|
+
if (def.type === DefinitionType3.ImportBinding) return ALWAYS;
|
|
381
|
+
if (def.type === DefinitionType3.FunctionName) return isModuleLevel ? ALWAYS : NEVER;
|
|
382
|
+
if (def.type === DefinitionType3.Parameter)
|
|
383
|
+
return isComponentFunction(def.node) ? all([PER_RENDER, ...patternDefaults(def.name).map(ofTagExpression)]) : NEVER;
|
|
384
|
+
if (def.type !== DefinitionType3.Variable) return NEVER;
|
|
385
|
+
return isModuleLevel && def.parent.kind === "const" && isComponentInit(def.node.init) ? ALWAYS : NEVER;
|
|
386
|
+
})
|
|
387
|
+
);
|
|
388
|
+
resolvingTags.delete(variable);
|
|
389
|
+
return verdict;
|
|
390
|
+
};
|
|
391
|
+
const isProvider = (element, name, variable) => {
|
|
392
|
+
const [only, ...rest] = element.attributes;
|
|
393
|
+
const isValueOnly = rest.length === 0 && !element.selfClosing && only?.type === AST_NODE_TYPES11.JSXAttribute && only.name.type === AST_NODE_TYPES11.JSXIdentifier && only.name.name === "value";
|
|
394
|
+
return PROVIDER.test(name) || PROVIDER.test(importedName(variable)) || isValueOnly;
|
|
395
|
+
};
|
|
396
|
+
const classifyTag = (element) => {
|
|
397
|
+
const { name } = element;
|
|
398
|
+
if (name.type === AST_NODE_TYPES11.JSXNamespacedName) return ALWAYS;
|
|
399
|
+
if (name.type === AST_NODE_TYPES11.JSXIdentifier) {
|
|
400
|
+
if (INTRINSIC.test(name.name)) return ALWAYS;
|
|
401
|
+
const variable = variableOf(element, name.name);
|
|
402
|
+
return isProvider(element, name.name, variable) ? NEVER : ofTagBinding(variable);
|
|
403
|
+
}
|
|
404
|
+
return name.object.type === AST_NODE_TYPES11.JSXIdentifier && isNamespaceImport(variableOf(element, name.object.name)) ? ALWAYS : NEVER;
|
|
405
|
+
};
|
|
406
|
+
const positionOf = (element) => element.name.type === AST_NODE_TYPES11.JSXIdentifier && INTRINSIC.test(element.name.name) ? "text" : "prop";
|
|
407
|
+
return { classify: classify2, classifyTag, positionOf, variableOf };
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
// isEventHandler.ts
|
|
411
|
+
var isEventHandler = (key) => /^on[A-Z]/u.test(key);
|
|
412
|
+
|
|
413
|
+
// isFunctionAttribute.ts
|
|
414
|
+
var FUNCTION_ATTRIBUTES = /* @__PURE__ */ new Set(["ref", "action", "formAction"]);
|
|
415
|
+
var isFunctionAttribute = (key) => isEventHandler(key) || FUNCTION_ATTRIBUTES.has(key);
|
|
416
|
+
|
|
417
|
+
// needsClient.ts
|
|
418
|
+
var { DefinitionType: DefinitionType4 } = TSESLint4.Scope;
|
|
419
|
+
var HOOK = /^use[A-Z]/u;
|
|
420
|
+
var STYLESHEET = /\.(?:css|scss|sass|less)$/u;
|
|
421
|
+
var CLIENT_CALLS = /* @__PURE__ */ new Set(["use", "createContext", "createPortal", "flushSync"]);
|
|
422
|
+
var CLIENT_MODULES = /* @__PURE__ */ new Set(["next/dynamic", "client-only"]);
|
|
423
|
+
var CLASS_BASES = /* @__PURE__ */ new Set(["Component", "PureComponent"]);
|
|
424
|
+
var PURE_CALLS = /* @__PURE__ */ new Set(["cva", "tv"]);
|
|
425
|
+
var INERT_TYPES = /* @__PURE__ */ new Set([
|
|
426
|
+
AST_NODE_TYPES12.Literal,
|
|
427
|
+
AST_NODE_TYPES12.TemplateLiteral,
|
|
428
|
+
AST_NODE_TYPES12.TemplateElement,
|
|
429
|
+
AST_NODE_TYPES12.Identifier,
|
|
430
|
+
AST_NODE_TYPES12.UnaryExpression,
|
|
431
|
+
AST_NODE_TYPES12.BinaryExpression,
|
|
432
|
+
AST_NODE_TYPES12.LogicalExpression,
|
|
433
|
+
AST_NODE_TYPES12.ConditionalExpression,
|
|
434
|
+
AST_NODE_TYPES12.ArrayExpression,
|
|
435
|
+
AST_NODE_TYPES12.ObjectExpression,
|
|
436
|
+
AST_NODE_TYPES12.Property,
|
|
437
|
+
AST_NODE_TYPES12.SpreadElement,
|
|
438
|
+
AST_NODE_TYPES12.RestElement,
|
|
439
|
+
AST_NODE_TYPES12.ObjectPattern,
|
|
440
|
+
AST_NODE_TYPES12.ArrayPattern,
|
|
441
|
+
AST_NODE_TYPES12.AssignmentPattern,
|
|
442
|
+
AST_NODE_TYPES12.JSXElement,
|
|
443
|
+
AST_NODE_TYPES12.JSXFragment,
|
|
444
|
+
AST_NODE_TYPES12.JSXOpeningElement,
|
|
445
|
+
AST_NODE_TYPES12.JSXClosingElement,
|
|
446
|
+
AST_NODE_TYPES12.JSXOpeningFragment,
|
|
447
|
+
AST_NODE_TYPES12.JSXClosingFragment,
|
|
448
|
+
AST_NODE_TYPES12.JSXAttribute,
|
|
449
|
+
AST_NODE_TYPES12.JSXSpreadAttribute,
|
|
450
|
+
AST_NODE_TYPES12.JSXExpressionContainer,
|
|
451
|
+
AST_NODE_TYPES12.JSXEmptyExpression,
|
|
452
|
+
AST_NODE_TYPES12.JSXText,
|
|
453
|
+
AST_NODE_TYPES12.JSXIdentifier,
|
|
454
|
+
AST_NODE_TYPES12.JSXNamespacedName,
|
|
455
|
+
AST_NODE_TYPES12.TSAsExpression,
|
|
456
|
+
AST_NODE_TYPES12.TSSatisfiesExpression,
|
|
457
|
+
AST_NODE_TYPES12.TSNonNullExpression
|
|
458
|
+
]);
|
|
459
|
+
var TYPE_DECLARATIONS = /* @__PURE__ */ new Set([
|
|
460
|
+
AST_NODE_TYPES12.TSInterfaceDeclaration,
|
|
461
|
+
AST_NODE_TYPES12.TSTypeAliasDeclaration,
|
|
462
|
+
AST_NODE_TYPES12.TSDeclareFunction
|
|
463
|
+
]);
|
|
464
|
+
var BROWSER_GLOBALS = /* @__PURE__ */ new Set([
|
|
465
|
+
...Object.keys(globals.browser).filter(
|
|
466
|
+
(name) => !Object.hasOwn(globals.node, name) && !Object.hasOwn(globals.builtin, name)
|
|
467
|
+
),
|
|
468
|
+
"navigator",
|
|
469
|
+
"localStorage",
|
|
470
|
+
"sessionStorage"
|
|
471
|
+
]);
|
|
472
|
+
var isValueReference = (reference) => reference.isValueReference !== false;
|
|
473
|
+
var verdicts = /* @__PURE__ */ new WeakMap();
|
|
474
|
+
var analyze = (sourceCode) => {
|
|
475
|
+
const { classify: classify2, classifyTag, positionOf, variableOf } = createClassifier(sourceCode, false);
|
|
476
|
+
const isData = (node) => classify2(node, "prop").data;
|
|
477
|
+
const isComponentBinding = (identifier) => {
|
|
478
|
+
const variable = variableOf(identifier, identifier.name);
|
|
479
|
+
const isNamedLikeComponent = isComponentName(variable?.name);
|
|
480
|
+
return everyDef(
|
|
481
|
+
variable,
|
|
482
|
+
(def) => def.type === DefinitionType4.Type || isNamedLikeComponent && (def.type === DefinitionType4.FunctionName || def.type === DefinitionType4.Variable && isComponentInit(def.node.init))
|
|
483
|
+
);
|
|
484
|
+
};
|
|
485
|
+
const isLocalRead = (node) => {
|
|
486
|
+
let root = node;
|
|
487
|
+
while (root.type === AST_NODE_TYPES12.MemberExpression) {
|
|
488
|
+
if (root.computed && !isInert(root.property)) return false;
|
|
489
|
+
root = root.object;
|
|
490
|
+
}
|
|
491
|
+
const variable = root.type === AST_NODE_TYPES12.Identifier ? variableOf(root, root.name) : null;
|
|
492
|
+
return everyDef(variable, (def) => def.type === DefinitionType4.Variable);
|
|
493
|
+
};
|
|
494
|
+
const isPlainCallee = (callee) => callee.type === AST_NODE_TYPES12.Identifier || callee.type === AST_NODE_TYPES12.MemberExpression && !callee.computed && isPlainCallee(callee.object);
|
|
495
|
+
const isInert = (node) => {
|
|
496
|
+
if (isFunctionNode(node)) return true;
|
|
497
|
+
if (node.type === AST_NODE_TYPES12.UnaryExpression && node.operator === "delete") return false;
|
|
498
|
+
if (node.type === AST_NODE_TYPES12.MemberExpression) return isLocalRead(node);
|
|
499
|
+
if (node.type === AST_NODE_TYPES12.CallExpression)
|
|
500
|
+
return isPlainCallee(node.callee) && (PURE_CALLS.has(calleeName(node.callee)) || isComponentWrapperCall(node)) && node.arguments.every(isInert);
|
|
501
|
+
return INERT_TYPES.has(node.type) && childNodes(node, sourceCode.visitorKeys).every(isInert);
|
|
502
|
+
};
|
|
503
|
+
const exportsOnlyComponents = (declaration) => {
|
|
504
|
+
if (TYPE_DECLARATIONS.has(declaration.type)) return true;
|
|
505
|
+
if (declaration.type === AST_NODE_TYPES12.FunctionDeclaration)
|
|
506
|
+
return isComponentName(declaration.id?.name);
|
|
507
|
+
if (declaration.type !== AST_NODE_TYPES12.VariableDeclaration) return false;
|
|
508
|
+
return declaration.declarations.every(
|
|
509
|
+
(declarator) => declarator.id.type === AST_NODE_TYPES12.Identifier && isComponentName(declarator.id.name) && declarator.init !== null && isComponentInit(declarator.init) && isInert(declarator.init)
|
|
510
|
+
);
|
|
511
|
+
};
|
|
512
|
+
const isServerSafeStatement = (statement) => {
|
|
513
|
+
switch (statement.type) {
|
|
514
|
+
case AST_NODE_TYPES12.ExpressionStatement:
|
|
515
|
+
return statement.directive !== void 0;
|
|
516
|
+
case AST_NODE_TYPES12.ImportDeclaration:
|
|
517
|
+
if (statement.importKind === "type") return true;
|
|
518
|
+
if (statement.specifiers.length === 0) return STYLESHEET.test(statement.source.value);
|
|
519
|
+
return !CLIENT_MODULES.has(statement.source.value);
|
|
520
|
+
case AST_NODE_TYPES12.FunctionDeclaration:
|
|
521
|
+
return true;
|
|
522
|
+
case AST_NODE_TYPES12.TSEnumDeclaration:
|
|
523
|
+
return statement.body.members.every(
|
|
524
|
+
(member) => !member.initializer || isInert(member.initializer)
|
|
525
|
+
);
|
|
526
|
+
case AST_NODE_TYPES12.VariableDeclaration:
|
|
527
|
+
return statement.declarations.every(
|
|
528
|
+
(declarator) => isInert(declarator.id) && (!declarator.init || isInert(declarator.init))
|
|
529
|
+
);
|
|
530
|
+
case AST_NODE_TYPES12.ExportAllDeclaration:
|
|
531
|
+
return statement.exportKind === "type";
|
|
532
|
+
case AST_NODE_TYPES12.ExportNamedDeclaration: {
|
|
533
|
+
if (statement.exportKind === "type") return true;
|
|
534
|
+
const isTypeOnly = statement.specifiers.length > 0 && statement.specifiers.every((specifier) => specifier.exportKind === "type");
|
|
535
|
+
if (statement.source) return isTypeOnly;
|
|
536
|
+
if (statement.declaration) return exportsOnlyComponents(statement.declaration);
|
|
537
|
+
return statement.specifiers.every(
|
|
538
|
+
(specifier) => specifier.exportKind === "type" || specifier.local.type === AST_NODE_TYPES12.Identifier && isComponentBinding(specifier.local)
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
case AST_NODE_TYPES12.ExportDefaultDeclaration: {
|
|
542
|
+
const { declaration } = statement;
|
|
543
|
+
if (declaration.type === AST_NODE_TYPES12.FunctionDeclaration)
|
|
544
|
+
return isComponentName(declaration.id?.name);
|
|
545
|
+
if (declaration.type === AST_NODE_TYPES12.Identifier) return isComponentBinding(declaration);
|
|
546
|
+
return isComponentWrapperCall(declaration) && isComponentInit(declaration) && isInert(declaration);
|
|
547
|
+
}
|
|
548
|
+
default:
|
|
549
|
+
return TYPE_DECLARATIONS.has(statement.type);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
const callNames = (callee) => {
|
|
553
|
+
if (callee.type !== AST_NODE_TYPES12.Identifier) return [calleeName(callee)];
|
|
554
|
+
return [callee.name, importedName(variableOf(callee, callee.name))];
|
|
555
|
+
};
|
|
556
|
+
const needsNode = (node) => {
|
|
557
|
+
switch (node.type) {
|
|
558
|
+
case AST_NODE_TYPES12.CallExpression:
|
|
559
|
+
return callNames(node.callee).some((name) => HOOK.test(name) || CLIENT_CALLS.has(name));
|
|
560
|
+
case AST_NODE_TYPES12.ClassDeclaration:
|
|
561
|
+
case AST_NODE_TYPES12.ClassExpression:
|
|
562
|
+
return !!node.superClass && CLASS_BASES.has(calleeName(node.superClass));
|
|
563
|
+
case AST_NODE_TYPES12.MemberExpression:
|
|
564
|
+
return node.object.type === AST_NODE_TYPES12.Identifier && node.object.name === "globalThis" && !node.computed && node.property.type === AST_NODE_TYPES12.Identifier && BROWSER_GLOBALS.has(node.property.name) && !variableOf(node.object, "globalThis")?.defs.length;
|
|
565
|
+
case AST_NODE_TYPES12.JSXOpeningElement: {
|
|
566
|
+
if (!classifyTag(node).data) return true;
|
|
567
|
+
const isTag = positionOf(node) === "text";
|
|
568
|
+
return node.attributes.some((attribute) => {
|
|
569
|
+
if (attribute.type === AST_NODE_TYPES12.JSXSpreadAttribute) return !isData(attribute.argument);
|
|
570
|
+
const key = attribute.name.type === AST_NODE_TYPES12.JSXIdentifier ? attribute.name.name : "";
|
|
571
|
+
if (isEventHandler(key)) return true;
|
|
572
|
+
const { value } = attribute;
|
|
573
|
+
if (value?.type !== AST_NODE_TYPES12.JSXExpressionContainer) return false;
|
|
574
|
+
return (isTag ? isFunctionAttribute(key) : key !== "className") && !isData(value.expression);
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
case AST_NODE_TYPES12.JSXExpressionContainer:
|
|
578
|
+
return node.parent.type === AST_NODE_TYPES12.JSXElement && positionOf(node.parent.openingElement) === "prop" && !isData(node.expression);
|
|
579
|
+
default:
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
const walk = (node) => needsNode(node) || childNodes(node, sourceCode.visitorKeys).some(walk);
|
|
584
|
+
if (!sourceCode.ast.body.every(isServerSafeStatement) || walk(sourceCode.ast)) return true;
|
|
585
|
+
const scope = sourceCode.getScope(sourceCode.ast);
|
|
586
|
+
return scope.through.some(
|
|
587
|
+
(reference) => isValueReference(reference) && BROWSER_GLOBALS.has(reference.identifier.name)
|
|
588
|
+
) || scope.variables.some(
|
|
589
|
+
(variable) => variable.defs.length === 0 && BROWSER_GLOBALS.has(variable.name) && variable.references.some(isValueReference)
|
|
590
|
+
);
|
|
591
|
+
};
|
|
592
|
+
var needsClient = (sourceCode) => {
|
|
593
|
+
const cached = verdicts.get(sourceCode.ast);
|
|
594
|
+
if (cached !== void 0) return cached;
|
|
595
|
+
const verdict = analyze(sourceCode);
|
|
596
|
+
verdicts.set(sourceCode.ast, verdict);
|
|
597
|
+
return verdict;
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
// needlessUseClient.ts
|
|
601
|
+
var needlessUseClient = ESLintUtils.RuleCreator.withoutDocs({
|
|
602
|
+
meta: {
|
|
603
|
+
type: "problem",
|
|
604
|
+
docs: {
|
|
605
|
+
description: "Disallow a `'use client'` directive in a module that holds only what a server module could: server-safe module-level statements, component exports, renderable tags and data handed to components."
|
|
606
|
+
},
|
|
607
|
+
schema: [],
|
|
608
|
+
messages: {
|
|
609
|
+
needless: "Nothing in this file needs `'use client'`: no hook call, no event handler, no browser global, no class component, no `next/dynamic` or `client-only`, nothing run at module level, no export but components, no tag a server component could not render, and every value it hands to a component is data a server parent could pass. A file without the directive still runs on the client when a client component imports it, so delete the line and let the importer decide. If a dependency without its own directive needs a boundary here, re-export it from this file, or disable this rule on the line with the reason."
|
|
610
|
+
}
|
|
611
|
+
},
|
|
612
|
+
defaultOptions: [],
|
|
613
|
+
create(context) {
|
|
614
|
+
const { sourceCode } = context;
|
|
615
|
+
const directive = findUseClientDirective(sourceCode.ast);
|
|
616
|
+
if (!directive) return {};
|
|
617
|
+
return {
|
|
618
|
+
Program() {
|
|
619
|
+
if (!needsClient(sourceCode)) context.report({ node: directive, messageId: "needless" });
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
// noComments.ts
|
|
626
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES14, AST_TOKEN_TYPES as AST_TOKEN_TYPES2, ESLintUtils as ESLintUtils2 } from "@typescript-eslint/utils";
|
|
627
|
+
|
|
628
|
+
// commentKinds.ts
|
|
629
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES13, AST_TOKEN_TYPES } from "@typescript-eslint/utils";
|
|
630
|
+
var DIRECTIVE = /^\s*(?:eslint-disable\b|eslint-enable\b|\/\s*<|prettier-ignore|biome-ignore|(?:istanbul|c8|v8)\s+ignore\b|(?:webpack|turbopack)[A-Z]|@vitest-environment\b)/u;
|
|
631
|
+
var ALLOW_MARKER = /\bgitleaks:allow\b/u;
|
|
19
632
|
var BLOCK_DIRECTIVE = /^\s*(?:eslint\s|eslint-env\b|global\s|globals\s|exported\s)/u;
|
|
633
|
+
var PRAGMA = /^\s*(?:@ts-(?:expect-error|ignore|nocheck|check)\b|@jsx(?:Frag|ImportSource|Runtime)?\b|[@#]__[A-Z_]+__|[@#]\s*source(?:Mapping)?URL=|@jest-environment\b|@vite-ignore\b|@refresh\s+reset\b|@license\b|@preserve\b|@format\b|@prettier\b|@internal\s*$|node:coverage\s)/u;
|
|
634
|
+
var TYPED = /^\s*\{/u;
|
|
635
|
+
var NAME = /^[\w$]+$/u;
|
|
636
|
+
var IMPORT_CLAUSE = /^\s*(?:\{[^}]*\}|\*\s*as\s+[\w$]+|[\w$]+)\s+from\s+['"]/u;
|
|
637
|
+
var TYPED_TAG = /(?:^|\s)@(?:param|returns?)\s*\{/u;
|
|
638
|
+
var firstLine = (rest) => (rest.split(/\r?\n/u)[0] ?? "").trim();
|
|
639
|
+
var typed = (rest) => TYPED.test(rest);
|
|
640
|
+
var named = (rest) => typed(rest) || NAME.test(firstLine(rest));
|
|
641
|
+
var nameList = (rest) => typed(rest) || firstLine(rest).split(",").every((part) => NAME.test(part.trim()));
|
|
642
|
+
var heritage = (rest) => typed(rest) || /^[\w$.]+$/u.test(firstLine(rest).replace(/<.*>$/u, ""));
|
|
643
|
+
var TYPE_TAGS = /* @__PURE__ */ new Map([
|
|
644
|
+
["type", typed],
|
|
645
|
+
["param", typed],
|
|
646
|
+
["returns", typed],
|
|
647
|
+
["return", typed],
|
|
648
|
+
["satisfies", typed],
|
|
649
|
+
["enum", typed],
|
|
650
|
+
["this", typed],
|
|
651
|
+
["typedef", named],
|
|
652
|
+
["callback", named],
|
|
653
|
+
["template", nameList],
|
|
654
|
+
["extends", heritage],
|
|
655
|
+
["augments", heritage],
|
|
656
|
+
["implements", heritage],
|
|
657
|
+
["import", (rest) => IMPORT_CLAUSE.test(rest)],
|
|
658
|
+
["overload", (rest) => TYPED_TAG.test(rest)]
|
|
659
|
+
]);
|
|
20
660
|
var ANNOTATION = /^\s*[@#]/u;
|
|
21
661
|
var BLOCK_ANNOTATION = /^\s*[\w-]+:\S/u;
|
|
22
|
-
var isComment = (token) => token?.type ===
|
|
23
|
-
var isDocShaped = (comment) => comment.type ===
|
|
24
|
-
var isBanner = (comment) => comment.type ===
|
|
662
|
+
var isComment = (token) => token?.type === AST_TOKEN_TYPES.Line || token?.type === AST_TOKEN_TYPES.Block;
|
|
663
|
+
var isDocShaped = (comment) => comment.type === AST_TOKEN_TYPES.Block && comment.value.startsWith("*");
|
|
664
|
+
var isBanner = (comment) => comment.type === AST_TOKEN_TYPES.Block && comment.value.startsWith("!");
|
|
25
665
|
var pragmaText = (comment) => comment.value.replace(/^\*+/u, "");
|
|
26
666
|
var isDirectiveText = (text) => DIRECTIVE.test(text) || ANNOTATION.test(text);
|
|
27
|
-
var isDirective = (comment) => isDirectiveText(pragmaText(comment)) || comment.type ===
|
|
28
|
-
var
|
|
29
|
-
|
|
667
|
+
var isDirective = (comment) => isDirectiveText(pragmaText(comment)) || comment.type === AST_TOKEN_TYPES.Block && (BLOCK_DIRECTIVE.test(comment.value) || !isDocShaped(comment) && BLOCK_ANNOTATION.test(comment.value));
|
|
668
|
+
var isToolDirective = (comment) => {
|
|
669
|
+
const text = pragmaText(comment);
|
|
670
|
+
return DIRECTIVE.test(text) || PRAGMA.test(text) || comment.type === AST_TOKEN_TYPES.Block && BLOCK_DIRECTIVE.test(comment.value);
|
|
671
|
+
};
|
|
672
|
+
var holdsTag = (comment) => /(?:^|\s)@\w/u.test(pragmaText(comment));
|
|
673
|
+
var isTypeAnnotation = (comment) => {
|
|
674
|
+
const text = pragmaText(comment);
|
|
675
|
+
const tag = isDocShaped(comment) ? /(?:^|\s)@(\w+)/u.exec(text) : null;
|
|
676
|
+
const shape = TYPE_TAGS.get(tag?.[1] ?? "");
|
|
677
|
+
return !!tag && !!shape && shape(text.slice(tag.index + tag[0].length));
|
|
678
|
+
};
|
|
679
|
+
var spansLines = (comment) => comment.loc.start.line !== comment.loc.end.line;
|
|
680
|
+
var followedOnLine = (comment, after) => !!after && after.loc.start.line === comment.loc.end.line;
|
|
681
|
+
var createCommentLookup = (sourceCode) => {
|
|
682
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
683
|
+
const nodeAt = (index) => {
|
|
684
|
+
const known = nodes.get(index);
|
|
685
|
+
if (known !== void 0) return known;
|
|
686
|
+
const node = sourceCode.getNodeByRangeIndex(index);
|
|
687
|
+
nodes.set(index, node);
|
|
688
|
+
return node;
|
|
689
|
+
};
|
|
690
|
+
const enclosingNode = (comment) => nodeAt(comment.range[0]);
|
|
691
|
+
const jsxContainer = (comment) => {
|
|
692
|
+
const node = enclosingNode(comment);
|
|
693
|
+
return node?.type === AST_NODE_TYPES13.JSXEmptyExpression ? node.parent : null;
|
|
694
|
+
};
|
|
695
|
+
const sidesOf = (span) => {
|
|
696
|
+
const { lines } = sourceCode;
|
|
697
|
+
return {
|
|
698
|
+
before: (lines[span.start.line - 1] ?? "").slice(0, span.start.column).trim() !== "",
|
|
699
|
+
after: (lines[span.end.line - 1] ?? "").slice(span.end.column).trim() !== ""
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
const sides = (comment) => sidesOf(jsxContainer(comment)?.loc ?? comment.loc);
|
|
703
|
+
const isOwnLine = (comment) => {
|
|
704
|
+
const side = comment.type === AST_TOKEN_TYPES.Line ? sidesOf(comment.loc) : sides(comment);
|
|
705
|
+
return !side.before && !side.after;
|
|
706
|
+
};
|
|
707
|
+
const isAllowMarker = (comment) => {
|
|
708
|
+
if (spansLines(comment) || !ALLOW_MARKER.test(comment.value)) return false;
|
|
709
|
+
const before = sourceCode.getTokenBefore(comment);
|
|
710
|
+
const after = sourceCode.getTokenAfter(comment);
|
|
711
|
+
return !!before && before.loc.end.line === comment.loc.start.line || !!after && after.loc.start.line === comment.loc.end.line;
|
|
712
|
+
};
|
|
713
|
+
return { nodeAt, enclosingNode, jsxContainer, sides, isOwnLine, isAllowMarker };
|
|
714
|
+
};
|
|
715
|
+
|
|
716
|
+
// noComments.ts
|
|
717
|
+
var EXPORTS = /* @__PURE__ */ new Set([
|
|
718
|
+
AST_NODE_TYPES14.ExportNamedDeclaration,
|
|
719
|
+
AST_NODE_TYPES14.ExportDefaultDeclaration,
|
|
720
|
+
AST_NODE_TYPES14.ExportAllDeclaration
|
|
721
|
+
]);
|
|
722
|
+
var DOCUMENTED = /* @__PURE__ */ new Set([
|
|
723
|
+
AST_NODE_TYPES14.ClassDeclaration,
|
|
724
|
+
AST_NODE_TYPES14.FunctionDeclaration,
|
|
725
|
+
AST_NODE_TYPES14.TSDeclareFunction,
|
|
726
|
+
AST_NODE_TYPES14.VariableDeclaration,
|
|
727
|
+
AST_NODE_TYPES14.TSInterfaceDeclaration,
|
|
728
|
+
AST_NODE_TYPES14.TSTypeAliasDeclaration,
|
|
729
|
+
AST_NODE_TYPES14.TSEnumDeclaration,
|
|
730
|
+
AST_NODE_TYPES14.TSModuleDeclaration,
|
|
731
|
+
AST_NODE_TYPES14.PropertyDefinition,
|
|
732
|
+
AST_NODE_TYPES14.MethodDefinition,
|
|
733
|
+
AST_NODE_TYPES14.TSAbstractPropertyDefinition,
|
|
734
|
+
AST_NODE_TYPES14.TSAbstractMethodDefinition,
|
|
735
|
+
AST_NODE_TYPES14.AccessorProperty,
|
|
736
|
+
AST_NODE_TYPES14.TSAbstractAccessorProperty,
|
|
737
|
+
AST_NODE_TYPES14.TSParameterProperty,
|
|
738
|
+
AST_NODE_TYPES14.TSIndexSignature,
|
|
739
|
+
AST_NODE_TYPES14.TSPropertySignature,
|
|
740
|
+
AST_NODE_TYPES14.TSMethodSignature,
|
|
741
|
+
AST_NODE_TYPES14.TSCallSignatureDeclaration,
|
|
742
|
+
AST_NODE_TYPES14.TSConstructSignatureDeclaration,
|
|
743
|
+
AST_NODE_TYPES14.TSEnumMember,
|
|
744
|
+
AST_NODE_TYPES14.Property
|
|
745
|
+
]);
|
|
746
|
+
var BOUNDARIES = /* @__PURE__ */ new Set([
|
|
747
|
+
AST_NODE_TYPES14.Program,
|
|
748
|
+
AST_NODE_TYPES14.BlockStatement,
|
|
749
|
+
AST_NODE_TYPES14.StaticBlock
|
|
750
|
+
]);
|
|
751
|
+
var MODULE_STATEMENTS = /* @__PURE__ */ new Set([
|
|
752
|
+
AST_NODE_TYPES14.ImportDeclaration,
|
|
753
|
+
AST_NODE_TYPES14.ExportNamedDeclaration,
|
|
754
|
+
AST_NODE_TYPES14.ExportDefaultDeclaration,
|
|
755
|
+
AST_NODE_TYPES14.ExportAllDeclaration,
|
|
756
|
+
AST_NODE_TYPES14.TSExportAssignment
|
|
757
|
+
]);
|
|
758
|
+
var MEMBER_OPENERS = /* @__PURE__ */ new Set(["{", ";", ","]);
|
|
759
|
+
var JS_FILE = /\.[cm]?jsx?$/u;
|
|
760
|
+
var DECLARATION_FILE = /\.d\.[cm]?ts$/u;
|
|
761
|
+
var EM_DASH = String.fromCodePoint(8212);
|
|
762
|
+
var identifierName = (node) => node?.type === AST_NODE_TYPES14.Identifier ? node.name : void 0;
|
|
763
|
+
var isModuleExports = (node) => node.type === AST_NODE_TYPES14.MemberExpression && identifierName(node.object) === "module" && identifierName(node.property) === "exports";
|
|
764
|
+
var commonJsExport = (statement) => {
|
|
765
|
+
if (statement.type !== AST_NODE_TYPES14.ExpressionStatement) return null;
|
|
766
|
+
const { expression } = statement;
|
|
767
|
+
if (expression.type !== AST_NODE_TYPES14.AssignmentExpression) return null;
|
|
768
|
+
const { left, right } = expression;
|
|
769
|
+
if (left.type !== AST_NODE_TYPES14.MemberExpression) return null;
|
|
770
|
+
const exported = isModuleExports(left) || identifierName(left.object) === "exports" || isModuleExports(left.object);
|
|
771
|
+
return exported ? right : null;
|
|
772
|
+
};
|
|
773
|
+
var deferredExports = (body) => {
|
|
774
|
+
const names = /* @__PURE__ */ new Set();
|
|
775
|
+
const add = (node) => {
|
|
776
|
+
const name = identifierName(node);
|
|
777
|
+
if (name) names.add(name);
|
|
778
|
+
};
|
|
779
|
+
for (const statement of body) {
|
|
780
|
+
const commonJs = commonJsExport(statement);
|
|
781
|
+
if (commonJs?.type === AST_NODE_TYPES14.ObjectExpression) {
|
|
782
|
+
for (const property of commonJs.properties) {
|
|
783
|
+
if (property.type === AST_NODE_TYPES14.Property) add(property.value);
|
|
784
|
+
}
|
|
785
|
+
} else add(commonJs);
|
|
786
|
+
if (statement.type === AST_NODE_TYPES14.ExportNamedDeclaration && !statement.source) {
|
|
787
|
+
for (const { local } of statement.specifiers) add(local);
|
|
788
|
+
}
|
|
789
|
+
if (statement.type === AST_NODE_TYPES14.ExportDefaultDeclaration) add(statement.declaration);
|
|
790
|
+
if (statement.type === AST_NODE_TYPES14.TSExportAssignment) add(statement.expression);
|
|
791
|
+
}
|
|
792
|
+
return names;
|
|
793
|
+
};
|
|
794
|
+
var declaredIds = (statement) => {
|
|
795
|
+
if (statement.type === AST_NODE_TYPES14.VariableDeclaration) {
|
|
796
|
+
return statement.declarations.map(({ id }) => id);
|
|
797
|
+
}
|
|
798
|
+
return "id" in statement ? [statement.id] : [];
|
|
799
|
+
};
|
|
800
|
+
var boundNames = (node) => {
|
|
801
|
+
if (node?.type === AST_NODE_TYPES14.Identifier) return [node.name];
|
|
802
|
+
if (node?.type === AST_NODE_TYPES14.ObjectPattern) {
|
|
803
|
+
return node.properties.flatMap(
|
|
804
|
+
(property) => boundNames(property.type === AST_NODE_TYPES14.RestElement ? property.argument : property.value)
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
if (node?.type === AST_NODE_TYPES14.ArrayPattern) {
|
|
808
|
+
return node.elements.flatMap((element) => boundNames(element));
|
|
809
|
+
}
|
|
810
|
+
if (node?.type === AST_NODE_TYPES14.AssignmentPattern) return boundNames(node.left);
|
|
811
|
+
if (node?.type === AST_NODE_TYPES14.RestElement) return boundNames(node.argument);
|
|
812
|
+
return [];
|
|
813
|
+
};
|
|
814
|
+
var isDeferred = (statement, deferred) => declaredIds(statement).some((id) => boundNames(id).some((name) => deferred.has(name)));
|
|
815
|
+
var isModuleFile = (program) => program.body.some(
|
|
816
|
+
(statement) => MODULE_STATEMENTS.has(statement.type) || commonJsExport(statement) !== null || statement.type === AST_NODE_TYPES14.TSImportEqualsDeclaration && statement.moduleReference.type === AST_NODE_TYPES14.TSExternalModuleReference
|
|
817
|
+
);
|
|
818
|
+
var isAmbient = (statement) => statement.type === AST_NODE_TYPES14.TSInterfaceDeclaration || statement.type === AST_NODE_TYPES14.TSTypeAliasDeclaration || "declare" in statement && statement.declare === true;
|
|
819
|
+
var ambience = (block) => {
|
|
820
|
+
let declared = false;
|
|
821
|
+
let node = block.parent;
|
|
822
|
+
while (node) {
|
|
823
|
+
if (node.type === AST_NODE_TYPES14.TSModuleDeclaration) {
|
|
824
|
+
if (node.kind === "global" || node.id.type === AST_NODE_TYPES14.Literal) return "public";
|
|
825
|
+
declared ||= node.declare;
|
|
826
|
+
}
|
|
827
|
+
node = node.parent;
|
|
828
|
+
}
|
|
829
|
+
return declared ? "declared" : "local";
|
|
830
|
+
};
|
|
831
|
+
var isBoundary = (node, child, walk) => BOUNDARIES.has(node.type) || node.type === AST_NODE_TYPES14.ArrowFunctionExpression && node.body === child || !walk.throughCalls && (node.type === AST_NODE_TYPES14.CallExpression || node.type === AST_NODE_TYPES14.NewExpression) && node.arguments.some((argument) => argument === child);
|
|
832
|
+
var isPublished = (statement, walk) => {
|
|
833
|
+
const { parent } = statement;
|
|
834
|
+
if (parent?.type !== AST_NODE_TYPES14.TSModuleBlock) return true;
|
|
835
|
+
return ambience(parent) === "public" || reachesExport(parent.parent, walk);
|
|
836
|
+
};
|
|
837
|
+
var reachesExport = (start, walk) => {
|
|
838
|
+
let child = start;
|
|
839
|
+
let node = start.parent;
|
|
840
|
+
while (node) {
|
|
841
|
+
if (EXPORTS.has(node.type)) return isPublished(node, walk);
|
|
842
|
+
if (node.type === AST_NODE_TYPES14.TSModuleBlock) {
|
|
843
|
+
const scope = ambience(node);
|
|
844
|
+
if (scope !== "declared") return scope === "public";
|
|
845
|
+
}
|
|
846
|
+
if (node.type === AST_NODE_TYPES14.Program) return walk.topLevel(child);
|
|
847
|
+
if (isBoundary(node, child, walk)) return false;
|
|
848
|
+
child = node;
|
|
849
|
+
node = node.parent;
|
|
850
|
+
}
|
|
851
|
+
return false;
|
|
852
|
+
};
|
|
853
|
+
var isExportedDoc = (comment, sourceCode, lookup, decorated, walk) => {
|
|
854
|
+
const before = sourceCode.getTokenBefore(comment);
|
|
855
|
+
if (before?.loc.end.line === comment.loc.start.line && !MEMBER_OPENERS.has(before.value)) {
|
|
856
|
+
return false;
|
|
857
|
+
}
|
|
858
|
+
const token = sourceCode.getTokenAfter(comment);
|
|
859
|
+
if (!token) return false;
|
|
860
|
+
const target = decorated.get(token.range[0]);
|
|
861
|
+
if (target?.type === AST_NODE_TYPES14.ClassDeclaration && reachesExport(target, walk)) {
|
|
862
|
+
return true;
|
|
863
|
+
}
|
|
864
|
+
let node = lookup.nodeAt(token.range[0]);
|
|
865
|
+
while (node?.range[0] === token.range[0]) {
|
|
866
|
+
if (EXPORTS.has(node.type)) return isPublished(node, walk);
|
|
867
|
+
if (DOCUMENTED.has(node.type)) return reachesExport(node, walk);
|
|
868
|
+
node = node.parent ?? null;
|
|
869
|
+
}
|
|
870
|
+
return false;
|
|
871
|
+
};
|
|
872
|
+
var isJsxNode = (node) => !!node && node.type.startsWith("JSX") && node.type !== AST_NODE_TYPES14.JSXExpressionContainer;
|
|
873
|
+
var classify = (comment, sourceCode, lookup, decorated, topLevel) => {
|
|
874
|
+
const node = lookup.enclosingNode(comment);
|
|
875
|
+
const inJsx = isJsxNode(node);
|
|
876
|
+
if (isToolDirective(comment) || lookup.isAllowMarker(comment)) {
|
|
877
|
+
return inJsx ? "jsxDirective" : "directive";
|
|
878
|
+
}
|
|
879
|
+
if (isBanner(comment)) return "banner";
|
|
880
|
+
if (inJsx) return node?.type === AST_NODE_TYPES14.JSXEmptyExpression ? "jsx" : "attribute";
|
|
881
|
+
if (isDocShaped(comment)) {
|
|
882
|
+
const reaches = (throughCalls) => isExportedDoc(comment, sourceCode, lookup, decorated, { topLevel, throughCalls });
|
|
883
|
+
if (reaches(false)) return "jsdoc";
|
|
884
|
+
return reaches(true) ? "argumentDoc" : "orphanDoc";
|
|
885
|
+
}
|
|
886
|
+
return comment.type === AST_TOKEN_TYPES2.Line ? "line" : "block";
|
|
887
|
+
};
|
|
888
|
+
var MESSAGES = {
|
|
889
|
+
line: "Comments are not allowed in code. Delete this `//` comment: a reason the code cannot carry belongs in the README. Only tool directives and a JSDoc on an exported symbol stay.",
|
|
890
|
+
block: "Comments are not allowed in code. Delete this block comment: a reason the code cannot carry belongs in the README. Only tool directives and a JSDoc on an exported symbol stay.",
|
|
891
|
+
orphanDoc: "A JSDoc is allowed only directly above an exported symbol, or a member of an exported class, interface, type or enum. Delete this one.",
|
|
892
|
+
argumentDoc: "This JSDoc sits in an argument of an exported call or `new`, so it is published only when the callee returns its argument's type, as `Object.freeze` or a generic identity helper does. The rule cannot see the signature: delete it unless the callee keeps it.",
|
|
893
|
+
jsdoc: "This config allows no JSDoc. Delete it.",
|
|
894
|
+
jsx: "Comments are not allowed in JSX. Delete this `{/* */}` container; only a tool directive stays.",
|
|
895
|
+
attribute: "Comments are not allowed inside a JSX tag. Delete this one.",
|
|
896
|
+
emDash: "This JSDoc holds an em dash. Write a comma, a colon, parentheses or two sentences instead."
|
|
897
|
+
};
|
|
898
|
+
var MESSAGE_IDS = {
|
|
899
|
+
directive: null,
|
|
900
|
+
banner: null,
|
|
901
|
+
jsxDirective: null,
|
|
902
|
+
jsdoc: "jsdoc",
|
|
903
|
+
orphanDoc: "orphanDoc",
|
|
904
|
+
argumentDoc: "argumentDoc",
|
|
905
|
+
jsx: "jsx",
|
|
906
|
+
attribute: "attribute",
|
|
907
|
+
line: "line",
|
|
908
|
+
block: "block"
|
|
909
|
+
};
|
|
910
|
+
var noComments = ESLintUtils2.RuleCreator.withoutDocs({
|
|
911
|
+
meta: {
|
|
912
|
+
type: "suggestion",
|
|
913
|
+
docs: {
|
|
914
|
+
description: "Disallow comments in code, except tool directives and a JSDoc directly above an exported symbol or a member of an exported class, interface, type or enum."
|
|
915
|
+
},
|
|
916
|
+
fixable: "code",
|
|
917
|
+
schema: [
|
|
918
|
+
{
|
|
919
|
+
type: "object",
|
|
920
|
+
properties: { jsdoc: { type: "string", enum: ["exports", "never"] } },
|
|
921
|
+
additionalProperties: false
|
|
922
|
+
}
|
|
923
|
+
],
|
|
924
|
+
messages: MESSAGES
|
|
925
|
+
},
|
|
926
|
+
defaultOptions: [{}],
|
|
927
|
+
create(context, [{ jsdoc }]) {
|
|
928
|
+
const sourceCode = context.sourceCode;
|
|
929
|
+
const { lines, text } = sourceCode;
|
|
930
|
+
const lookup = createCommentLookup(sourceCode);
|
|
931
|
+
const decorated = /* @__PURE__ */ new Map();
|
|
932
|
+
const program = sourceCode.ast;
|
|
933
|
+
const deferred = deferredExports(program.body);
|
|
934
|
+
const globalScope = !isModuleFile(program);
|
|
935
|
+
const declarationFile = DECLARATION_FILE.test(context.filename);
|
|
936
|
+
const topLevel = (statement) => isDeferred(statement, deferred) || globalScope && (declarationFile || isAmbient(statement));
|
|
937
|
+
const typedJs = JS_FILE.test(context.filename);
|
|
938
|
+
const lineStart = (line) => sourceCode.getIndexFromLoc({ line, column: 0 });
|
|
939
|
+
const lineEnd = (line) => lineStart(line) + (lines[line - 1]?.length ?? 0);
|
|
940
|
+
const wholeLines = (first, last) => {
|
|
941
|
+
if (last < lines.length) return [lineStart(first), lineStart(last + 1)];
|
|
942
|
+
if (first > 1) return [lineEnd(first - 1), text.length];
|
|
943
|
+
return [0, text.length];
|
|
944
|
+
};
|
|
945
|
+
const removal = (comment, kind) => {
|
|
946
|
+
if (kind === "attribute" || kind === "argumentDoc" || (kind === "orphanDoc" || kind === "jsdoc") && holdsTag(comment)) {
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
const span = lookup.jsxContainer(comment) ?? comment;
|
|
950
|
+
const side = lookup.sides(comment);
|
|
951
|
+
const { range, loc } = span;
|
|
952
|
+
const { before, after } = side;
|
|
953
|
+
if (!before && !after) {
|
|
954
|
+
const bounds = [loc.start.line, loc.end.line];
|
|
955
|
+
return { range: wholeLines(...bounds), text: "", lines: bounds };
|
|
956
|
+
}
|
|
957
|
+
if (kind === "jsx") return null;
|
|
958
|
+
const previousEnd = sourceCode.getTokenBefore(comment, { includeComments: true })?.range[1];
|
|
959
|
+
const nextStart = sourceCode.getTokenAfter(comment, { includeComments: true })?.range[0];
|
|
960
|
+
if (before && after) {
|
|
961
|
+
if (spansLines(comment) || previousEnd === void 0 || nextStart === void 0) return null;
|
|
962
|
+
return { range: [previousEnd, nextStart], text: " ", lines: null };
|
|
963
|
+
}
|
|
964
|
+
if (before) {
|
|
965
|
+
return previousEnd === void 0 ? null : { range: [previousEnd, range[1]], text: "", lines: null };
|
|
966
|
+
}
|
|
967
|
+
return nextStart === void 0 ? null : { range: [range[0], nextStart], text: "", lines: null };
|
|
968
|
+
};
|
|
969
|
+
return {
|
|
970
|
+
Decorator(decorator) {
|
|
971
|
+
const { parent } = decorator;
|
|
972
|
+
if ("decorators" in parent && parent.decorators[0] === decorator) {
|
|
973
|
+
decorated.set(decorator.range[0], parent);
|
|
974
|
+
}
|
|
975
|
+
},
|
|
976
|
+
"Program:exit"() {
|
|
977
|
+
const reports = [];
|
|
978
|
+
for (const comment of sourceCode.getAllComments().filter(isComment)) {
|
|
979
|
+
const kind = typedJs && isTypeAnnotation(comment) ? "directive" : classify(comment, sourceCode, lookup, decorated, topLevel);
|
|
980
|
+
if (kind === "jsdoc" && jsdoc !== "never") {
|
|
981
|
+
if (comment.value.includes(EM_DASH))
|
|
982
|
+
reports.push({ comment, messageId: "emDash", fix: null });
|
|
983
|
+
continue;
|
|
984
|
+
}
|
|
985
|
+
const messageId = MESSAGE_IDS[kind];
|
|
986
|
+
if (messageId) reports.push({ comment, messageId, fix: removal(comment, kind) });
|
|
987
|
+
}
|
|
988
|
+
const ownLine = reports.map(({ fix }) => fix).filter((fix) => !!fix?.lines).sort((a, b) => a.lines[0] - b.lines[0]);
|
|
989
|
+
let run = [];
|
|
990
|
+
const flush = () => {
|
|
991
|
+
const first = run[0];
|
|
992
|
+
const last = run[run.length - 1];
|
|
993
|
+
if (first && last) {
|
|
994
|
+
const range = wholeLines(first.lines[0], last.lines[1]);
|
|
995
|
+
for (const fix of run) fix.range = range;
|
|
996
|
+
}
|
|
997
|
+
run = [];
|
|
998
|
+
};
|
|
999
|
+
for (const fix of ownLine) {
|
|
1000
|
+
const previous = run[run.length - 1];
|
|
1001
|
+
if (previous && previous.lines[1] + 1 !== fix.lines[0]) flush();
|
|
1002
|
+
run.push(fix);
|
|
1003
|
+
}
|
|
1004
|
+
flush();
|
|
1005
|
+
for (const { comment, messageId, fix } of reports) {
|
|
1006
|
+
context.report({
|
|
1007
|
+
loc: comment.loc,
|
|
1008
|
+
messageId,
|
|
1009
|
+
fix: fix ? (fixer) => fixer.replaceTextRange(fix.range, fix.text) : null
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
1016
|
+
|
|
1017
|
+
// oneExportPerFile.ts
|
|
1018
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES15, ESLintUtils as ESLintUtils3 } from "@typescript-eslint/utils";
|
|
1019
|
+
var isTypeOnlyDeclaration = (declaration) => declaration?.type === AST_NODE_TYPES15.TSInterfaceDeclaration || declaration?.type === AST_NODE_TYPES15.TSTypeAliasDeclaration || declaration?.type === AST_NODE_TYPES15.TSDeclareFunction;
|
|
1020
|
+
var declaratorEntries = (declaration) => declaration.declarations.map((declarator) => ({
|
|
1021
|
+
node: declarator,
|
|
1022
|
+
name: declarator.id.type === AST_NODE_TYPES15.Identifier ? declarator.id.name : "a destructured export"
|
|
1023
|
+
}));
|
|
1024
|
+
var declarationEntry = (declaration) => ({
|
|
1025
|
+
node: declaration,
|
|
1026
|
+
name: "id" in declaration && declaration.id?.type === AST_NODE_TYPES15.Identifier ? declaration.id.name : "default"
|
|
1027
|
+
});
|
|
1028
|
+
var namedEntries = (node) => {
|
|
1029
|
+
if (node.exportKind === "type") return [];
|
|
1030
|
+
const { declaration, specifiers } = node;
|
|
1031
|
+
if (declaration) {
|
|
1032
|
+
if (isTypeOnlyDeclaration(declaration)) return [];
|
|
1033
|
+
if (declaration.type === AST_NODE_TYPES15.VariableDeclaration) return declaratorEntries(declaration);
|
|
1034
|
+
return [declarationEntry(declaration)];
|
|
1035
|
+
}
|
|
1036
|
+
return specifiers.filter((specifier) => specifier.exportKind !== "type").map((specifier) => ({
|
|
1037
|
+
node: specifier,
|
|
1038
|
+
name: specifier.exported.type === AST_NODE_TYPES15.Identifier ? specifier.exported.name : specifier.exported.value
|
|
1039
|
+
}));
|
|
1040
|
+
};
|
|
1041
|
+
var exportEntries = (statement) => {
|
|
1042
|
+
if (statement.type === AST_NODE_TYPES15.ExportNamedDeclaration) return namedEntries(statement);
|
|
1043
|
+
if (statement.type === AST_NODE_TYPES15.ExportDefaultDeclaration)
|
|
1044
|
+
return statement.declaration.type === AST_NODE_TYPES15.TSDeclareFunction ? [] : [{ node: statement, name: "default" }];
|
|
1045
|
+
return [];
|
|
1046
|
+
};
|
|
1047
|
+
var oneExportPerFile = ESLintUtils3.RuleCreator.withoutDocs({
|
|
1048
|
+
meta: {
|
|
1049
|
+
type: "suggestion",
|
|
1050
|
+
docs: {
|
|
1051
|
+
description: "Disallow more than one value export per module. A type export (an interface, a type alias, or a type-only named export) is free of the count."
|
|
1052
|
+
},
|
|
1053
|
+
schema: [],
|
|
1054
|
+
messages: {
|
|
1055
|
+
multiple: "This module already exports `{{first}}`; give `{{name}}` its own module. A type export is free of this rule."
|
|
1056
|
+
}
|
|
1057
|
+
},
|
|
1058
|
+
defaultOptions: [],
|
|
1059
|
+
create(context) {
|
|
1060
|
+
return {
|
|
1061
|
+
Program(program) {
|
|
1062
|
+
const [first, ...rest] = program.body.flatMap(exportEntries);
|
|
1063
|
+
if (!first || rest.length === 0) return;
|
|
1064
|
+
for (const entry of rest)
|
|
1065
|
+
context.report({
|
|
1066
|
+
node: entry.node,
|
|
1067
|
+
messageId: "multiple",
|
|
1068
|
+
data: { first: first.name, name: entry.name }
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
// oneLineComments.ts
|
|
1076
|
+
import { AST_TOKEN_TYPES as AST_TOKEN_TYPES3, ESLintUtils as ESLintUtils4 } from "@typescript-eslint/utils";
|
|
1077
|
+
var isBare = (comment) => comment.type === AST_TOKEN_TYPES3.Line && comment.value.trim() === "";
|
|
30
1078
|
var collapse = (text) => text.replace(/\s+/gu, " ").trim();
|
|
31
1079
|
var asLine = (body) => body ? `// ${body}` : null;
|
|
32
|
-
var followedOnLine = (comment, after) => !!after?.loc && !!comment.loc && after.loc.start.line === comment.loc.end.line;
|
|
33
1080
|
var blockLines = (comment) => comment.value.replace(/^!/u, "").split(/\r\n|[\r\n\u2028\u2029]/u).map(
|
|
34
1081
|
(line) => line.trim().replace(/^\*(?= |$)/u, "").trim()
|
|
35
1082
|
);
|
|
@@ -60,10 +1107,9 @@ var collapsedBlock = (comment, lines) => {
|
|
|
60
1107
|
};
|
|
61
1108
|
var isJsDoc = (comment, after) => {
|
|
62
1109
|
if (!isComment(after)) return true;
|
|
63
|
-
|
|
64
|
-
return isDirective(next) || isDocShaped(next) && /^\*+\s*@/u.test(comment.value);
|
|
1110
|
+
return isDirective(after) || isDocShaped(after) && /^\*+\s*@/u.test(comment.value);
|
|
65
1111
|
};
|
|
66
|
-
var oneLineComments = {
|
|
1112
|
+
var oneLineComments = ESLintUtils4.RuleCreator.withoutDocs({
|
|
67
1113
|
meta: {
|
|
68
1114
|
type: "layout",
|
|
69
1115
|
docs: {
|
|
@@ -79,34 +1125,16 @@ var oneLineComments = {
|
|
|
79
1125
|
orphanDoc: "`/**` is JSDoc, and JSDoc sits directly above the code it documents. Move it there, join it with the doc under it, or write it as `//`."
|
|
80
1126
|
}
|
|
81
1127
|
},
|
|
1128
|
+
defaultOptions: [],
|
|
82
1129
|
create(context) {
|
|
83
1130
|
const sourceCode = context.sourceCode;
|
|
84
1131
|
const comments = sourceCode.getAllComments().filter(isComment);
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const known = enclosing.get(comment);
|
|
88
|
-
if (known !== void 0) return known;
|
|
89
|
-
const node = sourceCode.getNodeByRangeIndex(comment.range?.[0] ?? 0);
|
|
90
|
-
enclosing.set(comment, node);
|
|
91
|
-
return node;
|
|
92
|
-
};
|
|
93
|
-
const insideJsx = (comment) => enclosingNode(comment)?.type?.startsWith("JSX") ?? false;
|
|
94
|
-
const jsxContainer = (comment) => {
|
|
95
|
-
const node = comment.type === "Block" ? enclosingNode(comment) : null;
|
|
96
|
-
return node?.type === "JSXEmptyExpression" ? node.parent ?? null : null;
|
|
97
|
-
};
|
|
98
|
-
const isOwnLine = (comment) => {
|
|
99
|
-
const span = jsxContainer(comment)?.loc ?? comment.loc;
|
|
100
|
-
if (!span) return false;
|
|
101
|
-
const lines = sourceCode.getLines();
|
|
102
|
-
const before = (lines[span.start.line - 1] ?? "").slice(0, span.start.column);
|
|
103
|
-
const after = (lines[span.end.line - 1] ?? "").slice(span.end.column);
|
|
104
|
-
return before.trim() === "" && after.trim() === "";
|
|
105
|
-
};
|
|
1132
|
+
const { enclosingNode, isOwnLine, isAllowMarker } = createCommentLookup(sourceCode);
|
|
1133
|
+
const insideJsx = (comment) => enclosingNode(comment)?.type.startsWith("JSX") ?? false;
|
|
106
1134
|
const breaksSemicolonInsertion = (comment, after) => {
|
|
107
1135
|
if (insideJsx(comment)) return false;
|
|
108
1136
|
const before = sourceCode.getTokenBefore(comment, { includeComments: true });
|
|
109
|
-
return !!before
|
|
1137
|
+
return !!before && before.loc.end.line === comment.loc.start.line && followedOnLine(comment, after);
|
|
110
1138
|
};
|
|
111
1139
|
const blockVerdict = (comment, after) => {
|
|
112
1140
|
const lines = blockLines(comment);
|
|
@@ -124,7 +1152,9 @@ var oneLineComments = {
|
|
|
124
1152
|
"Program:exit"() {
|
|
125
1153
|
const docs = /* @__PURE__ */ new Set();
|
|
126
1154
|
for (const comment of comments) {
|
|
127
|
-
if (comment.type !==
|
|
1155
|
+
if (comment.type !== AST_TOKEN_TYPES3.Block || isDirective(comment) || isAllowMarker(comment)) {
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
128
1158
|
const after = sourceCode.getTokenAfter(comment, { includeComments: true });
|
|
129
1159
|
if (spansLines(comment)) {
|
|
130
1160
|
const { messageId: messageId2, text: text2 } = blockVerdict(comment, after);
|
|
@@ -158,20 +1188,20 @@ var oneLineComments = {
|
|
|
158
1188
|
if (current.length < 2 || current.some(isDirective)) return;
|
|
159
1189
|
const first = current[0];
|
|
160
1190
|
const last = current[current.length - 1];
|
|
161
|
-
if (!first
|
|
162
|
-
const block = current.some((comment) => comment.type ===
|
|
1191
|
+
if (!first || !last) return;
|
|
1192
|
+
const block = current.some((comment) => comment.type === AST_TOKEN_TYPES3.Block);
|
|
163
1193
|
const texts = current.map((comment) => isBare(comment) ? "" : comment.value.trim() || " ");
|
|
164
1194
|
const paragraphs = proseParagraphs(texts, false) > 1;
|
|
165
1195
|
const text = asLine(collapse(texts.join(" ")));
|
|
166
1196
|
context.report({
|
|
167
1197
|
loc: { start: first.loc.start, end: last.loc.end },
|
|
168
1198
|
messageId: paragraphs ? "paragraphs" : "adjacent",
|
|
169
|
-
fix: paragraphs || block || !text ? null : (fixer) => fixer.replaceTextRange([first.range
|
|
1199
|
+
fix: paragraphs || block || !text ? null : (fixer) => fixer.replaceTextRange([first.range[0], last.range[1]], text)
|
|
170
1200
|
});
|
|
171
1201
|
};
|
|
172
1202
|
for (const comment of joinable) {
|
|
173
1203
|
const previous = run[run.length - 1];
|
|
174
|
-
const touching = previous &&
|
|
1204
|
+
const touching = previous && previous.loc.end.line + 1 === comment.loc.start.line;
|
|
175
1205
|
if (!touching) flush();
|
|
176
1206
|
run.push(comment);
|
|
177
1207
|
}
|
|
@@ -179,12 +1209,142 @@ var oneLineComments = {
|
|
|
179
1209
|
}
|
|
180
1210
|
};
|
|
181
1211
|
}
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
// staticJsxInClient.ts
|
|
1215
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES16, AST_TOKEN_TYPES as AST_TOKEN_TYPES4, ESLintUtils as ESLintUtils5 } from "@typescript-eslint/utils";
|
|
1216
|
+
var DISABLE_KEYWORDS = ["eslint-disable-next-line", "eslint-disable-line", "eslint-disable"];
|
|
1217
|
+
var isJsx = (node) => node.type === AST_NODE_TYPES16.JSXElement || node.type === AST_NODE_TYPES16.JSXFragment;
|
|
1218
|
+
var isRenderedByComponent = (node) => {
|
|
1219
|
+
let current = node.parent;
|
|
1220
|
+
while (current && !isFunctionNode(current)) current = current.parent;
|
|
1221
|
+
return !current || isComponentFunction(current);
|
|
182
1222
|
};
|
|
183
|
-
var
|
|
184
|
-
|
|
1223
|
+
var staticJsxInClient = ESLintUtils5.RuleCreator.withoutDocs({
|
|
1224
|
+
meta: {
|
|
1225
|
+
type: "suggestion",
|
|
1226
|
+
docs: {
|
|
1227
|
+
description: "Disallow a subtree of static JSX inside a client module, where it ships to the browser and hydrates for nothing."
|
|
1228
|
+
},
|
|
1229
|
+
schema: [
|
|
1230
|
+
{
|
|
1231
|
+
type: "object",
|
|
1232
|
+
properties: { minElements: { type: "integer", minimum: 1 } },
|
|
1233
|
+
additionalProperties: false
|
|
1234
|
+
}
|
|
1235
|
+
],
|
|
1236
|
+
messages: {
|
|
1237
|
+
static: "Static markup in a client file: {{count}} elements that read only literals, imports and module constants still ship to the browser and hydrate. Render them in the server parent and pass them in as `children` or a named ReactNode prop. Moving them to a file without the directive does not help while this file imports it."
|
|
1238
|
+
}
|
|
1239
|
+
},
|
|
1240
|
+
defaultOptions: [{ minElements: 3 }],
|
|
1241
|
+
create(context, [{ minElements }]) {
|
|
1242
|
+
const { sourceCode } = context;
|
|
1243
|
+
const directive = findUseClientDirective(sourceCode.ast);
|
|
1244
|
+
if (!directive) return {};
|
|
1245
|
+
const isDirectiveKept = () => sourceCode.getAllComments().some((comment) => {
|
|
1246
|
+
const text = comment.value.trim();
|
|
1247
|
+
const keyword = DISABLE_KEYWORDS.find(
|
|
1248
|
+
(candidate) => text === candidate || text.startsWith(`${candidate} `)
|
|
1249
|
+
);
|
|
1250
|
+
if (!keyword) return false;
|
|
1251
|
+
const list = text.slice(keyword.length);
|
|
1252
|
+
const rules = list.split("--")[0]?.split(/[\s,]+/u).filter(Boolean) ?? [];
|
|
1253
|
+
const covers = rules.length === 0 || rules.some((rule) => rule.endsWith("no-needless-use-client"));
|
|
1254
|
+
const line = directive.loc.start.line;
|
|
1255
|
+
if (keyword === "eslint-disable-line") return covers && comment.loc.start.line === line;
|
|
1256
|
+
if (keyword === "eslint-disable-next-line") return covers && comment.loc.end.line === line - 1;
|
|
1257
|
+
return covers && comment.type === AST_TOKEN_TYPES4.Block && comment.range[1] <= directive.range[0];
|
|
1258
|
+
});
|
|
1259
|
+
if (!needsClient(sourceCode) && !isDirectiveKept()) return {};
|
|
1260
|
+
const { classify: classify2, classifyTag, positionOf } = createClassifier(sourceCode, true);
|
|
1261
|
+
const isStatic = (node, position) => {
|
|
1262
|
+
const verdict = classify2(node, position);
|
|
1263
|
+
return verdict.data && verdict.stable;
|
|
1264
|
+
};
|
|
1265
|
+
const isStaticAttribute = (attribute, position) => {
|
|
1266
|
+
if (attribute.type !== AST_NODE_TYPES16.JSXAttribute) return false;
|
|
1267
|
+
const key = attribute.name.type === AST_NODE_TYPES16.JSXIdentifier ? attribute.name.name : "";
|
|
1268
|
+
if (isFunctionAttribute(key)) return false;
|
|
1269
|
+
const { value } = attribute;
|
|
1270
|
+
if (!value || value.type === AST_NODE_TYPES16.Literal) return true;
|
|
1271
|
+
return value.type === AST_NODE_TYPES16.JSXExpressionContainer && isStatic(value.expression, position);
|
|
1272
|
+
};
|
|
1273
|
+
const childPosition = (node) => node.type === AST_NODE_TYPES16.JSXElement ? positionOf(node.openingElement) : "text";
|
|
1274
|
+
const verdicts2 = /* @__PURE__ */ new Map();
|
|
1275
|
+
const judge = (node) => {
|
|
1276
|
+
const cached = verdicts2.get(node);
|
|
1277
|
+
if (cached) return cached;
|
|
1278
|
+
const position = childPosition(node);
|
|
1279
|
+
let isStaticNode = true;
|
|
1280
|
+
let count = 0;
|
|
1281
|
+
if (node.type === AST_NODE_TYPES16.JSXElement) {
|
|
1282
|
+
const { openingElement } = node;
|
|
1283
|
+
const tag = classifyTag(openingElement);
|
|
1284
|
+
isStaticNode = tag.data && tag.stable && openingElement.attributes.every((attribute) => isStaticAttribute(attribute, position));
|
|
1285
|
+
count = 1;
|
|
1286
|
+
}
|
|
1287
|
+
for (const child of node.children) {
|
|
1288
|
+
if (isJsx(child)) {
|
|
1289
|
+
const verdict2 = judge(child);
|
|
1290
|
+
isStaticNode &&= verdict2.isStatic;
|
|
1291
|
+
count += verdict2.count;
|
|
1292
|
+
} else if (child.type === AST_NODE_TYPES16.JSXExpressionContainer)
|
|
1293
|
+
isStaticNode &&= isStatic(child.expression, position);
|
|
1294
|
+
else if (child.type !== AST_NODE_TYPES16.JSXText) isStaticNode = false;
|
|
1295
|
+
}
|
|
1296
|
+
const verdict = { isStatic: isStaticNode, count };
|
|
1297
|
+
verdicts2.set(node, verdict);
|
|
1298
|
+
return verdict;
|
|
1299
|
+
};
|
|
1300
|
+
const report = (loc, count) => context.report({ loc, messageId: "static", data: { count: String(count) } });
|
|
1301
|
+
const visit = (node) => {
|
|
1302
|
+
const { isStatic: isStaticNode, count } = judge(node);
|
|
1303
|
+
if (isStaticNode) {
|
|
1304
|
+
if (count >= minElements) report(node.loc, count);
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
const position = childPosition(node);
|
|
1308
|
+
let run = [];
|
|
1309
|
+
const flush = () => {
|
|
1310
|
+
const [first] = run;
|
|
1311
|
+
const last = run.at(-1);
|
|
1312
|
+
const total = run.reduce((sum, member) => sum + judge(member).count, 0);
|
|
1313
|
+
if (first && last && run.length > 1 && total >= minElements)
|
|
1314
|
+
report({ start: first.loc.start, end: last.loc.end }, total);
|
|
1315
|
+
else for (const member of run) visit(member);
|
|
1316
|
+
run = [];
|
|
1317
|
+
};
|
|
1318
|
+
for (const child of node.children) {
|
|
1319
|
+
if (isJsx(child) && judge(child).isStatic) run.push(child);
|
|
1320
|
+
else if (isJsx(child)) {
|
|
1321
|
+
flush();
|
|
1322
|
+
visit(child);
|
|
1323
|
+
} else if (child.type === AST_NODE_TYPES16.JSXExpressionContainer && !isStatic(child.expression, position))
|
|
1324
|
+
flush();
|
|
1325
|
+
else if (child.type === AST_NODE_TYPES16.JSXSpreadChild) flush();
|
|
1326
|
+
}
|
|
1327
|
+
flush();
|
|
1328
|
+
};
|
|
1329
|
+
const visitRoot = (node) => {
|
|
1330
|
+
if (!isJsx(node.parent) && isRenderedByComponent(node)) visit(node);
|
|
1331
|
+
};
|
|
1332
|
+
return { JSXElement: visitRoot, JSXFragment: visitRoot };
|
|
1333
|
+
}
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
// plugin.ts
|
|
1337
|
+
var plugin = {
|
|
185
1338
|
meta: { name: "@soujvnunes/eslint-config" },
|
|
186
|
-
rules: {
|
|
1339
|
+
rules: {
|
|
1340
|
+
"one-line-comments": oneLineComments,
|
|
1341
|
+
"no-comments": noComments,
|
|
1342
|
+
"no-needless-use-client": needlessUseClient,
|
|
1343
|
+
"no-static-jsx-in-client": staticJsxInClient,
|
|
1344
|
+
"one-export-per-file": oneExportPerFile
|
|
1345
|
+
}
|
|
187
1346
|
};
|
|
1347
|
+
var soujvnunesPlugin = plugin;
|
|
188
1348
|
|
|
189
1349
|
// index.ts
|
|
190
1350
|
var DEFAULT_IGNORES = [
|
|
@@ -205,6 +1365,7 @@ var DEFAULT_IMPORT_GROUPS = [
|
|
|
205
1365
|
"sibling",
|
|
206
1366
|
"index"
|
|
207
1367
|
];
|
|
1368
|
+
var MAX_LINES = 300;
|
|
208
1369
|
var typescriptRules = {
|
|
209
1370
|
"@typescript-eslint/no-unused-vars": [
|
|
210
1371
|
"error",
|
|
@@ -229,7 +1390,6 @@ var typescriptRules = {
|
|
|
229
1390
|
"@typescript-eslint/prefer-nullish-coalescing": "error",
|
|
230
1391
|
"no-shadow": "off",
|
|
231
1392
|
"@typescript-eslint/no-shadow": "error",
|
|
232
|
-
// Type-aware, so they need the project service wired below.
|
|
233
1393
|
"@typescript-eslint/no-floating-promises": "error",
|
|
234
1394
|
"@typescript-eslint/no-misused-promises": "error",
|
|
235
1395
|
"@typescript-eslint/await-thenable": "error",
|
|
@@ -274,42 +1434,66 @@ var generalRules = {
|
|
|
274
1434
|
"no-eval": "error",
|
|
275
1435
|
"no-implied-eval": "error",
|
|
276
1436
|
"no-script-url": "error",
|
|
277
|
-
|
|
278
|
-
"
|
|
1437
|
+
"padding-line-between-statements": ["error", { blankLine: "never", prev: "*", next: "*" }],
|
|
1438
|
+
"max-lines": ["error", { max: MAX_LINES, skipBlankLines: true, skipComments: true }]
|
|
279
1439
|
};
|
|
280
|
-
var
|
|
281
|
-
|
|
282
|
-
"
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
{
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
1440
|
+
var RESTRICTED_SELECTORS = {
|
|
1441
|
+
exportDefaultFunction: {
|
|
1442
|
+
selector: "ExportDefaultDeclaration > FunctionDeclaration",
|
|
1443
|
+
message: "Avoid `export default function`; use `export const` instead for tree-shakeable modules."
|
|
1444
|
+
},
|
|
1445
|
+
exportNamedFunction: {
|
|
1446
|
+
selector: "ExportNamedDeclaration > FunctionDeclaration",
|
|
1447
|
+
message: "Use `export const` instead of `export function` for tree-shakeable modules."
|
|
1448
|
+
},
|
|
1449
|
+
tsEnum: {
|
|
1450
|
+
selector: "TSEnumDeclaration",
|
|
1451
|
+
message: "Avoid enums; use const assertions or union types instead."
|
|
1452
|
+
},
|
|
1453
|
+
reactDefaultImport: {
|
|
1454
|
+
selector: "ImportDeclaration[source.value='react'] > ImportDefaultSpecifier",
|
|
1455
|
+
message: "Do not import the React default. Use the ambient `React.*` namespace (the react-jsx runtime needs no React import)."
|
|
1456
|
+
},
|
|
1457
|
+
reactNamespaceImport: {
|
|
1458
|
+
selector: "ImportDeclaration[source.value='react'] > ImportNamespaceSpecifier",
|
|
1459
|
+
message: "Do not `import * as React`. Use the ambient `React.*` namespace."
|
|
1460
|
+
},
|
|
1461
|
+
reactTypeImportSpecifier: {
|
|
1462
|
+
selector: "ImportDeclaration[source.value='react'] > ImportSpecifier[importKind='type']",
|
|
1463
|
+
message: "Reference React types via the ambient `React.*` namespace, not a named `{ type X }` import from react."
|
|
1464
|
+
},
|
|
1465
|
+
reactTypeImportDeclaration: {
|
|
1466
|
+
selector: "ImportDeclaration[importKind='type'][source.value='react']",
|
|
1467
|
+
message: 'Reference React types via the ambient `React.*` namespace, not `import type \u2026 from "react"`.'
|
|
1468
|
+
},
|
|
1469
|
+
lucideIcon: {
|
|
1470
|
+
selector: "ImportDeclaration[source.value='lucide-react'][importKind!='type'] > ImportSpecifier[importKind!='type'][imported.name!=/Icon$/][imported.name!='createLucideIcon'][imported.name!='icons'][imported.name!='dynamicIconImports']",
|
|
1471
|
+
message: "Import the `*Icon` name from lucide-react, so a rename never lands on the plain word."
|
|
1472
|
+
},
|
|
1473
|
+
nextFontGoogle: {
|
|
1474
|
+
selector: "ImportDeclaration[source.value='next/font/google']",
|
|
1475
|
+
message: "Self-host fonts instead of fetching them from next/font/google."
|
|
1476
|
+
},
|
|
1477
|
+
cloneElementImport: {
|
|
1478
|
+
selector: "ImportDeclaration[source.value='react'] > ImportSpecifier[imported.name='cloneElement']",
|
|
1479
|
+
message: "Avoid cloneElement; pass data through props instead of mutating a child element."
|
|
1480
|
+
},
|
|
1481
|
+
cloneElementMember: {
|
|
1482
|
+
selector: "MemberExpression[object.name='React'][property.name='cloneElement']",
|
|
1483
|
+
message: "Avoid React.cloneElement; pass data through props instead of mutating a child element."
|
|
1484
|
+
}
|
|
312
1485
|
};
|
|
1486
|
+
var ALL_SELECTOR_KEYS = Object.keys(RESTRICTED_SELECTORS);
|
|
1487
|
+
var EXPORT_DEFAULT_KEYS = ["exportDefaultFunction", "exportNamedFunction"];
|
|
1488
|
+
var NON_EXPORT_DEFAULT_KEYS = ALL_SELECTOR_KEYS.filter((key) => !EXPORT_DEFAULT_KEYS.includes(key));
|
|
1489
|
+
var NEXT_FILE_CONVENTIONS_GLOB = "**/{default,page,layout,error,loading,forbidden,not-found,template,unauthorized,icon,apple-icon,manifest,opengraph-image,twitter-image,global-error,proxy,middleware,sitemap,robots}.{ts,tsx}";
|
|
1490
|
+
var cnTernarySelector = (classMergeName) => ({
|
|
1491
|
+
selector: `CallExpression[callee.name='${classMergeName}'] > ConditionalExpression`,
|
|
1492
|
+
message: "Avoid a ternary inside `cn()`; use a cva variant or an object entry instead."
|
|
1493
|
+
});
|
|
1494
|
+
var restrictedSyntaxRule = (keys, extra = []) => ({
|
|
1495
|
+
"no-restricted-syntax": ["error", ...keys.map((key) => RESTRICTED_SELECTORS[key]), ...extra]
|
|
1496
|
+
});
|
|
313
1497
|
var reactRules = {
|
|
314
1498
|
"react/prop-types": "off",
|
|
315
1499
|
"react/react-in-jsx-scope": "off",
|
|
@@ -333,18 +1517,33 @@ var nextRules = {
|
|
|
333
1517
|
"@next/next/no-html-link-for-pages": "error",
|
|
334
1518
|
"@next/next/no-img-element": "error"
|
|
335
1519
|
};
|
|
1520
|
+
var JSX_A11Y_COMPONENTS = {
|
|
1521
|
+
Link: "a",
|
|
1522
|
+
Image: "img",
|
|
1523
|
+
Button: "button",
|
|
1524
|
+
Input: "input"
|
|
1525
|
+
};
|
|
336
1526
|
var importOrderRule = (groups) => ({
|
|
337
1527
|
"import-helpers/order-imports": [
|
|
338
1528
|
"error",
|
|
339
1529
|
{ newlinesBetween: "never", groups, alphabetize: { order: "asc", ignoreCase: true } }
|
|
340
1530
|
]
|
|
341
1531
|
});
|
|
1532
|
+
var escapeForRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1533
|
+
var arbitraryTailwindValuePattern = (allow) => {
|
|
1534
|
+
const exempt = allow.length ? `(?!(?:${allow.map(escapeForRegExp).join("|")})-)` : "";
|
|
1535
|
+
return `(?:^|:)!?-?${exempt}[a-zA-Z][a-zA-Z0-9-]*-\\[[^\\]]+\\](?:/[a-zA-Z0-9.]+)?!?$`;
|
|
1536
|
+
};
|
|
342
1537
|
var buildConfig = ({
|
|
343
1538
|
next = false,
|
|
344
1539
|
ignores = [],
|
|
345
1540
|
importGroups = DEFAULT_IMPORT_GROUPS,
|
|
346
1541
|
tsconfigRootDir = process.cwd(),
|
|
347
1542
|
tailwindEntryPoint,
|
|
1543
|
+
allowArbitraryClasses = [],
|
|
1544
|
+
classMergeName = "cn",
|
|
1545
|
+
nextConfigModules = [],
|
|
1546
|
+
strictExportGlobs = [],
|
|
348
1547
|
extend = []
|
|
349
1548
|
} = {}) => {
|
|
350
1549
|
const plugins = {
|
|
@@ -358,10 +1557,10 @@ var buildConfig = ({
|
|
|
358
1557
|
...importRules,
|
|
359
1558
|
...securityRules,
|
|
360
1559
|
...generalRules,
|
|
361
|
-
...restrictedSyntaxRule,
|
|
1560
|
+
...restrictedSyntaxRule(ALL_SELECTOR_KEYS, next ? [cnTernarySelector(classMergeName)] : []),
|
|
362
1561
|
...importOrderRule(importGroups)
|
|
363
1562
|
};
|
|
364
|
-
const languageGlobals = { ...
|
|
1563
|
+
const languageGlobals = { ...globals2.node, ...globals2.es2021 };
|
|
365
1564
|
const settings = {};
|
|
366
1565
|
if (next) {
|
|
367
1566
|
Object.assign(plugins, {
|
|
@@ -370,44 +1569,105 @@ var buildConfig = ({
|
|
|
370
1569
|
"react-hooks": reactHooks,
|
|
371
1570
|
"jsx-a11y": jsxA11y
|
|
372
1571
|
});
|
|
373
|
-
Object.assign(rules, reactRules, nextRules);
|
|
374
|
-
Object.assign(languageGlobals,
|
|
1572
|
+
Object.assign(rules, reactRules, nextRules, jsxA11y.configs.recommended.rules);
|
|
1573
|
+
Object.assign(languageGlobals, globals2.browser, {
|
|
375
1574
|
React: "readonly",
|
|
376
1575
|
JSX: "readonly",
|
|
377
1576
|
NodeJS: "readonly"
|
|
378
1577
|
});
|
|
379
1578
|
settings.react = { version: "detect" };
|
|
380
1579
|
settings["import-x/resolver-next"] = [createTypeScriptImportResolver({ alwaysTryTypes: true })];
|
|
1580
|
+
settings["jsx-a11y"] = { components: JSX_A11Y_COMPONENTS };
|
|
381
1581
|
if (tailwindEntryPoint) {
|
|
382
1582
|
plugins["better-tailwindcss"] = betterTailwind;
|
|
383
1583
|
Object.assign(rules, {
|
|
384
1584
|
"better-tailwindcss/no-unknown-classes": "error",
|
|
385
1585
|
"better-tailwindcss/no-conflicting-classes": "error",
|
|
386
|
-
"better-tailwindcss/no-concatenated-classes": "error"
|
|
1586
|
+
"better-tailwindcss/no-concatenated-classes": "error",
|
|
1587
|
+
"better-tailwindcss/no-restricted-classes": [
|
|
1588
|
+
"error",
|
|
1589
|
+
{
|
|
1590
|
+
restrict: [
|
|
1591
|
+
{
|
|
1592
|
+
pattern: arbitraryTailwindValuePattern(allowArbitraryClasses),
|
|
1593
|
+
message: "Avoid an arbitrary Tailwind value ($0); use a theme token, or list its prefix in allowArbitraryClasses when it has none (e.g. grid-cols-[...])."
|
|
1594
|
+
}
|
|
1595
|
+
]
|
|
1596
|
+
}
|
|
1597
|
+
]
|
|
387
1598
|
});
|
|
388
1599
|
settings["better-tailwindcss"] = { entryPoint: tailwindEntryPoint };
|
|
389
1600
|
}
|
|
390
1601
|
}
|
|
391
1602
|
const rootConfigOverride = {
|
|
392
1603
|
files: ["*.{mjs,js,ts,mts,cts}"],
|
|
393
|
-
rules: {
|
|
1604
|
+
rules: {
|
|
1605
|
+
"import-x/no-default-export": "off",
|
|
1606
|
+
...restrictedSyntaxRule(NON_EXPORT_DEFAULT_KEYS, next ? [cnTernarySelector(classMergeName)] : [])
|
|
1607
|
+
}
|
|
394
1608
|
};
|
|
395
1609
|
const nextFileConventionsOverride = {
|
|
396
|
-
files: [
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
1610
|
+
files: [NEXT_FILE_CONVENTIONS_GLOB],
|
|
1611
|
+
rules: {
|
|
1612
|
+
"import-x/no-default-export": "off",
|
|
1613
|
+
...restrictedSyntaxRule(NON_EXPORT_DEFAULT_KEYS, [cnTernarySelector(classMergeName)])
|
|
1614
|
+
}
|
|
400
1615
|
};
|
|
401
|
-
const
|
|
1616
|
+
const commentsOverride = {
|
|
402
1617
|
files: ["**/*.{js,jsx,mjs,cjs,ts,tsx,mts,cts}"],
|
|
403
|
-
plugins: { soujvnunes:
|
|
404
|
-
rules: { "soujvnunes/one-line-comments": "error" }
|
|
1618
|
+
plugins: { soujvnunes: soujvnunesPlugin },
|
|
1619
|
+
rules: { "soujvnunes/one-line-comments": "error", "soujvnunes/no-comments": "error" }
|
|
1620
|
+
};
|
|
1621
|
+
const clientBoundaryOverride = {
|
|
1622
|
+
files: ["**/*.{jsx,tsx}"],
|
|
1623
|
+
ignores: ["**/{error,global-error}.{jsx,tsx}"],
|
|
1624
|
+
plugins: { soujvnunes: soujvnunesPlugin },
|
|
1625
|
+
rules: {
|
|
1626
|
+
"soujvnunes/no-needless-use-client": "error",
|
|
1627
|
+
"soujvnunes/no-static-jsx-in-client": "error"
|
|
1628
|
+
}
|
|
1629
|
+
};
|
|
1630
|
+
const programBanRule = (message) => restrictedSyntaxRule(ALL_SELECTOR_KEYS, [
|
|
1631
|
+
cnTernarySelector(classMergeName),
|
|
1632
|
+
{ selector: "Program", message }
|
|
1633
|
+
]);
|
|
1634
|
+
const barrelOverride = {
|
|
1635
|
+
files: ["**/index.{ts,tsx}"],
|
|
1636
|
+
ignores: ["**/pages/**"],
|
|
1637
|
+
rules: programBanRule("Avoid a barrel index file; import each module by its own path.")
|
|
1638
|
+
};
|
|
1639
|
+
const featureRootOverride = {
|
|
1640
|
+
files: ["**/features/*/*.{ts,tsx}"],
|
|
1641
|
+
ignores: ["**/*.test.{ts,tsx}", NEXT_FILE_CONVENTIONS_GLOB],
|
|
1642
|
+
rules: programBanRule("A feature root holds only subfolders; place this file inside one of them.")
|
|
405
1643
|
};
|
|
406
1644
|
const scriptsOverride = {
|
|
407
1645
|
files: ["scripts/**/*.mjs"],
|
|
408
|
-
languageOptions: { globals: { ...
|
|
1646
|
+
languageOptions: { globals: { ...globals2.node } },
|
|
409
1647
|
rules: { "no-console": "off" }
|
|
410
1648
|
};
|
|
1649
|
+
const maxLinesExemptOverride = {
|
|
1650
|
+
files: ["**/*.test.*", "**/copy/**"],
|
|
1651
|
+
rules: { "max-lines": "off" }
|
|
1652
|
+
};
|
|
1653
|
+
const pureUtilsOverride = {
|
|
1654
|
+
files: ["**/utils/**"],
|
|
1655
|
+
rules: {
|
|
1656
|
+
"no-restricted-imports": [
|
|
1657
|
+
"error",
|
|
1658
|
+
{ patterns: ["server-only", "next/*", "react", "@/lib/*", "@/app/*"] }
|
|
1659
|
+
]
|
|
1660
|
+
}
|
|
1661
|
+
};
|
|
1662
|
+
const nextConfigModulesOverride = {
|
|
1663
|
+
files: ["next.config.{ts,mts,cts}", ...nextConfigModules],
|
|
1664
|
+
rules: { "no-restricted-imports": ["error", { patterns: ["@/*"] }] }
|
|
1665
|
+
};
|
|
1666
|
+
const strictExportsOverride = {
|
|
1667
|
+
files: strictExportGlobs,
|
|
1668
|
+
plugins: { soujvnunes: soujvnunesPlugin },
|
|
1669
|
+
rules: { "soujvnunes/one-export-per-file": "error" }
|
|
1670
|
+
};
|
|
411
1671
|
return [
|
|
412
1672
|
{ ignores: [...DEFAULT_IGNORES, ...ignores] },
|
|
413
1673
|
js.configs.recommended,
|
|
@@ -415,7 +1675,6 @@ var buildConfig = ({
|
|
|
415
1675
|
{
|
|
416
1676
|
files: ["**/*.{js,jsx,ts,tsx}"],
|
|
417
1677
|
plugins,
|
|
418
|
-
// Every rule here is an error, never a warning: a rule worth keeping is worth failing on, and a deliberate exception is an `eslint-disable` comment, which records the decision where the code is. `reportUnusedDisableDirectives` closes the loop by failing on a disable comment that suppresses nothing.
|
|
419
1678
|
linterOptions: { reportUnusedDisableDirectives: "error" },
|
|
420
1679
|
languageOptions: {
|
|
421
1680
|
parserOptions: {
|
|
@@ -431,10 +1690,14 @@ var buildConfig = ({
|
|
|
431
1690
|
rules
|
|
432
1691
|
},
|
|
433
1692
|
prettier,
|
|
434
|
-
|
|
1693
|
+
commentsOverride,
|
|
435
1694
|
rootConfigOverride,
|
|
436
|
-
...next ? [nextFileConventionsOverride] : [],
|
|
1695
|
+
...next ? [nextFileConventionsOverride, clientBoundaryOverride, barrelOverride, featureRootOverride] : [],
|
|
1696
|
+
maxLinesExemptOverride,
|
|
1697
|
+
pureUtilsOverride,
|
|
437
1698
|
scriptsOverride,
|
|
1699
|
+
...next && nextConfigModules.length ? [nextConfigModulesOverride] : [],
|
|
1700
|
+
...strictExportGlobs.length ? [strictExportsOverride] : [],
|
|
438
1701
|
...extend
|
|
439
1702
|
];
|
|
440
1703
|
};
|
|
@@ -444,5 +1707,5 @@ export {
|
|
|
444
1707
|
createBaseConfig,
|
|
445
1708
|
createNextConfig,
|
|
446
1709
|
oneLineComments,
|
|
447
|
-
|
|
1710
|
+
soujvnunesPlugin
|
|
448
1711
|
};
|