@sarj/eslint-plugin 16.4.8 → 16.5.1
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/dist/index.cjs +483 -362
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +482 -361
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
52
52
|
// package.json
|
|
53
53
|
var package_default = {
|
|
54
54
|
name: "@sarj/eslint-plugin",
|
|
55
|
-
version: "16.
|
|
55
|
+
version: "16.5.1",
|
|
56
56
|
packageManager: "npm@12.1.0",
|
|
57
57
|
description: "Custom ESLint rules for hypermodern TypeScript / React / Next.js projects",
|
|
58
58
|
type: "module",
|
|
@@ -2017,13 +2017,21 @@ function attributeText(node, name) {
|
|
|
2017
2017
|
}
|
|
2018
2018
|
return attribute.value === null ? "" : staticText(attribute.value);
|
|
2019
2019
|
}
|
|
2020
|
-
function isHidden(node) {
|
|
2020
|
+
function isHidden(node, source) {
|
|
2021
2021
|
if (attributeText(node, "aria-hidden") === "true") return true;
|
|
2022
2022
|
const hidden = node.attributes.findLast(
|
|
2023
2023
|
(attribute) => attribute.type === import_utils11.AST_NODE_TYPES.JSXSpreadAttribute || attribute.name.type === import_utils11.AST_NODE_TYPES.JSXIdentifier && attribute.name.name === "hidden"
|
|
2024
2024
|
);
|
|
2025
2025
|
if (hidden?.type !== import_utils11.AST_NODE_TYPES.JSXAttribute) return false;
|
|
2026
2026
|
if (hidden.value === null) return true;
|
|
2027
|
+
if (hidden.value.type === import_utils11.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
2028
|
+
const value = hidden.value.expression;
|
|
2029
|
+
if (value.type === import_utils11.AST_NODE_TYPES.Identifier && value.name === "undefined") {
|
|
2030
|
+
const binding = import_utils11.ASTUtils.findVariable(source.getScope(value), value.name);
|
|
2031
|
+
if (binding === null || binding.defs.length === 0) return false;
|
|
2032
|
+
}
|
|
2033
|
+
if (value.type === import_utils11.AST_NODE_TYPES.UnaryExpression && value.operator === "void" && value.argument.type === import_utils11.AST_NODE_TYPES.Literal && value.argument.value === 0) return false;
|
|
2034
|
+
}
|
|
2027
2035
|
if (hidden.value.type === import_utils11.AST_NODE_TYPES.JSXExpressionContainer && hidden.value.expression.type === import_utils11.AST_NODE_TYPES.Literal)
|
|
2028
2036
|
return hidden.value.expression.value !== false && hidden.value.expression.value !== null;
|
|
2029
2037
|
return true;
|
|
@@ -2054,7 +2062,7 @@ function childrenNameStatus(children, source, iconModules) {
|
|
|
2054
2062
|
return childrenNameStatus(child.children, source, iconModules);
|
|
2055
2063
|
if (child.type !== import_utils11.AST_NODE_TYPES.JSXElement) return "unknown";
|
|
2056
2064
|
const opening = child.openingElement;
|
|
2057
|
-
if (isHidden(opening)) return "empty";
|
|
2065
|
+
if (isHidden(opening, source)) return "empty";
|
|
2058
2066
|
const imported = importedComponent(opening.name, source);
|
|
2059
2067
|
const intrinsic = opening.name.type === import_utils11.AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(opening.name.name);
|
|
2060
2068
|
if (!intrinsic && (imported === null || !iconModules.includes(imported.module)))
|
|
@@ -2080,7 +2088,7 @@ function isPassedAsProp(node, source) {
|
|
|
2080
2088
|
}
|
|
2081
2089
|
function hasHiddenAncestor(node, source) {
|
|
2082
2090
|
return source.getAncestors(node).some(
|
|
2083
|
-
(ancestor) => ancestor.type === import_utils11.AST_NODE_TYPES.JSXElement && isHidden(ancestor.openingElement)
|
|
2091
|
+
(ancestor) => ancestor.type === import_utils11.AST_NODE_TYPES.JSXElement && isHidden(ancestor.openingElement, source)
|
|
2084
2092
|
);
|
|
2085
2093
|
}
|
|
2086
2094
|
function textNameStatus(text) {
|
|
@@ -2096,7 +2104,8 @@ var REQUIRE_BUTTON_ACCESSIBLE_NAME_DOCUMENTATION = {
|
|
|
2096
2104
|
category: "correctness",
|
|
2097
2105
|
limitations: [
|
|
2098
2106
|
"Native button and conventional Button elements are checked by default. Other custom buttons require exact module/export configuration; aliases and namespace imports are resolved by scope. Lucide icons are recognized by default; other icon modules are configurable.",
|
|
2099
|
-
"Composed JSX passed as props, render/asChild adapters, dynamic labels, children, unknown components, and prop spreads are left to runtime accessibility testing. Referenced IDs, CSS visibility, and meaningful wording are not verified. Generated files, tests, fixtures, and stories are excluded. No automatic labels are invented."
|
|
2107
|
+
"Composed JSX passed as props, render/asChild adapters, dynamic labels, children, unknown components, and prop spreads are left to runtime accessibility testing. Referenced IDs, CSS visibility, and meaningful wording are not verified. Generated files, tests, fixtures, and stories are excluded. No automatic labels are invented.",
|
|
2108
|
+
"A hidden prop with unshadowed undefined or exact void 0 does not hide the element or its children. Shadowed undefined and dynamic hidden values remain unproven."
|
|
2100
2109
|
],
|
|
2101
2110
|
examples: [
|
|
2102
2111
|
{
|
|
@@ -2174,7 +2183,7 @@ var require_button_accessible_name_default = createRule({
|
|
|
2174
2183
|
return;
|
|
2175
2184
|
if (isPassedAsProp(node, context.sourceCode) || hasHiddenAncestor(node, context.sourceCode))
|
|
2176
2185
|
return;
|
|
2177
|
-
if (isHidden(opening) || attributeNameStatus(opening) !== "empty")
|
|
2186
|
+
if (isHidden(opening, context.sourceCode) || attributeNameStatus(opening) !== "empty")
|
|
2178
2187
|
return;
|
|
2179
2188
|
if (childrenNameStatus(node.children, context.sourceCode, iconModules) !== "empty")
|
|
2180
2189
|
return;
|
|
@@ -2270,7 +2279,8 @@ var REQUIRE_SVG_ACCESSIBLE_NAME_DOCUMENTATION = {
|
|
|
2270
2279
|
remediation: "Add aria-label, aria-labelledby, or a direct title child; mark decorative graphics aria-hidden or presentational.",
|
|
2271
2280
|
category: "correctness",
|
|
2272
2281
|
limitations: [
|
|
2273
|
-
"Only intrinsic svg elements are checked. Dynamic labels, forwarded props, and dynamic title content remain runtime concerns. IDs, CSS visibility and graphic meaning are not inferred. Tests, stories, fixtures and generated files are excluded. No automatic title or decorative marker is invented."
|
|
2282
|
+
"Only intrinsic svg elements are checked. Dynamic labels, forwarded props, and dynamic title content remain runtime concerns. IDs, CSS visibility and graphic meaning are not inferred. Tests, stories, fixtures and generated files are excluded. No automatic title or decorative marker is invented.",
|
|
2283
|
+
"A hidden prop with unshadowed undefined or exact void 0 does not hide the element. Shadowed undefined and dynamic hidden values remain unproven."
|
|
2274
2284
|
],
|
|
2275
2285
|
examples: [
|
|
2276
2286
|
{
|
|
@@ -2320,7 +2330,7 @@ var require_svg_accessible_name_default = createRule({
|
|
|
2320
2330
|
return;
|
|
2321
2331
|
if (isPassedAsProp(node, context.sourceCode) || hasHiddenAncestor(node, context.sourceCode))
|
|
2322
2332
|
return;
|
|
2323
|
-
if (isHidden(opening) || ["none", "presentation"].includes(
|
|
2333
|
+
if (isHidden(opening, context.sourceCode) || ["none", "presentation"].includes(
|
|
2324
2334
|
attributeText(opening, "role") ?? ""
|
|
2325
2335
|
))
|
|
2326
2336
|
return;
|
|
@@ -6987,7 +6997,7 @@ var NO_JSON_STRINGIFY_ERROR_DOCUMENTATION = {
|
|
|
6987
6997
|
rationale: "Native Error details are non-enumerable, so generic JSON serialization discards diagnostic information.",
|
|
6988
6998
|
remediation: "Serialize explicit error fields or use an error-aware serializer.",
|
|
6989
6999
|
category: "correctness",
|
|
6990
|
-
limitations: ["The rule uses stable local catch bindings and unshadowed built-in constructors, not runtime type information. Custom replacers and explicit toJSON hooks are left to their serializer contract; a catch value is not guaranteed to be an Error. Member values, including cause, do not inherit the base Error's provenance; even an Error-valued member requires explicit value/dataflow proof outside this rule. Known literal __proto__ initializer chains preserve native hook inheritance and own toJSON precedence; computed __proto__ keys remain data. Unknown prototype expressions, hook values/spreads and deferred hook writes conservatively lose default serializer proof. Explicit writes invalidate constructor provenance except a later, separate top-level statement; deferred functions, loops, and unknown property keys conservatively lose constructor proof. Statically owned global/property writes and native Reflect.set/Reflect.defineProperty/Object.defineProperty/Object.defineProperties calls are tracked. Mutator aliases, replaced Reflect/Object methods, external calls, and runtime-only property names are not resolved; uncertain ordering conservatively loses proof."],
|
|
7000
|
+
limitations: ["The rule uses stable local catch bindings and unshadowed built-in constructors, not runtime type information. Native DOMException constructor coverage is validated in Node; browser serialization is not evaluated. Custom replacers and explicit toJSON hooks are left to their serializer contract; a catch value is not guaranteed to be an Error. Member values, including cause, do not inherit the base Error's provenance; even an Error-valued member requires explicit value/dataflow proof outside this rule. Known literal __proto__ initializer chains preserve native hook inheritance and own toJSON precedence; computed __proto__ keys remain data. Unknown prototype expressions, hook values/spreads and deferred hook writes conservatively lose default serializer proof. Explicit writes invalidate constructor provenance except a later, separate top-level statement; deferred functions, loops, and unknown property keys conservatively lose constructor proof. Statically owned global/property writes and native Reflect.set/Reflect.defineProperty/Object.defineProperty/Object.defineProperties calls are tracked. Mutator aliases, replaced Reflect/Object methods, external calls, and runtime-only property names are not resolved; uncertain ordering conservatively loses proof."],
|
|
6991
7001
|
examples: [
|
|
6992
7002
|
{ id: "explicit-error-message", title: "Narrow an unknown catch value before selecting fields", outcome: "no-match", files: [{ path: "src/report.ts", source: "try { f(); } catch (err) { JSON.stringify({ error: err instanceof Error ? err.message : String(err) }); }" }], focusPath: "src/report.ts", expectedCount: 0, public: true },
|
|
6993
7003
|
{ id: "stringified-error", title: "Do not stringify an Error object", outcome: "match", files: [{ path: "src/report.ts", source: "try { f(); } catch (err) { JSON.stringify({ error: err }); }" }], focusPath: "src/report.ts", expectedCount: 1, public: true },
|
|
@@ -7009,6 +7019,7 @@ var NO_JSON_STRINGIFY_ERROR_DOCUMENTATION = {
|
|
|
7009
7019
|
};
|
|
7010
7020
|
var BUILTIN_ERROR_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
7011
7021
|
"AggregateError",
|
|
7022
|
+
"DOMException",
|
|
7012
7023
|
"Error",
|
|
7013
7024
|
"EvalError",
|
|
7014
7025
|
"RangeError",
|
|
@@ -11852,7 +11863,7 @@ var NO_SILENT_PROMISE_CATCH_DOCUMENTATION = {
|
|
|
11852
11863
|
rationale: "A swallowed rejection hides failures and gives callers an indistinguishable fallback value.",
|
|
11853
11864
|
remediation: "Log, rethrow, or explicitly recover from the rejection; explain intentional teardown suppression.",
|
|
11854
11865
|
category: "correctness",
|
|
11855
|
-
limitations: ["Test files, teardown calls, explanatory comments, non-function handlers, and handlers that consume or report the error are excluded.", "Recognized imported Zod construction chains and their stable local aliases are excluded. Other untyped catch-like APIs are not proven to be Promises.", "Computed methods resolve literal syntax and stable local string aliases in lexical scope. Function-derived, object-derived and mutated computed keys remain unproven."],
|
|
11866
|
+
limitations: ["Test files, teardown calls, explanatory comments, non-function handlers, and handlers that consume or report the error are excluded.", "Recognized imported Zod construction chains and their stable local aliases are excluded, including URL schemas and primitive bigint, boolean, number and string coercion. Other untyped catch-like APIs are not proven to be Promises.", "Computed methods resolve literal syntax and stable local string aliases in lexical scope. Function-derived, object-derived and mutated computed keys remain unproven."],
|
|
11856
11867
|
examples: [
|
|
11857
11868
|
{ id: "reported-rejection", title: "Report the rejection", outcome: "no-match", files: [{ path: "src/load.ts", source: "load().catch((error) => logger.error({ error }, 'load failed'));" }], focusPath: "src/load.ts", expectedCount: 0, public: true },
|
|
11858
11869
|
{ id: "silent-rejection", title: "Do not swallow the rejection", outcome: "match", files: [{ path: "src/load.ts", source: "load().catch(() => null);" }], focusPath: "src/load.ts", expectedCount: 1, public: true },
|
|
@@ -11888,7 +11899,8 @@ var ZOD_CONSTRUCTORS = /* @__PURE__ */ new Set([
|
|
|
11888
11899
|
"tuple",
|
|
11889
11900
|
"undefined",
|
|
11890
11901
|
"union",
|
|
11891
|
-
"unknown"
|
|
11902
|
+
"unknown",
|
|
11903
|
+
"url"
|
|
11892
11904
|
]);
|
|
11893
11905
|
var ZOD_CHAIN_METHODS = /* @__PURE__ */ new Set([
|
|
11894
11906
|
"array",
|
|
@@ -11996,8 +12008,9 @@ var no_silent_promise_catch_default = createRule({
|
|
|
11996
12008
|
return binding.defs.length === 1 && definition?.node.type === import_utils68.AST_NODE_TYPES.VariableDeclarator && definition.node.init !== null && isZodSchema(definition.node.init, seen);
|
|
11997
12009
|
}
|
|
11998
12010
|
if (node.type !== import_utils68.AST_NODE_TYPES.CallExpression || unwrappedNodeCallee?.type !== import_utils68.AST_NODE_TYPES.MemberExpression) return false;
|
|
11999
|
-
|
|
12011
|
+
let { object } = unwrappedNodeCallee;
|
|
12000
12012
|
const method = staticPropertyName(unwrappedNodeCallee, context.sourceCode);
|
|
12013
|
+
if (object.type === import_utils68.AST_NODE_TYPES.MemberExpression && staticPropertyName(object, context.sourceCode) === "coerce" && method !== null && ["bigint", "boolean", "number", "string"].includes(method)) object = object.object;
|
|
12001
12014
|
if (object.type === import_utils68.AST_NODE_TYPES.Identifier && method !== null && ZOD_CONSTRUCTORS.has(method)) {
|
|
12002
12015
|
const binding = import_utils68.ASTUtils.findVariable(context.sourceCode.getScope(object), object.name);
|
|
12003
12016
|
if (binding?.defs.some((definition) => {
|
|
@@ -21360,8 +21373,112 @@ function staticFieldName(key) {
|
|
|
21360
21373
|
return key.type === import_utils115.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils115.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
21361
21374
|
}
|
|
21362
21375
|
|
|
21363
|
-
// src/rules/
|
|
21376
|
+
// src/rules/named-child-schema-type.ts
|
|
21364
21377
|
var import_utils116 = require("@typescript-eslint/utils");
|
|
21378
|
+
var UNRESOLVED_TYPE_NODES = /* @__PURE__ */ new Set([
|
|
21379
|
+
import_utils116.AST_NODE_TYPES.TSTypeQuery,
|
|
21380
|
+
import_utils116.AST_NODE_TYPES.TSImportType,
|
|
21381
|
+
import_utils116.AST_NODE_TYPES.TSTypeParameter,
|
|
21382
|
+
import_utils116.AST_NODE_TYPES.TSAnyKeyword,
|
|
21383
|
+
import_utils116.AST_NODE_TYPES.TSUnknownKeyword
|
|
21384
|
+
]);
|
|
21385
|
+
var NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION = {
|
|
21386
|
+
defaultLevel: "warning",
|
|
21387
|
+
summary: "Reference a named Zod record child's complete schema type instead of repeating its explicit annotation.",
|
|
21388
|
+
rationale: "Repeating a child schema's generic contract creates a second maintained declaration even though the record already uses that child at runtime.",
|
|
21389
|
+
remediation: "Replace only the matching record type argument with `typeof ChildSchema`; retain the outer annotation required by isolatedDeclarations and every runtime schema operation.",
|
|
21390
|
+
category: "maintainability",
|
|
21391
|
+
autofix: "none",
|
|
21392
|
+
limitations: [
|
|
21393
|
+
"Only direct module-level const z.record calls with two arguments, a ZodRecord annotation, and an earlier local const child with a complete explicit Zod type are inspected.",
|
|
21394
|
+
"The entire generic child annotation must match token for token; input/output, defaults, transforms, readonly modifiers and brands are never compared by output shape alone.",
|
|
21395
|
+
"Bare leaf types, broad ZodType constraints, type queries, imported or unqualified type references, annotation cycles, comments on the repeated argument, mutable bindings and generated files are excluded.",
|
|
21396
|
+
"Import aliases and namespace imports resolve through scope bindings. Independent public contract pins require review; this warning does not remove annotations or change runtime validation."
|
|
21397
|
+
],
|
|
21398
|
+
examples: [
|
|
21399
|
+
{ id: "named-child", title: "Reference the named child contract", outcome: "no-match", files: [{ path: "src/record.ts", source: 'import { z } from "zod"; const KeySchema: z.ZodEnum<{ a: "a"; b: "b" }> = z.enum(["a", "b"]); export const RecordSchema: z.ZodRecord<typeof KeySchema, z.ZodString> = z.record(KeySchema, z.string());' }], focusPath: "src/record.ts", expectedCount: 0, public: true },
|
|
21400
|
+
{ id: "copied-child", title: "Do not repeat the complete child annotation", outcome: "match", files: [{ path: "src/record.ts", source: 'import { z } from "zod"; const KeySchema: z.ZodEnum<{ a: "a"; b: "b" }> = z.enum(["a", "b"]); export const RecordSchema: z.ZodRecord<z.ZodEnum<{ a: "a"; b: "b" }>, z.ZodString> = z.record(KeySchema, z.string());' }], focusPath: "src/record.ts", expectedCount: 1, public: true }
|
|
21401
|
+
]
|
|
21402
|
+
};
|
|
21403
|
+
function isModuleConst(node) {
|
|
21404
|
+
if (node.parent.kind !== "const" || node.id.type !== import_utils116.AST_NODE_TYPES.Identifier) return false;
|
|
21405
|
+
const parent = node.parent.parent;
|
|
21406
|
+
return parent.type === import_utils116.AST_NODE_TYPES.Program || parent.type === import_utils116.AST_NODE_TYPES.ExportNamedDeclaration && parent.parent.type === import_utils116.AST_NODE_TYPES.Program;
|
|
21407
|
+
}
|
|
21408
|
+
var named_child_schema_type_default = createRule({
|
|
21409
|
+
name: "named-child-schema-type",
|
|
21410
|
+
documentation: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION,
|
|
21411
|
+
meta: {
|
|
21412
|
+
type: "suggestion",
|
|
21413
|
+
docs: { description: NAMED_CHILD_SCHEMA_TYPE_DOCUMENTATION.summary },
|
|
21414
|
+
schema: [],
|
|
21415
|
+
messages: { namedChildType: "Use `typeof {{name}}` for this exact child contract; keep the outer schema annotation and runtime operations." }
|
|
21416
|
+
},
|
|
21417
|
+
defaultOptions: [],
|
|
21418
|
+
create(context) {
|
|
21419
|
+
const source = context.sourceCode;
|
|
21420
|
+
if (isGeneratedFile(context.filename, source.text)) return {};
|
|
21421
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
21422
|
+
const bindingOf = (node) => import_utils116.ASTUtils.findVariable(source.getScope(node), node.name);
|
|
21423
|
+
function namespaceOf(type) {
|
|
21424
|
+
if (type.typeName.type !== import_utils116.AST_NODE_TYPES.TSQualifiedName || type.typeName.left.type !== import_utils116.AST_NODE_TYPES.Identifier) return null;
|
|
21425
|
+
const binding = bindingOf(type.typeName.left);
|
|
21426
|
+
return binding !== null && namespaces.has(binding) ? binding : null;
|
|
21427
|
+
}
|
|
21428
|
+
function closedType(node, namespace) {
|
|
21429
|
+
if (UNRESOLVED_TYPE_NODES.has(node.type)) return false;
|
|
21430
|
+
if (node.type === import_utils116.AST_NODE_TYPES.TSTypeReference && namespaceOf(node) !== namespace) return false;
|
|
21431
|
+
return !forEachOwnAstChild(node, (child) => !closedType(child, namespace));
|
|
21432
|
+
}
|
|
21433
|
+
function inspectChild(argument, repeated, namespace, parent) {
|
|
21434
|
+
if (argument.type !== import_utils116.AST_NODE_TYPES.Identifier || repeated.type !== import_utils116.AST_NODE_TYPES.TSTypeReference || repeated.typeArguments === void 0) return;
|
|
21435
|
+
if (repeated.typeName.type !== import_utils116.AST_NODE_TYPES.TSQualifiedName || /^(?:ZodType|ZodSchema|ZodTypeAny)$/u.test(repeated.typeName.right.name)) return;
|
|
21436
|
+
const variable = bindingOf(argument);
|
|
21437
|
+
const definition = variable?.defs.length === 1 ? variable.defs[0] : void 0;
|
|
21438
|
+
if (definition?.type !== "Variable" || !isModuleConst(definition.node)) return;
|
|
21439
|
+
const child = definition.node;
|
|
21440
|
+
if (child.id.type !== import_utils116.AST_NODE_TYPES.Identifier || child.init === null || child.range[0] >= parent.range[0]) return;
|
|
21441
|
+
const annotation = child.id.typeAnnotation?.typeAnnotation;
|
|
21442
|
+
if (annotation === void 0 || factoryNamespace(child.init) !== namespace || !closedType(annotation, namespace)) return;
|
|
21443
|
+
if (source.getCommentsInside(repeated).length > 0 || source.getCommentsBefore(repeated).length > 0) return;
|
|
21444
|
+
const expected = source.getTokens(annotation);
|
|
21445
|
+
const actual = source.getTokens(repeated);
|
|
21446
|
+
if (expected.length !== actual.length || expected.some((token, index) => token.type !== actual[index]?.type || token.value !== actual[index]?.value)) return;
|
|
21447
|
+
context.report({ node: repeated, messageId: "namedChildType", data: { name: argument.name } });
|
|
21448
|
+
}
|
|
21449
|
+
function factoryNamespace(expression) {
|
|
21450
|
+
if (expression.type !== import_utils116.AST_NODE_TYPES.CallExpression || expression.callee.type !== import_utils116.AST_NODE_TYPES.MemberExpression) return null;
|
|
21451
|
+
const object = expression.callee.object;
|
|
21452
|
+
return object.type === import_utils116.AST_NODE_TYPES.Identifier ? bindingOf(object) : factoryNamespace(object);
|
|
21453
|
+
}
|
|
21454
|
+
return {
|
|
21455
|
+
ImportDeclaration(node) {
|
|
21456
|
+
if (node.importKind === "type" || !isZodModule(node.source.value)) return;
|
|
21457
|
+
for (const specifier of node.specifiers) {
|
|
21458
|
+
if (specifier.type !== import_utils116.AST_NODE_TYPES.ImportNamespaceSpecifier && (specifier.type !== import_utils116.AST_NODE_TYPES.ImportSpecifier || specifier.importKind === "type" || importSpecifierName(specifier) !== "z")) continue;
|
|
21459
|
+
const binding = bindingOf(specifier.local);
|
|
21460
|
+
if (binding !== null) namespaces.add(binding);
|
|
21461
|
+
}
|
|
21462
|
+
},
|
|
21463
|
+
VariableDeclarator(node) {
|
|
21464
|
+
if (!isModuleConst(node) || node.id.type !== import_utils116.AST_NODE_TYPES.Identifier || node.init?.type !== import_utils116.AST_NODE_TYPES.CallExpression) return;
|
|
21465
|
+
const call = node.init;
|
|
21466
|
+
if (call.arguments.length !== 2 || call.callee.type !== import_utils116.AST_NODE_TYPES.MemberExpression || call.callee.object.type !== import_utils116.AST_NODE_TYPES.Identifier || import_utils116.ASTUtils.getPropertyName(call.callee) !== "record") return;
|
|
21467
|
+
const annotation = node.id.typeAnnotation?.typeAnnotation;
|
|
21468
|
+
if (annotation?.type !== import_utils116.AST_NODE_TYPES.TSTypeReference || annotation.typeName.type !== import_utils116.AST_NODE_TYPES.TSQualifiedName || annotation.typeName.right.name !== "ZodRecord") return;
|
|
21469
|
+
const namespace = namespaceOf(annotation);
|
|
21470
|
+
if (namespace === null || bindingOf(call.callee.object) !== namespace || annotation.typeArguments?.params.length !== 2) return;
|
|
21471
|
+
for (const [index, argument] of call.arguments.entries()) {
|
|
21472
|
+
const repeated = annotation.typeArguments.params[index];
|
|
21473
|
+
if (repeated !== void 0) inspectChild(argument, repeated, namespace, node);
|
|
21474
|
+
}
|
|
21475
|
+
}
|
|
21476
|
+
};
|
|
21477
|
+
}
|
|
21478
|
+
});
|
|
21479
|
+
|
|
21480
|
+
// src/rules/prefer-zod-parse-output-type.ts
|
|
21481
|
+
var import_utils117 = require("@typescript-eslint/utils");
|
|
21365
21482
|
var import_typescript7 = __toESM(require("typescript"), 1);
|
|
21366
21483
|
var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
21367
21484
|
summary: "Derive a function's return contract from the local Zod schema whose parsed output it returns.",
|
|
@@ -21417,22 +21534,22 @@ var PREFER_ZOD_PARSE_OUTPUT_TYPE_DOCUMENTATION = {
|
|
|
21417
21534
|
};
|
|
21418
21535
|
function isModuleLevelConst2(node) {
|
|
21419
21536
|
const declaration = node.parent;
|
|
21420
|
-
if (declaration.type !==
|
|
21537
|
+
if (declaration.type !== import_utils117.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const") {
|
|
21421
21538
|
return false;
|
|
21422
21539
|
}
|
|
21423
21540
|
const container = declaration.parent;
|
|
21424
|
-
return container.type ===
|
|
21541
|
+
return container.type === import_utils117.AST_NODE_TYPES.Program || container.type === import_utils117.AST_NODE_TYPES.ExportNamedDeclaration && container.parent.type === import_utils117.AST_NODE_TYPES.Program;
|
|
21425
21542
|
}
|
|
21426
21543
|
function isLocalZodObjectSchema(node, namespaces) {
|
|
21427
21544
|
let current = node;
|
|
21428
|
-
while (current.type ===
|
|
21545
|
+
while (current.type === import_utils117.AST_NODE_TYPES.CallExpression) {
|
|
21429
21546
|
const callee = unwrapExpression(current.callee);
|
|
21430
|
-
const calleeReceiver = callee.type ===
|
|
21431
|
-
if (callee.type !==
|
|
21547
|
+
const calleeReceiver = callee.type === import_utils117.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21548
|
+
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression || import_utils117.ASTUtils.getPropertyName(callee) === null) {
|
|
21432
21549
|
return false;
|
|
21433
21550
|
}
|
|
21434
|
-
if (calleeReceiver.type ===
|
|
21435
|
-
return namespaces.has(calleeReceiver.name) && ((
|
|
21551
|
+
if (calleeReceiver.type === import_utils117.AST_NODE_TYPES.Identifier) {
|
|
21552
|
+
return namespaces.has(calleeReceiver.name) && ((import_utils117.ASTUtils.getPropertyName(callee) ?? "") === "object" || (import_utils117.ASTUtils.getPropertyName(callee) ?? "") === "strictObject");
|
|
21436
21553
|
}
|
|
21437
21554
|
current = calleeReceiver;
|
|
21438
21555
|
}
|
|
@@ -21440,11 +21557,11 @@ function isLocalZodObjectSchema(node, namespaces) {
|
|
|
21440
21557
|
}
|
|
21441
21558
|
function zodParseCall(node) {
|
|
21442
21559
|
const callee = unwrapExpression(node.callee);
|
|
21443
|
-
const calleeReceiver = callee.type ===
|
|
21444
|
-
if (callee.type !==
|
|
21560
|
+
const calleeReceiver = callee.type === import_utils117.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
21561
|
+
if (callee.type !== import_utils117.AST_NODE_TYPES.MemberExpression || calleeReceiver.type !== import_utils117.AST_NODE_TYPES.Identifier || import_utils117.ASTUtils.getPropertyName(callee) === null) {
|
|
21445
21562
|
return null;
|
|
21446
21563
|
}
|
|
21447
|
-
const method =
|
|
21564
|
+
const method = import_utils117.ASTUtils.getPropertyName(callee);
|
|
21448
21565
|
if (method !== "parse" && method !== "safeParse") return null;
|
|
21449
21566
|
return {
|
|
21450
21567
|
call: node,
|
|
@@ -21458,7 +21575,7 @@ function returnedOutputCandidate(parsed, output) {
|
|
|
21458
21575
|
const annotation = owner?.returnType?.typeAnnotation;
|
|
21459
21576
|
if (annotation === void 0) return null;
|
|
21460
21577
|
const typeReference = returnContractReference(annotation);
|
|
21461
|
-
if (typeReference === null || typeReference.typeName.type !==
|
|
21578
|
+
if (typeReference === null || typeReference.typeName.type !== import_utils117.AST_NODE_TYPES.Identifier) {
|
|
21462
21579
|
return null;
|
|
21463
21580
|
}
|
|
21464
21581
|
return {
|
|
@@ -21475,7 +21592,7 @@ function directParseReturnCandidate(node) {
|
|
|
21475
21592
|
return parsed?.method === "parse" ? returnedOutputCandidate(parsed, node) : null;
|
|
21476
21593
|
}
|
|
21477
21594
|
function localParseReturnCandidates(node, sourceCode) {
|
|
21478
|
-
if (node.id.type !==
|
|
21595
|
+
if (node.id.type !== import_utils117.AST_NODE_TYPES.Identifier || node.init?.type !== import_utils117.AST_NODE_TYPES.CallExpression || node.parent.type !== import_utils117.AST_NODE_TYPES.VariableDeclaration || node.parent.kind !== "const" || enclosingFunction4(node.init) === null) {
|
|
21479
21596
|
return [];
|
|
21480
21597
|
}
|
|
21481
21598
|
const parsed = zodParseCall(node.init);
|
|
@@ -21486,7 +21603,7 @@ function localParseReturnCandidates(node, sourceCode) {
|
|
|
21486
21603
|
for (const reference of variable.references) {
|
|
21487
21604
|
const identifier = reference.identifier;
|
|
21488
21605
|
const parent = identifier.parent;
|
|
21489
|
-
const output = parsed.method === "parse" ? identifier : parent.type ===
|
|
21606
|
+
const output = parsed.method === "parse" ? identifier : parent.type === import_utils117.AST_NODE_TYPES.MemberExpression && parent.object === identifier && import_utils117.ASTUtils.getPropertyName(parent) !== null && (import_utils117.ASTUtils.getPropertyName(parent) ?? "") === "data" ? parent : null;
|
|
21490
21607
|
if (output === null) continue;
|
|
21491
21608
|
const candidate2 = returnedOutputCandidate(parsed, output);
|
|
21492
21609
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
@@ -21497,17 +21614,17 @@ function directReturnOwner(node) {
|
|
|
21497
21614
|
let current = node;
|
|
21498
21615
|
while (current.parent !== void 0) {
|
|
21499
21616
|
const parent = current.parent;
|
|
21500
|
-
if (parent.type ===
|
|
21617
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.ReturnStatement) {
|
|
21501
21618
|
return parent.argument === current ? enclosingFunction4(parent) : null;
|
|
21502
21619
|
}
|
|
21503
|
-
if (parent.type ===
|
|
21620
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.ArrowFunctionExpression && parent.expression && parent.body === current) {
|
|
21504
21621
|
return parent;
|
|
21505
21622
|
}
|
|
21506
|
-
if (parent.type ===
|
|
21623
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.AwaitExpression && parent.argument === current) {
|
|
21507
21624
|
current = parent;
|
|
21508
21625
|
continue;
|
|
21509
21626
|
}
|
|
21510
|
-
if (parent.type ===
|
|
21627
|
+
if (parent.type === import_utils117.AST_NODE_TYPES.ConditionalExpression) {
|
|
21511
21628
|
const parsedWhenTrue = parent.consequent === current && isNullishExpression(parent.alternate);
|
|
21512
21629
|
const parsedWhenFalse = parent.alternate === current && isNullishExpression(parent.consequent);
|
|
21513
21630
|
if (parsedWhenTrue || parsedWhenFalse) {
|
|
@@ -21520,12 +21637,12 @@ function directReturnOwner(node) {
|
|
|
21520
21637
|
return null;
|
|
21521
21638
|
}
|
|
21522
21639
|
function isNullishExpression(node) {
|
|
21523
|
-
return node.type ===
|
|
21640
|
+
return node.type === import_utils117.AST_NODE_TYPES.Literal && node.value === null || node.type === import_utils117.AST_NODE_TYPES.Identifier && node.name === "undefined";
|
|
21524
21641
|
}
|
|
21525
21642
|
function enclosingFunction4(node) {
|
|
21526
21643
|
let current = node.parent;
|
|
21527
21644
|
while (current != null) {
|
|
21528
|
-
if (current.type ===
|
|
21645
|
+
if (current.type === import_utils117.AST_NODE_TYPES.ArrowFunctionExpression || current.type === import_utils117.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils117.AST_NODE_TYPES.FunctionExpression) {
|
|
21529
21646
|
return current;
|
|
21530
21647
|
}
|
|
21531
21648
|
current = current.parent;
|
|
@@ -21533,45 +21650,45 @@ function enclosingFunction4(node) {
|
|
|
21533
21650
|
return null;
|
|
21534
21651
|
}
|
|
21535
21652
|
function returnContractReference(node) {
|
|
21536
|
-
if (node.type ===
|
|
21653
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSUnionType) {
|
|
21537
21654
|
const substantive = node.types.filter(
|
|
21538
|
-
(member) => member.type !==
|
|
21655
|
+
(member) => member.type !== import_utils117.AST_NODE_TYPES.TSNullKeyword && member.type !== import_utils117.AST_NODE_TYPES.TSUndefinedKeyword
|
|
21539
21656
|
);
|
|
21540
21657
|
const [only] = substantive;
|
|
21541
21658
|
return substantive.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21542
21659
|
}
|
|
21543
|
-
if (node.type ===
|
|
21660
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils117.AST_NODE_TYPES.Identifier && node.typeName.name === "Promise") {
|
|
21544
21661
|
const parameters = node.typeArguments?.params ?? [];
|
|
21545
21662
|
const [only] = parameters;
|
|
21546
21663
|
return parameters.length === 1 && only !== void 0 ? returnContractReference(only) : null;
|
|
21547
21664
|
}
|
|
21548
|
-
return node.type ===
|
|
21665
|
+
return node.type === import_utils117.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils117.AST_NODE_TYPES.Identifier && (node.typeArguments?.params.length ?? 0) === 0 ? node : null;
|
|
21549
21666
|
}
|
|
21550
21667
|
function recordZodNamespaces(node, namespaces) {
|
|
21551
21668
|
for (const statement of node.body) {
|
|
21552
|
-
if (statement.type !==
|
|
21669
|
+
if (statement.type !== import_utils117.AST_NODE_TYPES.ImportDeclaration || !isZodModule(statement.source.value)) {
|
|
21553
21670
|
continue;
|
|
21554
21671
|
}
|
|
21555
21672
|
for (const specifier of statement.specifiers) {
|
|
21556
|
-
if (specifier.type ===
|
|
21673
|
+
if (specifier.type === import_utils117.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils117.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils117.AST_NODE_TYPES.ImportSpecifier && importSpecifierName(specifier) === "z") {
|
|
21557
21674
|
namespaces.add(specifier.local.name);
|
|
21558
21675
|
}
|
|
21559
21676
|
}
|
|
21560
21677
|
}
|
|
21561
21678
|
}
|
|
21562
21679
|
function collectConstrainedNames(node, names) {
|
|
21563
|
-
if (node.type ===
|
|
21564
|
-
if (node.typeName.type ===
|
|
21680
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSTypeReference) {
|
|
21681
|
+
if (node.typeName.type === import_utils117.AST_NODE_TYPES.Identifier) names.add(node.typeName.name);
|
|
21565
21682
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21566
21683
|
collectConstrainedNames(argument, names);
|
|
21567
21684
|
}
|
|
21568
21685
|
return;
|
|
21569
21686
|
}
|
|
21570
|
-
if (node.type ===
|
|
21687
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSArrayType) {
|
|
21571
21688
|
collectConstrainedNames(node.elementType, names);
|
|
21572
21689
|
return;
|
|
21573
21690
|
}
|
|
21574
|
-
if (node.type ===
|
|
21691
|
+
if (node.type === import_utils117.AST_NODE_TYPES.TSUnionType || node.type === import_utils117.AST_NODE_TYPES.TSIntersectionType) {
|
|
21575
21692
|
for (const member of node.types) collectConstrainedNames(member, names);
|
|
21576
21693
|
}
|
|
21577
21694
|
}
|
|
@@ -21605,7 +21722,7 @@ function reportCandidates(context, services, schemas, candidates, zodNamespaces,
|
|
|
21605
21722
|
if (constrained) return;
|
|
21606
21723
|
if (declaration.getSourceFile() === tsSchema.getSourceFile()) {
|
|
21607
21724
|
const estreeDeclaration = services.tsNodeToESTreeNodeMap.get(declaration);
|
|
21608
|
-
if ((estreeDeclaration.type ===
|
|
21725
|
+
if ((estreeDeclaration.type === import_utils117.AST_NODE_TYPES.TSInterfaceDeclaration || estreeDeclaration.type === import_utils117.AST_NODE_TYPES.TSTypeAliasDeclaration) && preferZodInferOwnsDefaultTwin({
|
|
21609
21726
|
constrained,
|
|
21610
21727
|
declaration: estreeDeclaration,
|
|
21611
21728
|
initializer: schema.initializer,
|
|
@@ -21695,7 +21812,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21695
21812
|
}
|
|
21696
21813
|
let services;
|
|
21697
21814
|
try {
|
|
21698
|
-
services =
|
|
21815
|
+
services = import_utils117.ESLintUtils.getParserServices(context);
|
|
21699
21816
|
} catch {
|
|
21700
21817
|
services = null;
|
|
21701
21818
|
}
|
|
@@ -21710,7 +21827,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21710
21827
|
recordZodNamespaces(node, namespaces);
|
|
21711
21828
|
},
|
|
21712
21829
|
VariableDeclarator(node) {
|
|
21713
|
-
if (node.id.type ===
|
|
21830
|
+
if (node.id.type === import_utils117.AST_NODE_TYPES.Identifier && node.init !== null && isModuleLevelConst2(node) && isLocalZodObjectSchema(node.init, namespaces)) {
|
|
21714
21831
|
schemas.push({ identifier: node.id, initializer: node.init, name: node.id.name });
|
|
21715
21832
|
}
|
|
21716
21833
|
candidates.push(...localParseReturnCandidates(node, context.sourceCode));
|
|
@@ -21720,13 +21837,13 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21720
21837
|
if (candidate2 !== null) candidates.push(candidate2);
|
|
21721
21838
|
},
|
|
21722
21839
|
"MemberExpression"(node) {
|
|
21723
|
-
if (node.object.type ===
|
|
21840
|
+
if (node.object.type === import_utils117.AST_NODE_TYPES.Identifier && node.property.type === import_utils117.AST_NODE_TYPES.Identifier && isPreferZodInferModuleReshaper(node.property.name)) {
|
|
21724
21841
|
reshapedSchemas.add(node.object.name);
|
|
21725
21842
|
}
|
|
21726
21843
|
},
|
|
21727
21844
|
TSTypeReference(node) {
|
|
21728
21845
|
const { typeName } = node;
|
|
21729
|
-
const name = typeName.type ===
|
|
21846
|
+
const name = typeName.type === import_utils117.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils117.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils117.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
21730
21847
|
if (name === null || !isPreferZodInferTypeConstraintName(name)) return;
|
|
21731
21848
|
for (const argument of node.typeArguments?.params ?? []) {
|
|
21732
21849
|
collectConstrainedNames(argument, constrainedTypeNames);
|
|
@@ -21748,7 +21865,7 @@ var prefer_zod_parse_output_type_default = createRule({
|
|
|
21748
21865
|
});
|
|
21749
21866
|
|
|
21750
21867
|
// src/rules/require-assert-never.ts
|
|
21751
|
-
var
|
|
21868
|
+
var import_utils118 = require("@typescript-eslint/utils");
|
|
21752
21869
|
var import_typescript8 = __toESM(require("typescript"), 1);
|
|
21753
21870
|
var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
21754
21871
|
summary: "Require an empty switch default to call `assertNever` so discriminated unions remain exhaustive at compile time.",
|
|
@@ -21762,14 +21879,14 @@ var REQUIRE_ASSERT_NEVER_DOCUMENTATION = {
|
|
|
21762
21879
|
]
|
|
21763
21880
|
};
|
|
21764
21881
|
var isRuntimeHandlingStatement = (statement) => {
|
|
21765
|
-
if (statement.type ===
|
|
21766
|
-
if (statement.type ===
|
|
21882
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.EmptyStatement) return false;
|
|
21883
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.BreakStatement) {
|
|
21767
21884
|
return statement.label !== null;
|
|
21768
21885
|
}
|
|
21769
|
-
if (statement.type ===
|
|
21886
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.TSTypeAliasDeclaration || statement.type === import_utils118.AST_NODE_TYPES.TSInterfaceDeclaration) {
|
|
21770
21887
|
return false;
|
|
21771
21888
|
}
|
|
21772
|
-
if (statement.type ===
|
|
21889
|
+
if (statement.type === import_utils118.AST_NODE_TYPES.BlockStatement) {
|
|
21773
21890
|
return statement.body.some(isRuntimeHandlingStatement);
|
|
21774
21891
|
}
|
|
21775
21892
|
return true;
|
|
@@ -21785,7 +21902,7 @@ var isCommentOnlyNoopDefault = (defaultCase, sourceCode) => {
|
|
|
21785
21902
|
return colonToken !== null && sourceCode.getCommentsAfter(colonToken).length > 0;
|
|
21786
21903
|
}
|
|
21787
21904
|
const only = defaultCase.consequent[0];
|
|
21788
|
-
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type ===
|
|
21905
|
+
if (only !== void 0 && defaultCase.consequent.length === 1 && only.type === import_utils118.AST_NODE_TYPES.BlockStatement && !only.body.some(isRuntimeHandlingStatement)) {
|
|
21789
21906
|
return sourceCode.getCommentsInside(only).length > 0;
|
|
21790
21907
|
}
|
|
21791
21908
|
return false;
|
|
@@ -21839,7 +21956,7 @@ var require_assert_never_default = createRule({
|
|
|
21839
21956
|
create(context) {
|
|
21840
21957
|
let services;
|
|
21841
21958
|
try {
|
|
21842
|
-
services =
|
|
21959
|
+
services = import_utils118.ESLintUtils.getParserServices(context);
|
|
21843
21960
|
} catch {
|
|
21844
21961
|
services = null;
|
|
21845
21962
|
}
|
|
@@ -21866,7 +21983,7 @@ var require_assert_never_default = createRule({
|
|
|
21866
21983
|
});
|
|
21867
21984
|
|
|
21868
21985
|
// src/rules/require-fetch-timeout.ts
|
|
21869
|
-
var
|
|
21986
|
+
var import_utils119 = require("@typescript-eslint/utils");
|
|
21870
21987
|
var REQUIRE_FETCH_TIMEOUT_DOCUMENTATION = {
|
|
21871
21988
|
summary: "Require an explicit abort signal on locally analyzable global fetch calls.",
|
|
21872
21989
|
rationale: "An unbounded request can occupy work indefinitely when an upstream stalls.",
|
|
@@ -21893,18 +22010,18 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
21893
22010
|
return false;
|
|
21894
22011
|
}
|
|
21895
22012
|
function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
21896
|
-
if (init.type !==
|
|
22013
|
+
if (init.type !== import_utils119.AST_NODE_TYPES.ObjectExpression) return false;
|
|
21897
22014
|
let lacksSignal = true;
|
|
21898
22015
|
for (const prop of init.properties) {
|
|
21899
|
-
if (prop.type ===
|
|
22016
|
+
if (prop.type === import_utils119.AST_NODE_TYPES.SpreadElement) {
|
|
21900
22017
|
lacksSignal = false;
|
|
21901
22018
|
continue;
|
|
21902
22019
|
}
|
|
21903
|
-
const isSignal = !prop.computed && prop.key.type ===
|
|
22020
|
+
const isSignal = !prop.computed && prop.key.type === import_utils119.AST_NODE_TYPES.Identifier && prop.key.name === "signal" || prop.key.type === import_utils119.AST_NODE_TYPES.Literal && prop.key.value === "signal";
|
|
21904
22021
|
if (isSignal) {
|
|
21905
22022
|
const value = prop.value;
|
|
21906
|
-
lacksSignal = prop.kind === "init" && !prop.method && (value.type ===
|
|
21907
|
-
} else if (prop.computed && prop.key.type !==
|
|
22023
|
+
lacksSignal = prop.kind === "init" && !prop.method && (value.type === import_utils119.AST_NODE_TYPES.Literal && value.value === null || value.type === import_utils119.AST_NODE_TYPES.Identifier && value.name === "undefined" && resolvesToGlobal(value) || value.type === import_utils119.AST_NODE_TYPES.UnaryExpression && value.operator === "void" && value.argument.type === import_utils119.AST_NODE_TYPES.Literal && value.argument.value === 0);
|
|
22024
|
+
} else if (prop.computed && prop.key.type !== import_utils119.AST_NODE_TYPES.Literal) {
|
|
21908
22025
|
lacksSignal = false;
|
|
21909
22026
|
}
|
|
21910
22027
|
}
|
|
@@ -21912,7 +22029,7 @@ function initProvablyLacksSignal(init, resolvesToGlobal) {
|
|
|
21912
22029
|
}
|
|
21913
22030
|
function isInlineUrl(node, resolvesToGlobal) {
|
|
21914
22031
|
node = unwrapExpression(node);
|
|
21915
|
-
return node.type ===
|
|
22032
|
+
return node.type === import_utils119.AST_NODE_TYPES.Literal && typeof node.value === "string" || node.type === import_utils119.AST_NODE_TYPES.TemplateLiteral || node.type === import_utils119.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils119.AST_NODE_TYPES.Identifier && node.callee.name === "URL" && resolvesToGlobal(node.callee);
|
|
21916
22033
|
}
|
|
21917
22034
|
var require_fetch_timeout_default = createRule({
|
|
21918
22035
|
name: "require-fetch-timeout",
|
|
@@ -21950,30 +22067,30 @@ var require_fetch_timeout_default = createRule({
|
|
|
21950
22067
|
}
|
|
21951
22068
|
function resolvesToGlobal(identifier) {
|
|
21952
22069
|
const scope = context.sourceCode.getScope(identifier);
|
|
21953
|
-
const variable =
|
|
22070
|
+
const variable = import_utils119.ASTUtils.findVariable(scope, identifier.name);
|
|
21954
22071
|
return variable === null || variable.defs.length === 0;
|
|
21955
22072
|
}
|
|
21956
22073
|
function isGlobalFetchCall2(callee) {
|
|
21957
|
-
if (callee.type ===
|
|
22074
|
+
if (callee.type === import_utils119.AST_NODE_TYPES.Identifier) {
|
|
21958
22075
|
return callee.name === "fetch" && resolvesToGlobal(callee);
|
|
21959
22076
|
}
|
|
21960
|
-
return callee.type ===
|
|
22077
|
+
return callee.type === import_utils119.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils119.AST_NODE_TYPES.Identifier && callee.property.name === "fetch" && callee.object.type === import_utils119.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name) && resolvesToGlobal(callee.object);
|
|
21961
22078
|
}
|
|
21962
22079
|
function localConstInitProvablyLacksSignal(identifier) {
|
|
21963
|
-
const variable =
|
|
22080
|
+
const variable = import_utils119.ASTUtils.findVariable(
|
|
21964
22081
|
context.sourceCode.getScope(identifier),
|
|
21965
22082
|
identifier.name
|
|
21966
22083
|
);
|
|
21967
22084
|
if (variable?.defs.length !== 1) return false;
|
|
21968
22085
|
const definition = variable.defs[0];
|
|
21969
|
-
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !==
|
|
22086
|
+
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init?.type !== import_utils119.AST_NODE_TYPES.ObjectExpression || !initProvablyLacksSignal(definition.node.init, resolvesToGlobal)) {
|
|
21970
22087
|
return false;
|
|
21971
22088
|
}
|
|
21972
22089
|
for (const reference of variable.references) {
|
|
21973
22090
|
const ref = reference.identifier;
|
|
21974
22091
|
if (ref === identifier || ref === definition.name) continue;
|
|
21975
22092
|
const member = ref.parent;
|
|
21976
|
-
if (member.type !==
|
|
22093
|
+
if (member.type !== import_utils119.AST_NODE_TYPES.MemberExpression || member.object !== ref || member.computed || member.property.type !== import_utils119.AST_NODE_TYPES.Identifier || member.property.name === "signal" || member.parent.type !== import_utils119.AST_NODE_TYPES.AssignmentExpression || member.parent.left !== member) {
|
|
21977
22094
|
return false;
|
|
21978
22095
|
}
|
|
21979
22096
|
}
|
|
@@ -21981,13 +22098,13 @@ var require_fetch_timeout_default = createRule({
|
|
|
21981
22098
|
}
|
|
21982
22099
|
function isForwardedRequest(argument) {
|
|
21983
22100
|
let value = argument;
|
|
21984
|
-
if (value.type ===
|
|
21985
|
-
const binding =
|
|
22101
|
+
if (value.type === import_utils119.AST_NODE_TYPES.Identifier) {
|
|
22102
|
+
const binding = import_utils119.ASTUtils.findVariable(context.sourceCode.getScope(value), value.name);
|
|
21986
22103
|
const definition = binding?.defs.length === 1 ? binding.defs[0] : void 0;
|
|
21987
22104
|
if (definition?.type !== "Variable" || definition.parent.kind !== "const" || definition.node.init === null || binding?.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
21988
22105
|
value = definition.node.init;
|
|
21989
22106
|
}
|
|
21990
|
-
return value.type ===
|
|
22107
|
+
return value.type === import_utils119.AST_NODE_TYPES.NewExpression && value.callee.type === import_utils119.AST_NODE_TYPES.Identifier && value.callee.name === "Request" && resolvesToGlobal(value.callee);
|
|
21991
22108
|
}
|
|
21992
22109
|
return {
|
|
21993
22110
|
CallExpression(node) {
|
|
@@ -21999,7 +22116,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
21999
22116
|
if (first !== void 0 && (node.arguments.length === 1 && !isInlineUrl(first, resolvesToGlobal) || isForwardedRequest(first))) {
|
|
22000
22117
|
return;
|
|
22001
22118
|
}
|
|
22002
|
-
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type ===
|
|
22119
|
+
if (init === void 0 || initProvablyLacksSignal(init, resolvesToGlobal) || init.type === import_utils119.AST_NODE_TYPES.Identifier && localConstInitProvablyLacksSignal(init)) {
|
|
22003
22120
|
context.report({ node, messageId: "missingSignal" });
|
|
22004
22121
|
}
|
|
22005
22122
|
}
|
|
@@ -22008,7 +22125,7 @@ var require_fetch_timeout_default = createRule({
|
|
|
22008
22125
|
});
|
|
22009
22126
|
|
|
22010
22127
|
// src/rules/require-interface-for-exported-class.ts
|
|
22011
|
-
var
|
|
22128
|
+
var import_utils120 = require("@typescript-eslint/utils");
|
|
22012
22129
|
var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
22013
22130
|
defaultLevel: "warning",
|
|
22014
22131
|
summary: "Require exported concrete classes with public behavior to declare a contract.",
|
|
@@ -22055,23 +22172,23 @@ var REQUIRE_INTERFACE_FOR_EXPORTED_CLASS_DOCUMENTATION = {
|
|
|
22055
22172
|
};
|
|
22056
22173
|
function hasPublicInstanceBehavior(node) {
|
|
22057
22174
|
return node.body.body.some((member) => {
|
|
22058
|
-
if (member.type ===
|
|
22059
|
-
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !==
|
|
22175
|
+
if (member.type === import_utils120.AST_NODE_TYPES.MethodDefinition) {
|
|
22176
|
+
return member.kind !== "constructor" && !member.static && member.accessibility !== "private" && member.accessibility !== "protected" && member.key.type !== import_utils120.AST_NODE_TYPES.PrivateIdentifier;
|
|
22060
22177
|
}
|
|
22061
|
-
if (member.type !==
|
|
22178
|
+
if (member.type !== import_utils120.AST_NODE_TYPES.PropertyDefinition || member.static)
|
|
22062
22179
|
return false;
|
|
22063
|
-
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type ===
|
|
22064
|
-
return member.value?.type ===
|
|
22180
|
+
if (member.accessibility === "private" || member.accessibility === "protected" || member.key.type === import_utils120.AST_NODE_TYPES.PrivateIdentifier) return false;
|
|
22181
|
+
return member.value?.type === import_utils120.AST_NODE_TYPES.ArrowFunctionExpression || member.value?.type === import_utils120.AST_NODE_TYPES.FunctionExpression || member.typeAnnotation?.typeAnnotation.type === import_utils120.AST_NODE_TYPES.TSFunctionType;
|
|
22065
22182
|
});
|
|
22066
22183
|
}
|
|
22067
22184
|
function classBindings(statement) {
|
|
22068
|
-
const declaration = statement.type ===
|
|
22069
|
-
if (declaration?.type ===
|
|
22185
|
+
const declaration = statement.type === import_utils120.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
22186
|
+
if (declaration?.type === import_utils120.AST_NODE_TYPES.ClassDeclaration) {
|
|
22070
22187
|
return declaration.id === null ? [] : [{ declaration, name: declaration.id.name }];
|
|
22071
22188
|
}
|
|
22072
|
-
if (declaration?.type !==
|
|
22189
|
+
if (declaration?.type !== import_utils120.AST_NODE_TYPES.VariableDeclaration) return [];
|
|
22073
22190
|
return declaration.declarations.flatMap(
|
|
22074
|
-
(item) => item.id.type ===
|
|
22191
|
+
(item) => item.id.type === import_utils120.AST_NODE_TYPES.Identifier && item.init?.type === import_utils120.AST_NODE_TYPES.ClassExpression ? [{ declaration: item.init, name: item.id.name }] : []
|
|
22075
22192
|
);
|
|
22076
22193
|
}
|
|
22077
22194
|
var require_interface_for_exported_class_default = createRule({
|
|
@@ -22105,7 +22222,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
22105
22222
|
}
|
|
22106
22223
|
const exported = exportedClasses(program, classes);
|
|
22107
22224
|
for (const [declaration, exportedName] of exported) {
|
|
22108
|
-
const extendsLocalAbstractBase = declaration.superClass?.type ===
|
|
22225
|
+
const extendsLocalAbstractBase = declaration.superClass?.type === import_utils120.AST_NODE_TYPES.Identifier && abstractBases.has(declaration.superClass.name);
|
|
22109
22226
|
if (declaration.abstract || declaration.implements.length > 0 || extendsLocalAbstractBase || !hasPublicInstanceBehavior(declaration)) continue;
|
|
22110
22227
|
context.report({
|
|
22111
22228
|
node: declaration.id ?? declaration,
|
|
@@ -22120,7 +22237,7 @@ var require_interface_for_exported_class_default = createRule({
|
|
|
22120
22237
|
function exportedClasses(program, classes) {
|
|
22121
22238
|
const exported = /* @__PURE__ */ new Map();
|
|
22122
22239
|
function collectExportedClass(statement) {
|
|
22123
|
-
if (statement.type ===
|
|
22240
|
+
if (statement.type === import_utils120.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
22124
22241
|
for (const binding of classBindings(statement)) {
|
|
22125
22242
|
exported.set(binding.declaration, binding.name);
|
|
22126
22243
|
}
|
|
@@ -22128,13 +22245,13 @@ function exportedClasses(program, classes) {
|
|
|
22128
22245
|
collectClassSpecifiers(statement);
|
|
22129
22246
|
return;
|
|
22130
22247
|
}
|
|
22131
|
-
if (statement.type !==
|
|
22132
|
-
if (statement.declaration.type ===
|
|
22248
|
+
if (statement.type !== import_utils120.AST_NODE_TYPES.ExportDefaultDeclaration) return;
|
|
22249
|
+
if (statement.declaration.type === import_utils120.AST_NODE_TYPES.ClassDeclaration || statement.declaration.type === import_utils120.AST_NODE_TYPES.ClassExpression) {
|
|
22133
22250
|
exported.set(
|
|
22134
22251
|
statement.declaration,
|
|
22135
22252
|
statement.declaration.id?.name ?? "default"
|
|
22136
22253
|
);
|
|
22137
|
-
} else if (statement.declaration.type ===
|
|
22254
|
+
} else if (statement.declaration.type === import_utils120.AST_NODE_TYPES.Identifier) {
|
|
22138
22255
|
const candidate2 = classes.get(statement.declaration.name);
|
|
22139
22256
|
if (candidate2 !== void 0) {
|
|
22140
22257
|
exported.set(candidate2, statement.declaration.name);
|
|
@@ -22146,7 +22263,7 @@ function exportedClasses(program, classes) {
|
|
|
22146
22263
|
if (specifier.exportKind === "type") continue;
|
|
22147
22264
|
const candidate2 = classes.get(specifier.local.name);
|
|
22148
22265
|
if (candidate2 === void 0) continue;
|
|
22149
|
-
const exportedName = specifier.exported.type ===
|
|
22266
|
+
const exportedName = specifier.exported.type === import_utils120.AST_NODE_TYPES.Identifier ? specifier.exported.name : specifier.exported.value;
|
|
22150
22267
|
exported.set(candidate2, exportedName);
|
|
22151
22268
|
}
|
|
22152
22269
|
}
|
|
@@ -22157,7 +22274,7 @@ function exportedClasses(program, classes) {
|
|
|
22157
22274
|
}
|
|
22158
22275
|
|
|
22159
22276
|
// src/rules/require-sql-access-class.ts
|
|
22160
|
-
var
|
|
22277
|
+
var import_utils121 = require("@typescript-eslint/utils");
|
|
22161
22278
|
var DIRECT_EXECUTION_METHODS = /* @__PURE__ */ new Set([
|
|
22162
22279
|
"all",
|
|
22163
22280
|
"batch",
|
|
@@ -22261,80 +22378,80 @@ function isDatabaseOperation(method, receiver) {
|
|
|
22261
22378
|
}
|
|
22262
22379
|
function databaseReceiver(node) {
|
|
22263
22380
|
node = unwrapExpression(node);
|
|
22264
|
-
if (node.type ===
|
|
22381
|
+
if (node.type === import_utils121.AST_NODE_TYPES.Identifier)
|
|
22265
22382
|
return DATABASE_NAMES.test(node.name);
|
|
22266
|
-
if (node.type !==
|
|
22267
|
-
const name =
|
|
22383
|
+
if (node.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22384
|
+
const name = import_utils121.ASTUtils.getPropertyName(node);
|
|
22268
22385
|
return name === "DB" || name !== null && DATABASE_NAMES.test(name);
|
|
22269
22386
|
}
|
|
22270
22387
|
function databaseRootMember(node) {
|
|
22271
22388
|
let current = node;
|
|
22272
22389
|
for (; ; ) {
|
|
22273
22390
|
current = unwrapExpression(current);
|
|
22274
|
-
if (current.type ===
|
|
22391
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ChainExpression) {
|
|
22275
22392
|
current = current.expression;
|
|
22276
22393
|
continue;
|
|
22277
22394
|
}
|
|
22278
|
-
if (current.type ===
|
|
22279
|
-
if (current.callee.type !==
|
|
22395
|
+
if (current.type === import_utils121.AST_NODE_TYPES.CallExpression) {
|
|
22396
|
+
if (current.callee.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return null;
|
|
22280
22397
|
current = current.callee.object;
|
|
22281
22398
|
continue;
|
|
22282
22399
|
}
|
|
22283
|
-
if (current.type ===
|
|
22284
|
-
if (current.object.type ===
|
|
22285
|
-
return
|
|
22400
|
+
if (current.type === import_utils121.AST_NODE_TYPES.MemberExpression) {
|
|
22401
|
+
if (current.object.type === import_utils121.AST_NODE_TYPES.ThisExpression)
|
|
22402
|
+
return import_utils121.ASTUtils.getPropertyName(current);
|
|
22286
22403
|
current = current.object;
|
|
22287
22404
|
continue;
|
|
22288
22405
|
}
|
|
22289
|
-
return current.type ===
|
|
22406
|
+
return current.type === import_utils121.AST_NODE_TYPES.Identifier ? current.name : null;
|
|
22290
22407
|
}
|
|
22291
22408
|
}
|
|
22292
22409
|
function expressionHasDatabaseMarker(node) {
|
|
22293
22410
|
let current = node;
|
|
22294
22411
|
for (; ; ) {
|
|
22295
22412
|
current = unwrapExpression(current);
|
|
22296
|
-
if (current.type ===
|
|
22413
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ChainExpression) {
|
|
22297
22414
|
current = current.expression;
|
|
22298
22415
|
continue;
|
|
22299
22416
|
}
|
|
22300
|
-
if (current.type ===
|
|
22301
|
-
if (current.callee.type !==
|
|
22417
|
+
if (current.type === import_utils121.AST_NODE_TYPES.CallExpression) {
|
|
22418
|
+
if (current.callee.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22302
22419
|
current = current.callee.object;
|
|
22303
22420
|
continue;
|
|
22304
22421
|
}
|
|
22305
|
-
if (current.type ===
|
|
22306
|
-
const name =
|
|
22422
|
+
if (current.type === import_utils121.AST_NODE_TYPES.MemberExpression) {
|
|
22423
|
+
const name = import_utils121.ASTUtils.getPropertyName(current);
|
|
22307
22424
|
if (name === "DB" || name !== null && DATABASE_NAMES.test(name))
|
|
22308
22425
|
return true;
|
|
22309
22426
|
current = current.object;
|
|
22310
22427
|
continue;
|
|
22311
22428
|
}
|
|
22312
|
-
return current.type ===
|
|
22429
|
+
return current.type === import_utils121.AST_NODE_TYPES.Identifier && DATABASE_NAMES.test(current.name);
|
|
22313
22430
|
}
|
|
22314
22431
|
}
|
|
22315
22432
|
function expressionCallsBuilder(node) {
|
|
22316
22433
|
let current = node;
|
|
22317
22434
|
for (; ; ) {
|
|
22318
22435
|
current = unwrapExpression(current);
|
|
22319
|
-
if (current.type ===
|
|
22436
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ChainExpression) {
|
|
22320
22437
|
current = current.expression;
|
|
22321
22438
|
continue;
|
|
22322
22439
|
}
|
|
22323
|
-
if (current.type ===
|
|
22324
|
-
if (current.callee.type !==
|
|
22325
|
-
const name =
|
|
22440
|
+
if (current.type === import_utils121.AST_NODE_TYPES.CallExpression) {
|
|
22441
|
+
if (current.callee.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22442
|
+
const name = import_utils121.ASTUtils.getPropertyName(current.callee);
|
|
22326
22443
|
if (name !== null && BUILDER_METHODS.has(name)) return true;
|
|
22327
22444
|
current = current.callee.object;
|
|
22328
22445
|
continue;
|
|
22329
22446
|
}
|
|
22330
|
-
if (current.type !==
|
|
22447
|
+
if (current.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return false;
|
|
22331
22448
|
current = current.object;
|
|
22332
22449
|
}
|
|
22333
22450
|
}
|
|
22334
22451
|
function owningClass2(node) {
|
|
22335
22452
|
let current = node.parent;
|
|
22336
22453
|
while (current != null) {
|
|
22337
|
-
if (current.type ===
|
|
22454
|
+
if (current.type === import_utils121.AST_NODE_TYPES.ClassDeclaration || current.type === import_utils121.AST_NODE_TYPES.ClassExpression)
|
|
22338
22455
|
return current;
|
|
22339
22456
|
current = current.parent;
|
|
22340
22457
|
}
|
|
@@ -22343,25 +22460,25 @@ function owningClass2(node) {
|
|
|
22343
22460
|
function injectedMembers(owner) {
|
|
22344
22461
|
const injected = /* @__PURE__ */ new Set();
|
|
22345
22462
|
const constructor = owner.body.body.find(
|
|
22346
|
-
(member) => member.type ===
|
|
22463
|
+
(member) => member.type === import_utils121.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
22347
22464
|
);
|
|
22348
22465
|
if (constructor === void 0) return injected;
|
|
22349
22466
|
const parameters = /* @__PURE__ */ new Set();
|
|
22350
22467
|
for (const parameter of constructor.value.params) {
|
|
22351
22468
|
for (const name of parameterNames(parameter)) parameters.add(name);
|
|
22352
|
-
if (parameter.type !==
|
|
22353
|
-
const value = parameter.parameter.type ===
|
|
22354
|
-
if (value.type ===
|
|
22469
|
+
if (parameter.type !== import_utils121.AST_NODE_TYPES.TSParameterProperty) continue;
|
|
22470
|
+
const value = parameter.parameter.type === import_utils121.AST_NODE_TYPES.AssignmentPattern ? parameter.parameter.left : parameter.parameter;
|
|
22471
|
+
if (value.type === import_utils121.AST_NODE_TYPES.Identifier) injected.add(value.name);
|
|
22355
22472
|
}
|
|
22356
22473
|
const body2 = constructor.value.body;
|
|
22357
22474
|
if (body2 === null) return injected;
|
|
22358
22475
|
function collectInjectedMember(statement) {
|
|
22359
|
-
if (statement.type !==
|
|
22476
|
+
if (statement.type !== import_utils121.AST_NODE_TYPES.ExpressionStatement || statement.expression.type !== import_utils121.AST_NODE_TYPES.AssignmentExpression || statement.expression.operator !== "=") return;
|
|
22360
22477
|
const { left, right } = statement.expression;
|
|
22361
|
-
if (left.type !==
|
|
22478
|
+
if (left.type !== import_utils121.AST_NODE_TYPES.MemberExpression) return;
|
|
22362
22479
|
const target = thisRootMember(left);
|
|
22363
22480
|
if (target === null) return;
|
|
22364
|
-
const source = right.type ===
|
|
22481
|
+
const source = right.type === import_utils121.AST_NODE_TYPES.Identifier ? right.name : right.type === import_utils121.AST_NODE_TYPES.MemberExpression && right.object.type === import_utils121.AST_NODE_TYPES.Identifier ? right.object.name : null;
|
|
22365
22482
|
if (source !== null && parameters.has(source)) injected.add(target);
|
|
22366
22483
|
}
|
|
22367
22484
|
for (const statement of body2.body) {
|
|
@@ -22372,26 +22489,26 @@ function injectedMembers(owner) {
|
|
|
22372
22489
|
function thisRootMember(node) {
|
|
22373
22490
|
let current = node;
|
|
22374
22491
|
let root = null;
|
|
22375
|
-
while (current.type ===
|
|
22376
|
-
const name =
|
|
22492
|
+
while (current.type === import_utils121.AST_NODE_TYPES.MemberExpression) {
|
|
22493
|
+
const name = import_utils121.ASTUtils.getPropertyName(current);
|
|
22377
22494
|
if (name === null) return null;
|
|
22378
22495
|
root = name;
|
|
22379
22496
|
current = current.object;
|
|
22380
22497
|
}
|
|
22381
|
-
return current.type ===
|
|
22498
|
+
return current.type === import_utils121.AST_NODE_TYPES.ThisExpression ? root : null;
|
|
22382
22499
|
}
|
|
22383
22500
|
function parameterNames(parameter) {
|
|
22384
22501
|
let value = parameter;
|
|
22385
|
-
if (value.type ===
|
|
22386
|
-
if (value.type ===
|
|
22387
|
-
if (value.type ===
|
|
22388
|
-
if (value.type !==
|
|
22502
|
+
if (value.type === import_utils121.AST_NODE_TYPES.TSParameterProperty) value = value.parameter;
|
|
22503
|
+
if (value.type === import_utils121.AST_NODE_TYPES.AssignmentPattern) value = value.left;
|
|
22504
|
+
if (value.type === import_utils121.AST_NODE_TYPES.Identifier) return /* @__PURE__ */ new Set([value.name]);
|
|
22505
|
+
if (value.type !== import_utils121.AST_NODE_TYPES.ObjectPattern) return /* @__PURE__ */ new Set();
|
|
22389
22506
|
return new Set(
|
|
22390
22507
|
value.properties.flatMap((property) => {
|
|
22391
|
-
if (property.type ===
|
|
22392
|
-
return property.argument.type ===
|
|
22393
|
-
const target = property.value.type ===
|
|
22394
|
-
return target.type ===
|
|
22508
|
+
if (property.type === import_utils121.AST_NODE_TYPES.RestElement)
|
|
22509
|
+
return property.argument.type === import_utils121.AST_NODE_TYPES.Identifier ? [property.argument.name] : [];
|
|
22510
|
+
const target = property.value.type === import_utils121.AST_NODE_TYPES.AssignmentPattern ? property.value.left : property.value;
|
|
22511
|
+
return target.type === import_utils121.AST_NODE_TYPES.Identifier ? [target.name] : [];
|
|
22395
22512
|
})
|
|
22396
22513
|
);
|
|
22397
22514
|
}
|
|
@@ -22416,20 +22533,20 @@ var require_sql_access_class_default = createRule({
|
|
|
22416
22533
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22417
22534
|
if (seen.has(node)) return false;
|
|
22418
22535
|
seen.add(node);
|
|
22419
|
-
if (node.type ===
|
|
22420
|
-
const binding =
|
|
22536
|
+
if (node.type === import_utils121.AST_NODE_TYPES.Identifier) {
|
|
22537
|
+
const binding = import_utils121.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
22421
22538
|
if (binding?.defs.length !== 1 || binding.references.some((reference) => reference.isWrite() && reference.init !== true)) return false;
|
|
22422
22539
|
const definition = binding.defs[0];
|
|
22423
22540
|
return definition?.type === "Variable" && definition.node.init !== null && knownNonDatabase(definition.node.init, seen);
|
|
22424
22541
|
}
|
|
22425
|
-
return node.type ===
|
|
22542
|
+
return node.type === import_utils121.AST_NODE_TYPES.NewExpression && unwrappedNodeCallee?.type === import_utils121.AST_NODE_TYPES.Identifier && ["Map", "WeakMap", "URLSearchParams"].includes(unwrappedNodeCallee.name) && (import_utils121.ASTUtils.findVariable(context.sourceCode.getScope(unwrappedNodeCallee), unwrappedNodeCallee.name)?.defs.length ?? 0) === 0;
|
|
22426
22543
|
}
|
|
22427
22544
|
return {
|
|
22428
22545
|
CallExpression(node) {
|
|
22429
22546
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22430
|
-
if (unwrappedNodeCallee.type !==
|
|
22547
|
+
if (unwrappedNodeCallee.type !== import_utils121.AST_NODE_TYPES.MemberExpression)
|
|
22431
22548
|
return;
|
|
22432
|
-
const method =
|
|
22549
|
+
const method = import_utils121.ASTUtils.getPropertyName(unwrappedNodeCallee);
|
|
22433
22550
|
if (knownNonDatabase(unwrappedNodeCallee.object)) return;
|
|
22434
22551
|
if (method === null || !isDatabaseOperation(method, unwrappedNodeCallee.object))
|
|
22435
22552
|
return;
|
|
@@ -22445,7 +22562,7 @@ var require_sql_access_class_default = createRule({
|
|
|
22445
22562
|
});
|
|
22446
22563
|
|
|
22447
22564
|
// src/rules/require-static-next-matcher.ts
|
|
22448
|
-
var
|
|
22565
|
+
var import_utils122 = require("@typescript-eslint/utils");
|
|
22449
22566
|
var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
22450
22567
|
summary: "Require Next.js middleware and proxy matcher configuration to contain only build-time literals.",
|
|
22451
22568
|
rationale: "Next.js must statically analyze matcher values at build time; computed values are ignored.",
|
|
@@ -22461,27 +22578,27 @@ var REQUIRE_STATIC_NEXT_MATCHER_DOCUMENTATION = {
|
|
|
22461
22578
|
var NEXT_ENTRY_FILE = /(?:^|[/\\])(?:middleware|proxy)\.[cm]?[jt]sx?$/u;
|
|
22462
22579
|
function isStaticValue(node) {
|
|
22463
22580
|
const value = unwrapExpression(node);
|
|
22464
|
-
if (value.type ===
|
|
22581
|
+
if (value.type === import_utils122.AST_NODE_TYPES.Literal) {
|
|
22465
22582
|
return true;
|
|
22466
22583
|
}
|
|
22467
|
-
if (value.type ===
|
|
22584
|
+
if (value.type === import_utils122.AST_NODE_TYPES.TemplateLiteral) {
|
|
22468
22585
|
return value.expressions.length === 0;
|
|
22469
22586
|
}
|
|
22470
|
-
if (value.type ===
|
|
22587
|
+
if (value.type === import_utils122.AST_NODE_TYPES.ArrayExpression) {
|
|
22471
22588
|
return value.elements.every(
|
|
22472
|
-
(element) => element !== null && element.type !==
|
|
22589
|
+
(element) => element !== null && element.type !== import_utils122.AST_NODE_TYPES.SpreadElement && isStaticValue(element)
|
|
22473
22590
|
);
|
|
22474
22591
|
}
|
|
22475
|
-
if (value.type ===
|
|
22592
|
+
if (value.type === import_utils122.AST_NODE_TYPES.ObjectExpression) {
|
|
22476
22593
|
return value.properties.every(
|
|
22477
|
-
(property) => property.type ===
|
|
22594
|
+
(property) => property.type === import_utils122.AST_NODE_TYPES.Property && property.kind === "init" && !property.computed && property.value.type !== import_utils122.AST_NODE_TYPES.AssignmentPattern && isStaticValue(property.value)
|
|
22478
22595
|
);
|
|
22479
22596
|
}
|
|
22480
22597
|
return false;
|
|
22481
22598
|
}
|
|
22482
22599
|
function propertyName5(property) {
|
|
22483
|
-
if (!property.computed && property.key.type ===
|
|
22484
|
-
return property.key.type ===
|
|
22600
|
+
if (!property.computed && property.key.type === import_utils122.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
22601
|
+
return property.key.type === import_utils122.AST_NODE_TYPES.Literal && typeof property.key.value === "string" ? property.key.value : null;
|
|
22485
22602
|
}
|
|
22486
22603
|
var require_static_next_matcher_default = createRule({
|
|
22487
22604
|
name: "require-static-next-matcher",
|
|
@@ -22503,19 +22620,19 @@ var require_static_next_matcher_default = createRule({
|
|
|
22503
22620
|
}
|
|
22504
22621
|
return {
|
|
22505
22622
|
ExportNamedDeclaration(node) {
|
|
22506
|
-
if (node.declaration?.type !==
|
|
22623
|
+
if (node.declaration?.type !== import_utils122.AST_NODE_TYPES.VariableDeclaration) {
|
|
22507
22624
|
return;
|
|
22508
22625
|
}
|
|
22509
22626
|
for (const declaration of node.declaration.declarations) {
|
|
22510
|
-
if (declaration.id.type !==
|
|
22627
|
+
if (declaration.id.type !== import_utils122.AST_NODE_TYPES.Identifier || declaration.id.name !== "config" || declaration.init === null) {
|
|
22511
22628
|
continue;
|
|
22512
22629
|
}
|
|
22513
22630
|
const config = unwrapExpression(declaration.init);
|
|
22514
|
-
if (config.type !==
|
|
22631
|
+
if (config.type !== import_utils122.AST_NODE_TYPES.ObjectExpression) {
|
|
22515
22632
|
continue;
|
|
22516
22633
|
}
|
|
22517
22634
|
for (const property of config.properties) {
|
|
22518
|
-
if (property.type !==
|
|
22635
|
+
if (property.type !== import_utils122.AST_NODE_TYPES.Property || propertyName5(property) !== "matcher" || property.value.type === import_utils122.AST_NODE_TYPES.AssignmentPattern) {
|
|
22519
22636
|
continue;
|
|
22520
22637
|
}
|
|
22521
22638
|
if (!isStaticValue(property.value)) {
|
|
@@ -22529,7 +22646,7 @@ var require_static_next_matcher_default = createRule({
|
|
|
22529
22646
|
});
|
|
22530
22647
|
|
|
22531
22648
|
// src/rules/require-use-form-default-values.ts
|
|
22532
|
-
var
|
|
22649
|
+
var import_utils123 = require("@typescript-eslint/utils");
|
|
22533
22650
|
var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
22534
22651
|
summary: "Require explicit form-level initialization or a field default for directly bound Controller fields.",
|
|
22535
22652
|
rationale: "React Hook Form exposes form-level defaultValues/values and field-level defaultValue as its explicit initialization mechanisms. A directly bound controlled field should not omit both mechanisms.",
|
|
@@ -22562,8 +22679,8 @@ var REQUIRE_USE_FORM_DEFAULT_VALUES_DOCUMENTATION = {
|
|
|
22562
22679
|
};
|
|
22563
22680
|
function staticPropertyName2(property) {
|
|
22564
22681
|
if (property.computed) return null;
|
|
22565
|
-
if (property.key.type ===
|
|
22566
|
-
if (property.key.type ===
|
|
22682
|
+
if (property.key.type === import_utils123.AST_NODE_TYPES.Identifier) return property.key.name;
|
|
22683
|
+
if (property.key.type === import_utils123.AST_NODE_TYPES.Literal && typeof property.key.value === "string") return property.key.value;
|
|
22567
22684
|
return null;
|
|
22568
22685
|
}
|
|
22569
22686
|
var require_use_form_default_values_default = createRule({
|
|
@@ -22580,7 +22697,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
22580
22697
|
const imported = /* @__PURE__ */ new Map();
|
|
22581
22698
|
const uninitializedForms = /* @__PURE__ */ new Set();
|
|
22582
22699
|
const uninitializedControls = /* @__PURE__ */ new Set();
|
|
22583
|
-
const bindingNamed = (node, name) =>
|
|
22700
|
+
const bindingNamed = (node, name) => import_utils123.ASTUtils.findVariable(context.sourceCode.getScope(node), name);
|
|
22584
22701
|
const bindingOf = (node) => bindingNamed(node, node.name);
|
|
22585
22702
|
const stable = (variable) => !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
22586
22703
|
const importedKind = (node) => {
|
|
@@ -22593,22 +22710,22 @@ var require_use_form_default_values_default = createRule({
|
|
|
22593
22710
|
};
|
|
22594
22711
|
const isDefinitelyUndefined = (node) => {
|
|
22595
22712
|
const value = unwrapExpression(node);
|
|
22596
|
-
return value.type ===
|
|
22713
|
+
return value.type === import_utils123.AST_NODE_TYPES.UnaryExpression && value.operator === "void" || value.type === import_utils123.AST_NODE_TYPES.Identifier && value.name === "undefined" && (bindingOf(value)?.defs.length ?? 0) === 0;
|
|
22597
22714
|
};
|
|
22598
22715
|
const uninitializedUseFormCall = (node) => {
|
|
22599
22716
|
node = unwrapExpression(node);
|
|
22600
22717
|
const unwrappedNodeCallee = node.type === "CallExpression" || node.type === "NewExpression" ? unwrapExpression(node.callee) : null;
|
|
22601
|
-
if (node.type !==
|
|
22718
|
+
if (node.type !== import_utils123.AST_NODE_TYPES.CallExpression || unwrappedNodeCallee?.type !== import_utils123.AST_NODE_TYPES.Identifier || importedKind(unwrappedNodeCallee) !== "useForm") return false;
|
|
22602
22719
|
const options = node.arguments[0];
|
|
22603
|
-
return options?.type !==
|
|
22720
|
+
return options?.type !== import_utils123.AST_NODE_TYPES.SpreadElement && initializationState(options) === "uninitialized";
|
|
22604
22721
|
};
|
|
22605
22722
|
const initializationState = (node) => {
|
|
22606
22723
|
if (node === void 0) return "uninitialized";
|
|
22607
|
-
if (node.type !==
|
|
22724
|
+
if (node.type !== import_utils123.AST_NODE_TYPES.ObjectExpression) return "unknown";
|
|
22608
22725
|
const initialization = /* @__PURE__ */ new Map();
|
|
22609
22726
|
for (const property of node.properties) {
|
|
22610
|
-
if (property.type ===
|
|
22611
|
-
if (property.type !==
|
|
22727
|
+
if (property.type === import_utils123.AST_NODE_TYPES.SpreadElement || property.computed) return "unknown";
|
|
22728
|
+
if (property.type !== import_utils123.AST_NODE_TYPES.Property) continue;
|
|
22612
22729
|
const name = staticPropertyName2(property);
|
|
22613
22730
|
if (name === "defaultValues" || name === "values") initialization.set(name, !isDefinitelyUndefined(property.value));
|
|
22614
22731
|
}
|
|
@@ -22616,25 +22733,25 @@ var require_use_form_default_values_default = createRule({
|
|
|
22616
22733
|
};
|
|
22617
22734
|
const isUninitializedForm = (node) => {
|
|
22618
22735
|
node = unwrapExpression(node);
|
|
22619
|
-
if (node.type !==
|
|
22736
|
+
if (node.type !== import_utils123.AST_NODE_TYPES.Identifier) return false;
|
|
22620
22737
|
const variable = bindingOf(node);
|
|
22621
22738
|
return variable !== null && stable(variable) && uninitializedForms.has(variable);
|
|
22622
22739
|
};
|
|
22623
22740
|
const isUninitializedControl = (node) => {
|
|
22624
22741
|
node = unwrapExpression(node);
|
|
22625
|
-
if (node.type ===
|
|
22742
|
+
if (node.type === import_utils123.AST_NODE_TYPES.Identifier) {
|
|
22626
22743
|
const variable = bindingOf(node);
|
|
22627
22744
|
return variable !== null && stable(variable) && uninitializedControls.has(variable);
|
|
22628
22745
|
}
|
|
22629
|
-
return node.type ===
|
|
22746
|
+
return node.type === import_utils123.AST_NODE_TYPES.MemberExpression && import_utils123.ASTUtils.getPropertyName(node) !== null && (import_utils123.ASTUtils.getPropertyName(node) ?? "") === "control" && isUninitializedForm(node.object);
|
|
22630
22747
|
};
|
|
22631
22748
|
const fieldOptionsNeedDefault = (node) => {
|
|
22632
|
-
if (node?.type !==
|
|
22749
|
+
if (node?.type !== import_utils123.AST_NODE_TYPES.ObjectExpression) return false;
|
|
22633
22750
|
let control = null;
|
|
22634
22751
|
let hasDefault = false;
|
|
22635
22752
|
for (const property of node.properties) {
|
|
22636
|
-
if (property.type ===
|
|
22637
|
-
if (property.type !==
|
|
22753
|
+
if (property.type === import_utils123.AST_NODE_TYPES.SpreadElement || property.computed) return false;
|
|
22754
|
+
if (property.type !== import_utils123.AST_NODE_TYPES.Property) continue;
|
|
22638
22755
|
const name = staticPropertyName2(property);
|
|
22639
22756
|
if (name === "control") control = property.value;
|
|
22640
22757
|
if (name === "defaultValue") hasDefault = !isDefinitelyUndefined(property.value);
|
|
@@ -22644,14 +22761,14 @@ var require_use_form_default_values_default = createRule({
|
|
|
22644
22761
|
const jsxAttribute = (node, name) => {
|
|
22645
22762
|
let result = null;
|
|
22646
22763
|
for (const attribute of node.attributes) {
|
|
22647
|
-
if (attribute.type ===
|
|
22648
|
-
if (attribute.name.type ===
|
|
22764
|
+
if (attribute.type === import_utils123.AST_NODE_TYPES.JSXSpreadAttribute) return null;
|
|
22765
|
+
if (attribute.name.type === import_utils123.AST_NODE_TYPES.JSXIdentifier && attribute.name.name === name) result = attribute;
|
|
22649
22766
|
}
|
|
22650
22767
|
return result;
|
|
22651
22768
|
};
|
|
22652
22769
|
const trackDestructuredControl = (pattern) => {
|
|
22653
22770
|
for (const property of pattern.properties) {
|
|
22654
|
-
if (property.type !==
|
|
22771
|
+
if (property.type !== import_utils123.AST_NODE_TYPES.Property || staticPropertyName2(property) !== "control" || property.value.type !== import_utils123.AST_NODE_TYPES.Identifier) continue;
|
|
22655
22772
|
const variable = bindingOf(property.value);
|
|
22656
22773
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22657
22774
|
}
|
|
@@ -22660,8 +22777,8 @@ var require_use_form_default_values_default = createRule({
|
|
|
22660
22777
|
ImportDeclaration(node) {
|
|
22661
22778
|
if (node.source.value !== "react-hook-form") return;
|
|
22662
22779
|
for (const specifier of node.specifiers) {
|
|
22663
|
-
if (specifier.type !==
|
|
22664
|
-
const name = specifier.imported.type ===
|
|
22780
|
+
if (specifier.type !== import_utils123.AST_NODE_TYPES.ImportSpecifier) continue;
|
|
22781
|
+
const name = specifier.imported.type === import_utils123.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
22665
22782
|
if (name !== "Controller" && name !== "useController" && name !== "useForm") continue;
|
|
22666
22783
|
const variable = bindingOf(specifier.local);
|
|
22667
22784
|
if (variable !== null) imported.set(variable, name);
|
|
@@ -22670,35 +22787,35 @@ var require_use_form_default_values_default = createRule({
|
|
|
22670
22787
|
VariableDeclarator(node) {
|
|
22671
22788
|
if (node.init === null) return;
|
|
22672
22789
|
if (uninitializedUseFormCall(node.init)) {
|
|
22673
|
-
if (node.id.type ===
|
|
22790
|
+
if (node.id.type === import_utils123.AST_NODE_TYPES.Identifier) {
|
|
22674
22791
|
const variable = bindingOf(node.id);
|
|
22675
22792
|
if (variable !== null) uninitializedForms.add(variable);
|
|
22676
|
-
} else if (node.id.type ===
|
|
22793
|
+
} else if (node.id.type === import_utils123.AST_NODE_TYPES.ObjectPattern) {
|
|
22677
22794
|
trackDestructuredControl(node.id);
|
|
22678
22795
|
}
|
|
22679
22796
|
return;
|
|
22680
22797
|
}
|
|
22681
|
-
if (node.id.type ===
|
|
22798
|
+
if (node.id.type === import_utils123.AST_NODE_TYPES.ObjectPattern && isUninitializedForm(node.init)) {
|
|
22682
22799
|
trackDestructuredControl(node.id);
|
|
22683
22800
|
return;
|
|
22684
22801
|
}
|
|
22685
|
-
if (node.id.type ===
|
|
22802
|
+
if (node.id.type === import_utils123.AST_NODE_TYPES.Identifier && node.init.type === import_utils123.AST_NODE_TYPES.MemberExpression && import_utils123.ASTUtils.getPropertyName(node.init) !== null && (import_utils123.ASTUtils.getPropertyName(node.init) ?? "") === "control" && isUninitializedForm(node.init.object)) {
|
|
22686
22803
|
const variable = bindingOf(node.id);
|
|
22687
22804
|
if (variable !== null) uninitializedControls.add(variable);
|
|
22688
22805
|
}
|
|
22689
22806
|
},
|
|
22690
22807
|
CallExpression(node) {
|
|
22691
22808
|
const unwrappedNodeCallee = unwrapExpression(node.callee);
|
|
22692
|
-
if (unwrappedNodeCallee.type !==
|
|
22809
|
+
if (unwrappedNodeCallee.type !== import_utils123.AST_NODE_TYPES.Identifier || importedKind(unwrappedNodeCallee) !== "useController" || !fieldOptionsNeedDefault(node.arguments[0]?.type === import_utils123.AST_NODE_TYPES.SpreadElement ? void 0 : node.arguments[0])) return;
|
|
22693
22810
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22694
22811
|
},
|
|
22695
22812
|
JSXOpeningElement(node) {
|
|
22696
|
-
if (node.name.type !==
|
|
22697
|
-
if (node.attributes.some((attribute) => attribute.type ===
|
|
22813
|
+
if (node.name.type !== import_utils123.AST_NODE_TYPES.JSXIdentifier || importedJsxKind(node.name) !== "Controller") return;
|
|
22814
|
+
if (node.attributes.some((attribute) => attribute.type === import_utils123.AST_NODE_TYPES.JSXSpreadAttribute)) return;
|
|
22698
22815
|
const control = jsxAttribute(node, "control");
|
|
22699
|
-
if (control?.value?.type !==
|
|
22816
|
+
if (control?.value?.type !== import_utils123.AST_NODE_TYPES.JSXExpressionContainer || control.value.expression.type === import_utils123.AST_NODE_TYPES.JSXEmptyExpression || !isUninitializedControl(control.value.expression)) return;
|
|
22700
22817
|
const defaultValue = jsxAttribute(node, "defaultValue");
|
|
22701
|
-
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !==
|
|
22818
|
+
if (defaultValue !== null && (defaultValue.value === null || defaultValue.value.type !== import_utils123.AST_NODE_TYPES.JSXExpressionContainer || defaultValue.value.expression.type !== import_utils123.AST_NODE_TYPES.JSXEmptyExpression && !isDefinitelyUndefined(defaultValue.value.expression))) return;
|
|
22702
22819
|
context.report({ node, messageId: "requireUseFormDefaultValues" });
|
|
22703
22820
|
}
|
|
22704
22821
|
};
|
|
@@ -22706,7 +22823,7 @@ var require_use_form_default_values_default = createRule({
|
|
|
22706
22823
|
});
|
|
22707
22824
|
|
|
22708
22825
|
// src/rules/require-use-server-in-actions-file.ts
|
|
22709
|
-
var
|
|
22826
|
+
var import_utils124 = require("@typescript-eslint/utils");
|
|
22710
22827
|
var ACTION_MODULE_RE = /(?:^|\/)app\/.*\/(?:actions|[^/]+-actions)\.[cm]?[jt]s$/u;
|
|
22711
22828
|
var REQUIRE_USE_SERVER_IN_ACTIONS_FILE_DOCUMENTATION = {
|
|
22712
22829
|
summary: "route action module missing the use server directive",
|
|
@@ -22773,7 +22890,7 @@ var require_use_server_in_actions_file_default = createRule({
|
|
|
22773
22890
|
});
|
|
22774
22891
|
|
|
22775
22892
|
// src/rules/require-zod-form-validation.ts
|
|
22776
|
-
var
|
|
22893
|
+
var import_utils125 = require("@typescript-eslint/utils");
|
|
22777
22894
|
var REQUIRE_ZOD_FORM_VALIDATION_DOCUMENTATION = {
|
|
22778
22895
|
summary: "Require Zod validation (`Schema.parse(...)` / `Schema.safeParse(...)`) when reading values out of a `FormData` object.",
|
|
22779
22896
|
rationale: "FormData values are untrusted strings or files and need runtime validation before use.",
|
|
@@ -22799,14 +22916,14 @@ var FORM_VALUE_METHODS = /* @__PURE__ */ new Set(["get", "getAll"]);
|
|
|
22799
22916
|
var zodReceiverRoot = (node) => {
|
|
22800
22917
|
let current = node;
|
|
22801
22918
|
while (true) {
|
|
22802
|
-
if (current.type ===
|
|
22919
|
+
if (current.type === import_utils125.AST_NODE_TYPES.Identifier) {
|
|
22803
22920
|
return current;
|
|
22804
22921
|
}
|
|
22805
|
-
if (current.type ===
|
|
22922
|
+
if (current.type === import_utils125.AST_NODE_TYPES.CallExpression) {
|
|
22806
22923
|
current = current.callee;
|
|
22807
22924
|
continue;
|
|
22808
22925
|
}
|
|
22809
|
-
if (current.type ===
|
|
22926
|
+
if (current.type === import_utils125.AST_NODE_TYPES.MemberExpression) {
|
|
22810
22927
|
current = current.object;
|
|
22811
22928
|
continue;
|
|
22812
22929
|
}
|
|
@@ -22815,12 +22932,12 @@ var zodReceiverRoot = (node) => {
|
|
|
22815
22932
|
};
|
|
22816
22933
|
var isFormDataMethodCall = (node) => {
|
|
22817
22934
|
let current = node;
|
|
22818
|
-
if (current.type ===
|
|
22935
|
+
if (current.type === import_utils125.AST_NODE_TYPES.AwaitExpression) {
|
|
22819
22936
|
current = current.argument;
|
|
22820
22937
|
}
|
|
22821
|
-
if (current.type !==
|
|
22938
|
+
if (current.type !== import_utils125.AST_NODE_TYPES.CallExpression) return false;
|
|
22822
22939
|
const callee = unwrapExpression(current.callee);
|
|
22823
|
-
return callee.type ===
|
|
22940
|
+
return callee.type === import_utils125.AST_NODE_TYPES.MemberExpression && import_utils125.ASTUtils.getPropertyName(callee) === "formData";
|
|
22824
22941
|
};
|
|
22825
22942
|
var require_zod_form_validation_default = createRule({
|
|
22826
22943
|
name: "require-zod-form-validation",
|
|
@@ -22841,29 +22958,29 @@ var require_zod_form_validation_default = createRule({
|
|
|
22841
22958
|
return {};
|
|
22842
22959
|
}
|
|
22843
22960
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
22844
|
-
const resolvedBinding = (identifier) =>
|
|
22961
|
+
const resolvedBinding = (identifier) => import_utils125.ASTUtils.findVariable(
|
|
22845
22962
|
context.sourceCode.getScope(identifier),
|
|
22846
22963
|
identifier.name
|
|
22847
22964
|
);
|
|
22848
22965
|
const isFormDataGetCall = (node) => {
|
|
22849
22966
|
const callee = unwrapExpression(node.callee);
|
|
22850
|
-
const calleeReceiver = callee.type ===
|
|
22851
|
-
if (callee.type !==
|
|
22852
|
-
if (
|
|
22967
|
+
const calleeReceiver = callee.type === import_utils125.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
22968
|
+
if (callee.type !== import_utils125.AST_NODE_TYPES.MemberExpression) return false;
|
|
22969
|
+
if (import_utils125.ASTUtils.getPropertyName(callee) === null || !FORM_VALUE_METHODS.has(import_utils125.ASTUtils.getPropertyName(callee) ?? "")) {
|
|
22853
22970
|
return false;
|
|
22854
22971
|
}
|
|
22855
22972
|
return isFormSourceIdentifier(calleeReceiver);
|
|
22856
22973
|
};
|
|
22857
22974
|
const isFormSourceIdentifier = (node) => {
|
|
22858
22975
|
node = unwrapExpression(node);
|
|
22859
|
-
if (node.type !==
|
|
22976
|
+
if (node.type !== import_utils125.AST_NODE_TYPES.Identifier) return false;
|
|
22860
22977
|
const conventionalName = /formdata/i.test(node.name);
|
|
22861
22978
|
let scope = context.sourceCode.getScope(node);
|
|
22862
22979
|
while (scope !== null) {
|
|
22863
22980
|
const variable = scope.set.get(node.name);
|
|
22864
22981
|
if (variable !== void 0 && variable.defs.length === 1) {
|
|
22865
22982
|
const def = variable.defs[0];
|
|
22866
|
-
if (def !== void 0 && def.type === "Variable" && def.node.type ===
|
|
22983
|
+
if (def !== void 0 && def.type === "Variable" && def.node.type === import_utils125.AST_NODE_TYPES.VariableDeclarator && def.node.init !== null) {
|
|
22867
22984
|
return isFormDataMethodCall(def.node.init);
|
|
22868
22985
|
}
|
|
22869
22986
|
return def?.type === "Parameter" && conventionalName;
|
|
@@ -22876,24 +22993,24 @@ var require_zod_form_validation_default = createRule({
|
|
|
22876
22993
|
let parent = node.parent;
|
|
22877
22994
|
while (parent !== null && parent !== void 0) {
|
|
22878
22995
|
if (isZodParseCall(parent)) return parent;
|
|
22879
|
-
if (parent.type ===
|
|
22996
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils125.AST_NODE_TYPES.Identifier && ["Number", "String", "Boolean"].includes(parent.callee.name) && parent.arguments.length === 1 && (resolvedBinding(parent.callee)?.defs.length ?? 0) === 0) {
|
|
22880
22997
|
parent = parent.parent;
|
|
22881
22998
|
continue;
|
|
22882
22999
|
}
|
|
22883
|
-
if (parent.type ===
|
|
23000
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.CallExpression && parent.callee.type === import_utils125.AST_NODE_TYPES.MemberExpression && parent.callee.object.type === import_utils125.AST_NODE_TYPES.Identifier && parent.callee.object.name === "Object" && import_utils125.ASTUtils.getPropertyName(parent.callee) === "fromEntries" && (resolvedBinding(parent.callee.object)?.defs.length ?? 0) === 0) {
|
|
22884
23001
|
parent = parent.parent;
|
|
22885
23002
|
continue;
|
|
22886
23003
|
}
|
|
22887
|
-
if (parent.type ===
|
|
23004
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.CallExpression || parent.type === import_utils125.AST_NODE_TYPES.NewExpression || parent.type === import_utils125.AST_NODE_TYPES.TaggedTemplateExpression || parent.type === import_utils125.AST_NODE_TYPES.ArrowFunctionExpression || parent.type === import_utils125.AST_NODE_TYPES.FunctionExpression || parent.type === import_utils125.AST_NODE_TYPES.FunctionDeclaration) return null;
|
|
22888
23005
|
parent = parent.parent;
|
|
22889
23006
|
}
|
|
22890
23007
|
return null;
|
|
22891
23008
|
};
|
|
22892
23009
|
const isZodParseCall = (node) => {
|
|
22893
|
-
if (node.type !==
|
|
23010
|
+
if (node.type !== import_utils125.AST_NODE_TYPES.CallExpression) return false;
|
|
22894
23011
|
const callee = unwrapExpression(node.callee);
|
|
22895
|
-
const calleeReceiver = callee.type ===
|
|
22896
|
-
if (callee.type !==
|
|
23012
|
+
const calleeReceiver = callee.type === import_utils125.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
23013
|
+
if (callee.type !== import_utils125.AST_NODE_TYPES.MemberExpression || import_utils125.ASTUtils.getPropertyName(callee) === null || !ZOD_PARSE_METHODS.has(import_utils125.ASTUtils.getPropertyName(callee) ?? "")) {
|
|
22897
23014
|
return false;
|
|
22898
23015
|
}
|
|
22899
23016
|
const root = zodReceiverRoot(calleeReceiver);
|
|
@@ -22907,25 +23024,25 @@ var require_zod_form_validation_default = createRule({
|
|
|
22907
23024
|
return false;
|
|
22908
23025
|
}
|
|
22909
23026
|
const definition = binding.defs[0];
|
|
22910
|
-
if (definition?.type !== "Variable" || definition.node.type !==
|
|
23027
|
+
if (definition?.type !== "Variable" || definition.node.type !== import_utils125.AST_NODE_TYPES.VariableDeclarator) {
|
|
22911
23028
|
return false;
|
|
22912
23029
|
}
|
|
22913
23030
|
const init = definition.node.init;
|
|
22914
|
-
return init?.type ===
|
|
23031
|
+
return init?.type === import_utils125.AST_NODE_TYPES.ObjectExpression || init?.type === import_utils125.AST_NODE_TYPES.ArrayExpression || init?.type === import_utils125.AST_NODE_TYPES.Literal || init?.type === import_utils125.AST_NODE_TYPES.ArrowFunctionExpression || init?.type === import_utils125.AST_NODE_TYPES.FunctionExpression;
|
|
22915
23032
|
};
|
|
22916
23033
|
const hasZodParseAncestor = (node) => zodParseAncestor(node) !== null;
|
|
22917
23034
|
const isInstanceofNarrowing = (node) => {
|
|
22918
23035
|
const parent = node.parent;
|
|
22919
|
-
return parent !== null && parent !== void 0 && parent.type ===
|
|
23036
|
+
return parent !== null && parent !== void 0 && parent.type === import_utils125.AST_NODE_TYPES.BinaryExpression && parent.operator === "instanceof" && parent.left === node && parent.right.type === import_utils125.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
22920
23037
|
};
|
|
22921
23038
|
const boundDeclarator = (node) => {
|
|
22922
23039
|
let current = node;
|
|
22923
23040
|
let parent = current.parent;
|
|
22924
|
-
while ((parent.type ===
|
|
23041
|
+
while ((parent.type === import_utils125.AST_NODE_TYPES.TSAsExpression || parent.type === import_utils125.AST_NODE_TYPES.TSSatisfiesExpression || parent.type === import_utils125.AST_NODE_TYPES.TSNonNullExpression || parent.type === import_utils125.AST_NODE_TYPES.ChainExpression) && parent.expression === current) {
|
|
22925
23042
|
current = parent;
|
|
22926
23043
|
parent = current.parent;
|
|
22927
23044
|
}
|
|
22928
|
-
if (parent.type ===
|
|
23045
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.VariableDeclarator && parent.init === current && parent.id.type === import_utils125.AST_NODE_TYPES.Identifier) {
|
|
22929
23046
|
return parent;
|
|
22930
23047
|
}
|
|
22931
23048
|
return null;
|
|
@@ -22934,7 +23051,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22934
23051
|
let current = node;
|
|
22935
23052
|
while (current.parent !== void 0) {
|
|
22936
23053
|
const parent = current.parent;
|
|
22937
|
-
if (parent.type ===
|
|
23054
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.BlockStatement || parent.type === import_utils125.AST_NODE_TYPES.Program) {
|
|
22938
23055
|
return current;
|
|
22939
23056
|
}
|
|
22940
23057
|
current = parent;
|
|
@@ -22949,7 +23066,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22949
23066
|
if (declarationStatement === null || validationStatement === null || declarationStatement.parent !== validationStatement.parent || validationStatement.range[0] <= declarationStatement.range[1] || hasConditionalAncestorBeforeStatement(parse2, validationStatement)) {
|
|
22950
23067
|
return null;
|
|
22951
23068
|
}
|
|
22952
|
-
if (validationStatement.type !==
|
|
23069
|
+
if (validationStatement.type !== import_utils125.AST_NODE_TYPES.VariableDeclaration && validationStatement.type !== import_utils125.AST_NODE_TYPES.ExpressionStatement) {
|
|
22953
23070
|
return null;
|
|
22954
23071
|
}
|
|
22955
23072
|
const method = zodParseMethod(parse2);
|
|
@@ -22962,7 +23079,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22962
23079
|
const isAwaitedBeforeStatement = (node, statement) => {
|
|
22963
23080
|
let current = node.parent;
|
|
22964
23081
|
while (current !== void 0 && current !== statement) {
|
|
22965
|
-
if (current.type ===
|
|
23082
|
+
if (current.type === import_utils125.AST_NODE_TYPES.AwaitExpression) return true;
|
|
22966
23083
|
current = current.parent;
|
|
22967
23084
|
}
|
|
22968
23085
|
return false;
|
|
@@ -22970,7 +23087,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
22970
23087
|
const hasConditionalAncestorBeforeStatement = (node, statement) => {
|
|
22971
23088
|
let current = node.parent;
|
|
22972
23089
|
while (current !== void 0 && current !== statement) {
|
|
22973
|
-
if (current.type ===
|
|
23090
|
+
if (current.type === import_utils125.AST_NODE_TYPES.LogicalExpression || current.type === import_utils125.AST_NODE_TYPES.ConditionalExpression) {
|
|
22974
23091
|
return true;
|
|
22975
23092
|
}
|
|
22976
23093
|
current = current.parent;
|
|
@@ -22979,20 +23096,20 @@ var require_zod_form_validation_default = createRule({
|
|
|
22979
23096
|
};
|
|
22980
23097
|
const zodParseMethod = (call) => {
|
|
22981
23098
|
const callee = unwrapExpression(call.callee);
|
|
22982
|
-
return callee.type ===
|
|
23099
|
+
return callee.type === import_utils125.AST_NODE_TYPES.MemberExpression && import_utils125.ASTUtils.getPropertyName(callee) !== null ? import_utils125.ASTUtils.getPropertyName(callee) ?? "" : null;
|
|
22983
23100
|
};
|
|
22984
23101
|
const isSafePrevalidationInspection = (identifier) => {
|
|
22985
23102
|
const parent = identifier.parent;
|
|
22986
|
-
if (parent.type ===
|
|
23103
|
+
if (parent.type === import_utils125.AST_NODE_TYPES.UnaryExpression && parent.operator === "typeof") {
|
|
22987
23104
|
return true;
|
|
22988
23105
|
}
|
|
22989
|
-
if (parent.type !==
|
|
23106
|
+
if (parent.type !== import_utils125.AST_NODE_TYPES.BinaryExpression || parent.left !== identifier) {
|
|
22990
23107
|
return false;
|
|
22991
23108
|
}
|
|
22992
23109
|
if (parent.operator === "instanceof") {
|
|
22993
|
-
return parent.right.type ===
|
|
23110
|
+
return parent.right.type === import_utils125.AST_NODE_TYPES.Identifier && (parent.right.name === "File" || parent.right.name === "Blob");
|
|
22994
23111
|
}
|
|
22995
|
-
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type ===
|
|
23112
|
+
return ["===", "!==", "==", "!="].includes(parent.operator) && (parent.right.type === import_utils125.AST_NODE_TYPES.Literal && parent.right.value === null || parent.right.type === import_utils125.AST_NODE_TYPES.Identifier && parent.right.name === "undefined");
|
|
22996
23113
|
};
|
|
22997
23114
|
const isDescendantOf = (node, ancestor) => {
|
|
22998
23115
|
let current = node;
|
|
@@ -23003,23 +23120,23 @@ var require_zod_form_validation_default = createRule({
|
|
|
23003
23120
|
return false;
|
|
23004
23121
|
};
|
|
23005
23122
|
const blockTerminates = (node) => {
|
|
23006
|
-
if (node.type ===
|
|
23123
|
+
if (node.type === import_utils125.AST_NODE_TYPES.ReturnStatement || node.type === import_utils125.AST_NODE_TYPES.ThrowStatement) {
|
|
23007
23124
|
return true;
|
|
23008
23125
|
}
|
|
23009
|
-
if (node.type !==
|
|
23126
|
+
if (node.type !== import_utils125.AST_NODE_TYPES.BlockStatement || node.body.length === 0) return false;
|
|
23010
23127
|
const last = node.body.at(-1);
|
|
23011
23128
|
return last !== void 0 && blockTerminates(last);
|
|
23012
23129
|
};
|
|
23013
23130
|
const narrowingIf = (identifier) => {
|
|
23014
23131
|
const comparison = identifier.parent;
|
|
23015
|
-
if (comparison?.type !==
|
|
23132
|
+
if (comparison?.type !== import_utils125.AST_NODE_TYPES.BinaryExpression || comparison.operator !== "instanceof" || comparison.left !== identifier || comparison.right.type !== import_utils125.AST_NODE_TYPES.Identifier || comparison.right.name !== "File" && comparison.right.name !== "Blob") {
|
|
23016
23133
|
return null;
|
|
23017
23134
|
}
|
|
23018
23135
|
const maybeNegation = comparison.parent;
|
|
23019
|
-
const negated = maybeNegation?.type ===
|
|
23136
|
+
const negated = maybeNegation?.type === import_utils125.AST_NODE_TYPES.UnaryExpression && maybeNegation.operator === "!";
|
|
23020
23137
|
const test = negated ? maybeNegation : comparison;
|
|
23021
23138
|
const branch = test.parent;
|
|
23022
|
-
return branch?.type ===
|
|
23139
|
+
return branch?.type === import_utils125.AST_NODE_TYPES.IfStatement && branch.test === test ? { branch, positive: !negated } : null;
|
|
23023
23140
|
};
|
|
23024
23141
|
const useDominatedByNarrowing = (use, narrowings) => narrowings.some(({ branch, positive }) => {
|
|
23025
23142
|
if (positive) return isDescendantOf(use, branch.consequent);
|
|
@@ -23039,7 +23156,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23039
23156
|
const variable = context.sourceCode.getDeclaredVariables(declarator)[0];
|
|
23040
23157
|
if (variable === void 0) return false;
|
|
23041
23158
|
const references = variable.references.filter((reference) => !reference.isWriteOnly()).map((reference) => reference.identifier).filter(
|
|
23042
|
-
(identifier) => identifier.type ===
|
|
23159
|
+
(identifier) => identifier.type === import_utils125.AST_NODE_TYPES.Identifier
|
|
23043
23160
|
);
|
|
23044
23161
|
if (references.length === 0) return false;
|
|
23045
23162
|
const narrowings = references.map(narrowingIf).filter(
|
|
@@ -23065,7 +23182,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23065
23182
|
ImportDeclaration(node) {
|
|
23066
23183
|
if (!isZodModule(node.source.value)) return;
|
|
23067
23184
|
for (const specifier of node.specifiers) {
|
|
23068
|
-
if (specifier.type ===
|
|
23185
|
+
if (specifier.type === import_utils125.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils125.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils125.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils125.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
23069
23186
|
const binding = resolvedBinding(specifier.local);
|
|
23070
23187
|
if (binding !== null) zodBindings.add(binding);
|
|
23071
23188
|
}
|
|
@@ -23086,7 +23203,7 @@ var require_zod_form_validation_default = createRule({
|
|
|
23086
23203
|
});
|
|
23087
23204
|
|
|
23088
23205
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
23089
|
-
var
|
|
23206
|
+
var import_utils126 = require("@typescript-eslint/utils");
|
|
23090
23207
|
var STORE_INSERT_REQUIRES_ON_CONFLICT_DOCUMENTATION = {
|
|
23091
23208
|
summary: "Review conflict handling for embedded inserts in replay-named callables.",
|
|
23092
23209
|
rationale: "Names such as seed, enqueue, or upsert suggest that repeated execution deserves a conflict-policy review, but do not prove a replay contract.",
|
|
@@ -23155,7 +23272,7 @@ function expressionCallableName(current) {
|
|
|
23155
23272
|
}
|
|
23156
23273
|
|
|
23157
23274
|
// src/rules/stepdown.ts
|
|
23158
|
-
var
|
|
23275
|
+
var import_utils127 = require("@typescript-eslint/utils");
|
|
23159
23276
|
var STEPDOWN_DOCUMENTATION = {
|
|
23160
23277
|
summary: "Place a private helper below its sole direct same-scope caller.",
|
|
23161
23278
|
rationale: "Caller-first ordering lets a reader follow the main flow before descending into implementation details.",
|
|
@@ -23173,7 +23290,7 @@ var STEPDOWN_DOCUMENTATION = {
|
|
|
23173
23290
|
]
|
|
23174
23291
|
};
|
|
23175
23292
|
function isFunction(node) {
|
|
23176
|
-
return node.type ===
|
|
23293
|
+
return node.type === import_utils127.AST_NODE_TYPES.ArrowFunctionExpression || node.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils127.AST_NODE_TYPES.FunctionExpression;
|
|
23177
23294
|
}
|
|
23178
23295
|
function reportMisordered(context, candidates, scopeDefinitions, calls, pinned, canMove = () => true) {
|
|
23179
23296
|
const byName = new Map(scopeDefinitions.map((definition) => [definition.key, definition]));
|
|
@@ -23269,7 +23386,7 @@ function cycleComponents(graph) {
|
|
|
23269
23386
|
return components;
|
|
23270
23387
|
}
|
|
23271
23388
|
function isErasedExpression2(node) {
|
|
23272
|
-
return node.type ===
|
|
23389
|
+
return node.type === import_utils127.AST_NODE_TYPES.TSAsExpression || node.type === import_utils127.AST_NODE_TYPES.TSTypeAssertion || node.type === import_utils127.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils127.AST_NODE_TYPES.TSNonNullExpression || node.type === import_utils127.AST_NODE_TYPES.TSInstantiationExpression;
|
|
23273
23390
|
}
|
|
23274
23391
|
function unwrapExpression4(node) {
|
|
23275
23392
|
let current = node;
|
|
@@ -23293,11 +23410,11 @@ function localCallCount(context, node, owner) {
|
|
|
23293
23410
|
if (current === void 0 || enclosingFunction5(context, current) !== owner) return null;
|
|
23294
23411
|
const expression = wrappedExpression(current);
|
|
23295
23412
|
const parent = expression.parent;
|
|
23296
|
-
if (parent?.type ===
|
|
23413
|
+
if (parent?.type === import_utils127.AST_NODE_TYPES.CallExpression && parent.callee === expression) {
|
|
23297
23414
|
count += 1;
|
|
23298
23415
|
continue;
|
|
23299
23416
|
}
|
|
23300
|
-
if (parent?.type !==
|
|
23417
|
+
if (parent?.type !== import_utils127.AST_NODE_TYPES.VariableDeclarator || parent.init !== expression || parent.id.type !== import_utils127.AST_NODE_TYPES.Identifier || parent.parent.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || parent.parent.kind !== "const") return null;
|
|
23301
23418
|
const variable = context.sourceCode.getDeclaredVariables(parent)[0];
|
|
23302
23419
|
if (variable === void 0 || seen.has(variable) || !stableVariable(variable)) return null;
|
|
23303
23420
|
seen.add(variable);
|
|
@@ -23312,11 +23429,11 @@ function declarationScope(context, program) {
|
|
|
23312
23429
|
for (const node of declarations) counts.set(node.name, (counts.get(node.name) ?? 0) + 1);
|
|
23313
23430
|
const overloadNames = new Set(
|
|
23314
23431
|
program.body.flatMap((statement) => {
|
|
23315
|
-
const node = statement.type ===
|
|
23316
|
-
return node?.type ===
|
|
23432
|
+
const node = statement.type === import_utils127.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
23433
|
+
return node?.type === import_utils127.AST_NODE_TYPES.TSDeclareFunction && node.id !== null ? [node.id.name] : [];
|
|
23317
23434
|
})
|
|
23318
23435
|
);
|
|
23319
|
-
const exported = program.type ===
|
|
23436
|
+
const exported = program.type === import_utils127.AST_NODE_TYPES.Program ? exportedNames(program) : /* @__PURE__ */ new Set();
|
|
23320
23437
|
const scopeDefinitions = declarations.filter((node) => counts.get(node.name) === 1);
|
|
23321
23438
|
const definitions = scopeDefinitions.filter(
|
|
23322
23439
|
(definition) => !exported.has(definition.name) && !overloadNames.has(definition.name)
|
|
@@ -23328,7 +23445,7 @@ function declarationScope(context, program) {
|
|
|
23328
23445
|
runtimeBarrierPrefix.push((runtimeBarrierPrefix.at(-1) ?? 0) + (isDeferredModuleStatement(statement) ? 0 : 1));
|
|
23329
23446
|
}
|
|
23330
23447
|
const canMove = (helper, caller) => {
|
|
23331
|
-
if (helper.node.type ===
|
|
23448
|
+
if (helper.node.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration) return true;
|
|
23332
23449
|
const helperIndex = statementIndex(helper);
|
|
23333
23450
|
const callerIndex = statementIndex(caller);
|
|
23334
23451
|
return helperIndex !== void 0 && callerIndex !== void 0 && runtimeBarrierPrefix[callerIndex + 1] === runtimeBarrierPrefix[helperIndex + 1];
|
|
@@ -23370,26 +23487,26 @@ function moduleCallGraph(context, scopeDefinitions) {
|
|
|
23370
23487
|
return { calls, pinned };
|
|
23371
23488
|
}
|
|
23372
23489
|
function isDeferredModuleStatement(statement) {
|
|
23373
|
-
const node = statement.type ===
|
|
23374
|
-
if (node === null || node.type ===
|
|
23375
|
-
return node.type ===
|
|
23376
|
-
(declaration) => declaration.id.type ===
|
|
23490
|
+
const node = statement.type === import_utils127.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23491
|
+
if (node === null || node.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration || node.type === import_utils127.AST_NODE_TYPES.TSDeclareFunction || node.type === import_utils127.AST_NODE_TYPES.TSInterfaceDeclaration || node.type === import_utils127.AST_NODE_TYPES.TSTypeAliasDeclaration || node.type === import_utils127.AST_NODE_TYPES.ImportDeclaration || node.type === import_utils127.AST_NODE_TYPES.ExportAllDeclaration || node.type === import_utils127.AST_NODE_TYPES.EmptyStatement) return true;
|
|
23492
|
+
return node.type === import_utils127.AST_NODE_TYPES.VariableDeclaration && node.declarations.every(
|
|
23493
|
+
(declaration) => declaration.id.type === import_utils127.AST_NODE_TYPES.Identifier && declaration.init !== null && isFunction(unwrapExpression4(declaration.init))
|
|
23377
23494
|
);
|
|
23378
23495
|
}
|
|
23379
23496
|
function exportedNames(program) {
|
|
23380
23497
|
const names = /* @__PURE__ */ new Set();
|
|
23381
23498
|
function collectNamedExports(statement) {
|
|
23382
|
-
if (statement.type !==
|
|
23383
|
-
if (statement.declaration?.type ===
|
|
23499
|
+
if (statement.type !== import_utils127.AST_NODE_TYPES.ExportNamedDeclaration || statement.exportKind === "type" || statement.source !== null) return;
|
|
23500
|
+
if (statement.declaration?.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) {
|
|
23384
23501
|
names.add(statement.declaration.id.name);
|
|
23385
23502
|
}
|
|
23386
|
-
if (statement.declaration?.type ===
|
|
23503
|
+
if (statement.declaration?.type === import_utils127.AST_NODE_TYPES.VariableDeclaration) {
|
|
23387
23504
|
for (const declarator of statement.declaration.declarations) {
|
|
23388
|
-
if (declarator.id.type ===
|
|
23505
|
+
if (declarator.id.type === import_utils127.AST_NODE_TYPES.Identifier) names.add(declarator.id.name);
|
|
23389
23506
|
}
|
|
23390
23507
|
}
|
|
23391
23508
|
for (const specifier of statement.specifiers) {
|
|
23392
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
23509
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils127.AST_NODE_TYPES.Identifier) {
|
|
23393
23510
|
names.add(specifier.local.name);
|
|
23394
23511
|
}
|
|
23395
23512
|
}
|
|
@@ -23398,23 +23515,23 @@ function exportedNames(program) {
|
|
|
23398
23515
|
collectNamedExports(statement);
|
|
23399
23516
|
}
|
|
23400
23517
|
for (const statement of program.body) {
|
|
23401
|
-
if (statement.type ===
|
|
23402
|
-
if (statement.type ===
|
|
23518
|
+
if (statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils127.AST_NODE_TYPES.Identifier) names.add(statement.declaration.name);
|
|
23519
|
+
if (statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration && statement.declaration.id !== null) names.add(statement.declaration.id.name);
|
|
23403
23520
|
}
|
|
23404
23521
|
return names;
|
|
23405
23522
|
}
|
|
23406
23523
|
function moduleDefinitions(program) {
|
|
23407
23524
|
const definitions = [];
|
|
23408
23525
|
for (const statement of program.body) {
|
|
23409
|
-
const node = statement.type ===
|
|
23410
|
-
if (node?.type ===
|
|
23526
|
+
const node = statement.type === import_utils127.AST_NODE_TYPES.ExportNamedDeclaration || statement.type === import_utils127.AST_NODE_TYPES.ExportDefaultDeclaration ? statement.declaration : statement;
|
|
23527
|
+
if (node?.type === import_utils127.AST_NODE_TYPES.FunctionDeclaration && node.id !== null && node.body !== null) {
|
|
23411
23528
|
definitions.push({ key: node.id.name, name: node.id.name, node, functionNode: node, bindingNode: node });
|
|
23412
23529
|
continue;
|
|
23413
23530
|
}
|
|
23414
|
-
if (node?.type !==
|
|
23531
|
+
if (node?.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || node.kind !== "const" || node.declarations.length !== 1) continue;
|
|
23415
23532
|
for (const declarator of node.declarations) {
|
|
23416
23533
|
const initializer = declarator.init === null ? null : unwrapExpression4(declarator.init);
|
|
23417
|
-
if (declarator.id.type ===
|
|
23534
|
+
if (declarator.id.type === import_utils127.AST_NODE_TYPES.Identifier && initializer !== null && isFunction(initializer)) {
|
|
23418
23535
|
definitions.push({
|
|
23419
23536
|
key: declarator.id.name,
|
|
23420
23537
|
name: declarator.id.name,
|
|
@@ -23428,25 +23545,25 @@ function moduleDefinitions(program) {
|
|
|
23428
23545
|
return definitions;
|
|
23429
23546
|
}
|
|
23430
23547
|
function methodName(node) {
|
|
23431
|
-
if (node.key.type ===
|
|
23432
|
-
if (!node.computed && node.key.type ===
|
|
23433
|
-
return node.key.type ===
|
|
23548
|
+
if (node.key.type === import_utils127.AST_NODE_TYPES.PrivateIdentifier) return `#${node.key.name}`;
|
|
23549
|
+
if (!node.computed && node.key.type === import_utils127.AST_NODE_TYPES.Identifier) return node.key.name;
|
|
23550
|
+
return node.key.type === import_utils127.AST_NODE_TYPES.Literal && typeof node.key.value === "string" ? node.key.value : null;
|
|
23434
23551
|
}
|
|
23435
23552
|
function methodKey(name, isStatic2) {
|
|
23436
23553
|
return `${isStatic2 ? "static" : "instance"}:${name}`;
|
|
23437
23554
|
}
|
|
23438
23555
|
function receiverDomain(context, object, receivers, thisIsStatic) {
|
|
23439
23556
|
const unwrapped = unwrapExpression4(object);
|
|
23440
|
-
if (unwrapped.type ===
|
|
23557
|
+
if (unwrapped.type === import_utils127.AST_NODE_TYPES.ThisExpression) return thisIsStatic;
|
|
23441
23558
|
return externalReceiverDomain(context, unwrapped, receivers);
|
|
23442
23559
|
}
|
|
23443
23560
|
function externalReceiverDomain(context, object, receivers) {
|
|
23444
23561
|
const origin = receiverOrigin(context, object, receivers);
|
|
23445
23562
|
if (origin === null || typeof origin === "boolean") return origin;
|
|
23446
|
-
if (origin.type ===
|
|
23563
|
+
if (origin.type === import_utils127.AST_NODE_TYPES.NewExpression) {
|
|
23447
23564
|
return receiverOrigin(context, origin.callee, receivers) === true ? false : null;
|
|
23448
23565
|
}
|
|
23449
|
-
if (origin.type ===
|
|
23566
|
+
if (origin.type === import_utils127.AST_NODE_TYPES.ObjectExpression || origin.type === import_utils127.AST_NODE_TYPES.ArrayExpression || origin.type === import_utils127.AST_NODE_TYPES.Literal || origin.type === import_utils127.AST_NODE_TYPES.ArrowFunctionExpression || origin.type === import_utils127.AST_NODE_TYPES.FunctionExpression) return "unrelated";
|
|
23450
23567
|
return null;
|
|
23451
23568
|
}
|
|
23452
23569
|
function receiverOrigin(context, object, receivers) {
|
|
@@ -23454,8 +23571,8 @@ function receiverOrigin(context, object, receivers) {
|
|
|
23454
23571
|
const seen = /* @__PURE__ */ new Set();
|
|
23455
23572
|
while (true) {
|
|
23456
23573
|
const unwrapped = unwrapExpression4(current);
|
|
23457
|
-
if (unwrapped.type !==
|
|
23458
|
-
const variable =
|
|
23574
|
+
if (unwrapped.type !== import_utils127.AST_NODE_TYPES.Identifier) return unwrapped;
|
|
23575
|
+
const variable = import_utils127.ASTUtils.findVariable(context.sourceCode.getScope(unwrapped), unwrapped.name);
|
|
23459
23576
|
if (variable === null) return null;
|
|
23460
23577
|
const known = receivers.get(variable);
|
|
23461
23578
|
if (known !== void 0) return known;
|
|
@@ -23468,25 +23585,25 @@ function immutableInitializer(variable, seen) {
|
|
|
23468
23585
|
if (seen.has(variable) || !stableVariable(variable) || variable.defs.length !== 1) return null;
|
|
23469
23586
|
seen.add(variable);
|
|
23470
23587
|
const definition = variable.defs[0];
|
|
23471
|
-
if (definition?.node.type !==
|
|
23588
|
+
if (definition?.node.type !== import_utils127.AST_NODE_TYPES.VariableDeclarator || definition.node.parent.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || definition.node.parent.kind !== "const") return null;
|
|
23472
23589
|
return definition.node.init;
|
|
23473
23590
|
}
|
|
23474
23591
|
function stableVariable(variable) {
|
|
23475
23592
|
return !variable.references.some((reference) => reference.isWrite() && reference.init !== true);
|
|
23476
23593
|
}
|
|
23477
23594
|
function referencedPropertyName(node) {
|
|
23478
|
-
if (node.property.type ===
|
|
23479
|
-
if (!node.computed && node.property.type ===
|
|
23480
|
-
return node.computed && node.property.type ===
|
|
23595
|
+
if (node.property.type === import_utils127.AST_NODE_TYPES.PrivateIdentifier) return `#${node.property.name}`;
|
|
23596
|
+
if (!node.computed && node.property.type === import_utils127.AST_NODE_TYPES.Identifier) return node.property.name;
|
|
23597
|
+
return node.computed && node.property.type === import_utils127.AST_NODE_TYPES.Literal && typeof node.property.value === "string" ? node.property.value : null;
|
|
23481
23598
|
}
|
|
23482
23599
|
function walk(node, visitorKeys, visit, nestedFunction = false) {
|
|
23483
23600
|
visit(node, nestedFunction);
|
|
23484
|
-
const nested = nestedFunction || isFunction(node) || node.type ===
|
|
23601
|
+
const nested = nestedFunction || isFunction(node) || node.type === import_utils127.AST_NODE_TYPES.ClassDeclaration || node.type === import_utils127.AST_NODE_TYPES.ClassExpression;
|
|
23485
23602
|
forEachAstChild(node, visitorKeys, (child) => walk(child, visitorKeys, visit, nested));
|
|
23486
23603
|
}
|
|
23487
23604
|
function classScope(context, node, computedReferences) {
|
|
23488
23605
|
const methods = node.body.body.filter(
|
|
23489
|
-
(member) => member.type ===
|
|
23606
|
+
(member) => member.type === import_utils127.AST_NODE_TYPES.MethodDefinition
|
|
23490
23607
|
);
|
|
23491
23608
|
const counts = classMethodCounts(node.body, methods);
|
|
23492
23609
|
const implementations = methods.filter((method) => isFunction(method.value));
|
|
@@ -23497,7 +23614,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23497
23614
|
return name !== null && key !== null && implementationCounts.get(key) === 1 ? [{ key, name, node: method }] : [];
|
|
23498
23615
|
});
|
|
23499
23616
|
const definitions = scopeDefinitions.filter(
|
|
23500
|
-
({ key, node: method }) => (method.accessibility === "private" || method.key.type ===
|
|
23617
|
+
({ key, node: method }) => (method.accessibility === "private" || method.key.type === import_utils127.AST_NODE_TYPES.PrivateIdentifier) && counts.get(key) === 1 && method.decorators.length === 0 && !method.computed && method.kind === "method"
|
|
23501
23618
|
);
|
|
23502
23619
|
if (definitions.length === 0) return;
|
|
23503
23620
|
const methodKeys = new Set(scopeDefinitions.map((definition) => definition.key));
|
|
@@ -23513,11 +23630,11 @@ function classScope(context, node, computedReferences) {
|
|
|
23513
23630
|
};
|
|
23514
23631
|
function pinDestructuredMembers(binding, domain) {
|
|
23515
23632
|
for (const property of binding.properties) {
|
|
23516
|
-
if (property.type ===
|
|
23633
|
+
if (property.type === import_utils127.AST_NODE_TYPES.RestElement || property.computed) {
|
|
23517
23634
|
pinNames(null, domain);
|
|
23518
|
-
} else if (property.key.type ===
|
|
23635
|
+
} else if (property.key.type === import_utils127.AST_NODE_TYPES.Identifier) {
|
|
23519
23636
|
pinNames(property.key.name, domain);
|
|
23520
|
-
} else if (property.key.type ===
|
|
23637
|
+
} else if (property.key.type === import_utils127.AST_NODE_TYPES.Literal && typeof property.key.value === "string") {
|
|
23521
23638
|
pinNames(property.key.value, domain);
|
|
23522
23639
|
}
|
|
23523
23640
|
}
|
|
@@ -23539,15 +23656,15 @@ function classScope(context, node, computedReferences) {
|
|
|
23539
23656
|
}
|
|
23540
23657
|
}
|
|
23541
23658
|
const collectAlias = (current, nestedFunction) => {
|
|
23542
|
-
if (nestedFunction || current.type !==
|
|
23659
|
+
if (nestedFunction || current.type !== import_utils127.AST_NODE_TYPES.VariableDeclarator || current.init === null) return;
|
|
23543
23660
|
const domain = receiverDomain(context, current.init, receivers, method.static);
|
|
23544
23661
|
if (domain === null || domain === "unrelated") return;
|
|
23545
|
-
if (current.id.type ===
|
|
23662
|
+
if (current.id.type === import_utils127.AST_NODE_TYPES.ObjectPattern) {
|
|
23546
23663
|
pinDestructuredMembers(current.id, domain);
|
|
23547
23664
|
return;
|
|
23548
23665
|
}
|
|
23549
|
-
if (current.id.type !==
|
|
23550
|
-
if (current.parent.type !==
|
|
23666
|
+
if (current.id.type !== import_utils127.AST_NODE_TYPES.Identifier) return;
|
|
23667
|
+
if (current.parent.type !== import_utils127.AST_NODE_TYPES.VariableDeclaration || current.parent.kind !== "const") {
|
|
23551
23668
|
pinNames(null, domain);
|
|
23552
23669
|
return;
|
|
23553
23670
|
}
|
|
@@ -23556,7 +23673,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23556
23673
|
const local = variable.references.every((reference) => {
|
|
23557
23674
|
if (!reference.isRead()) return true;
|
|
23558
23675
|
const expression = wrappedExpression(reference.identifier);
|
|
23559
|
-
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type ===
|
|
23676
|
+
return enclosingFunction5(context, reference.identifier) === methodFunction && expression.parent?.type === import_utils127.AST_NODE_TYPES.MemberExpression && expression.parent.object === expression;
|
|
23560
23677
|
});
|
|
23561
23678
|
if (local) receivers.set(variable, domain);
|
|
23562
23679
|
else pinNames(null, domain);
|
|
@@ -23568,7 +23685,7 @@ function classScope(context, node, computedReferences) {
|
|
|
23568
23685
|
const domain2 = receiverDomain(context, destructuring.value, receivers, method.static);
|
|
23569
23686
|
if (domain2 !== "unrelated") pinDestructuredMembers(destructuring.binding, domain2);
|
|
23570
23687
|
}
|
|
23571
|
-
if (current.type !==
|
|
23688
|
+
if (current.type !== import_utils127.AST_NODE_TYPES.MemberExpression) return;
|
|
23572
23689
|
const domain = receiverDomain(context, current.object, receivers, method.static);
|
|
23573
23690
|
const targetName = referencedPropertyName(current);
|
|
23574
23691
|
if (domain === "unrelated") return;
|
|
@@ -23602,9 +23719,9 @@ function classScope(context, node, computedReferences) {
|
|
|
23602
23719
|
}
|
|
23603
23720
|
for (const method of methods) collectMethodCalls(method);
|
|
23604
23721
|
for (const member of node.body.body) {
|
|
23605
|
-
if (member.type ===
|
|
23722
|
+
if (member.type === import_utils127.AST_NODE_TYPES.MethodDefinition || member.type === import_utils127.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
23606
23723
|
walk(member, context.sourceCode.visitorKeys, (current) => {
|
|
23607
|
-
if (current.type !==
|
|
23724
|
+
if (current.type !== import_utils127.AST_NODE_TYPES.MemberExpression) return;
|
|
23608
23725
|
if (externalReceiverDomain(context, current.object, classReceivers) === "unrelated") return;
|
|
23609
23726
|
pinNames(referencedPropertyName(current));
|
|
23610
23727
|
});
|
|
@@ -23636,32 +23753,32 @@ function classScope(context, node, computedReferences) {
|
|
|
23636
23753
|
function classReceiverBindings(context, node) {
|
|
23637
23754
|
const classReceivers = /* @__PURE__ */ new Map();
|
|
23638
23755
|
if (node.id !== null) {
|
|
23639
|
-
const internal =
|
|
23756
|
+
const internal = import_utils127.ASTUtils.findVariable(context.sourceCode.getScope(node), node.id.name);
|
|
23640
23757
|
if (internal !== null && stableVariable(internal)) classReceivers.set(internal, true);
|
|
23641
23758
|
}
|
|
23642
|
-
if (node.type ===
|
|
23643
|
-
const outer =
|
|
23759
|
+
if (node.type === import_utils127.AST_NODE_TYPES.ClassExpression && node.parent.type === import_utils127.AST_NODE_TYPES.VariableDeclarator && node.parent.id.type === import_utils127.AST_NODE_TYPES.Identifier && node.parent.parent.type === import_utils127.AST_NODE_TYPES.VariableDeclaration && node.parent.parent.kind === "const") {
|
|
23760
|
+
const outer = import_utils127.ASTUtils.findVariable(context.sourceCode.getScope(node.parent), node.parent.id.name);
|
|
23644
23761
|
if (outer !== null && stableVariable(outer)) classReceivers.set(outer, true);
|
|
23645
23762
|
}
|
|
23646
23763
|
return classReceivers;
|
|
23647
23764
|
}
|
|
23648
23765
|
function receiverDestructuring(node) {
|
|
23649
|
-
if (node.type ===
|
|
23766
|
+
if (node.type === import_utils127.AST_NODE_TYPES.VariableDeclarator && node.id.type === import_utils127.AST_NODE_TYPES.ObjectPattern && node.init !== null) {
|
|
23650
23767
|
return { binding: node.id, value: node.init };
|
|
23651
23768
|
}
|
|
23652
|
-
if ((node.type ===
|
|
23769
|
+
if ((node.type === import_utils127.AST_NODE_TYPES.AssignmentPattern || node.type === import_utils127.AST_NODE_TYPES.AssignmentExpression) && node.left.type === import_utils127.AST_NODE_TYPES.ObjectPattern) {
|
|
23653
23770
|
return { binding: node.left, value: node.right };
|
|
23654
23771
|
}
|
|
23655
23772
|
return null;
|
|
23656
23773
|
}
|
|
23657
23774
|
function isClassRuntimeBarrier(member) {
|
|
23658
23775
|
switch (member.type) {
|
|
23659
|
-
case
|
|
23776
|
+
case import_utils127.AST_NODE_TYPES.StaticBlock:
|
|
23660
23777
|
return true;
|
|
23661
|
-
case
|
|
23662
|
-
case
|
|
23778
|
+
case import_utils127.AST_NODE_TYPES.PropertyDefinition:
|
|
23779
|
+
case import_utils127.AST_NODE_TYPES.AccessorProperty:
|
|
23663
23780
|
return member.static || member.computed || member.decorators.length > 0 || member.value !== null;
|
|
23664
|
-
case
|
|
23781
|
+
case import_utils127.AST_NODE_TYPES.MethodDefinition:
|
|
23665
23782
|
return member.computed || member.decorators.length > 0;
|
|
23666
23783
|
default:
|
|
23667
23784
|
return false;
|
|
@@ -23691,14 +23808,14 @@ var stepdown_default = createRule({
|
|
|
23691
23808
|
classes.push(node);
|
|
23692
23809
|
},
|
|
23693
23810
|
"FunctionDeclaration, FunctionExpression, ArrowFunctionExpression": (node) => {
|
|
23694
|
-
if (isFunction(node) && node.body?.type ===
|
|
23811
|
+
if (isFunction(node) && node.body?.type === import_utils127.AST_NODE_TYPES.BlockStatement) functionBodies.push(node.body);
|
|
23695
23812
|
},
|
|
23696
23813
|
"Program:exit": (program) => {
|
|
23697
23814
|
declarationScope(context, program);
|
|
23698
23815
|
for (const body2 of functionBodies) declarationScope(context, body2);
|
|
23699
23816
|
const computedReferences = [];
|
|
23700
23817
|
walk(program, context.sourceCode.visitorKeys, (node) => {
|
|
23701
|
-
if (node.type ===
|
|
23818
|
+
if (node.type === import_utils127.AST_NODE_TYPES.MemberExpression && node.computed) computedReferences.push(node);
|
|
23702
23819
|
});
|
|
23703
23820
|
for (const node of classes) classScope(context, node, computedReferences);
|
|
23704
23821
|
}
|
|
@@ -23715,8 +23832,8 @@ function classMethodCounts(body2, methods) {
|
|
|
23715
23832
|
}
|
|
23716
23833
|
}
|
|
23717
23834
|
for (const member of body2.body) {
|
|
23718
|
-
if (member.type !==
|
|
23719
|
-
const name = !member.computed && member.key.type ===
|
|
23835
|
+
if (member.type !== import_utils127.AST_NODE_TYPES.TSAbstractMethodDefinition) continue;
|
|
23836
|
+
const name = !member.computed && member.key.type === import_utils127.AST_NODE_TYPES.Identifier ? member.key.name : null;
|
|
23720
23837
|
if (name !== null) {
|
|
23721
23838
|
const key = methodKey(name, member.static);
|
|
23722
23839
|
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
@@ -23726,7 +23843,7 @@ function classMethodCounts(body2, methods) {
|
|
|
23726
23843
|
}
|
|
23727
23844
|
|
|
23728
23845
|
// src/rules/source-coupled-test.ts
|
|
23729
|
-
var
|
|
23846
|
+
var import_utils128 = require("@typescript-eslint/utils");
|
|
23730
23847
|
var GENERAL_SOURCE_SUFFIX_RE = /\.(?:bash|sh|ya?ml|jsonc?|toml|py|[cm]?[jt]s)$/iu;
|
|
23731
23848
|
var FS_MODULES = /* @__PURE__ */ new Set(["fs", "node:fs", "fs/promises", "node:fs/promises"]);
|
|
23732
23849
|
var FS_READERS = /* @__PURE__ */ new Set(["readFile", "readFileSync"]);
|
|
@@ -23800,16 +23917,16 @@ var SOURCE_COUPLED_TEST_DOCUMENTATION = {
|
|
|
23800
23917
|
function unwrap6(node) {
|
|
23801
23918
|
for (; ; ) {
|
|
23802
23919
|
node = unwrapExpression(node);
|
|
23803
|
-
if (node.type ===
|
|
23804
|
-
else if (node.type ===
|
|
23920
|
+
if (node.type === import_utils128.AST_NODE_TYPES.AwaitExpression) node = node.argument;
|
|
23921
|
+
else if (node.type === import_utils128.AST_NODE_TYPES.ChainExpression) node = node.expression;
|
|
23805
23922
|
else return node;
|
|
23806
23923
|
}
|
|
23807
23924
|
}
|
|
23808
23925
|
function stringValue(node) {
|
|
23809
23926
|
const current = unwrap6(node);
|
|
23810
|
-
if (current.type ===
|
|
23811
|
-
if (current.type ===
|
|
23812
|
-
if (current.type ===
|
|
23927
|
+
if (current.type === import_utils128.AST_NODE_TYPES.Literal && typeof current.value === "string") return current.value;
|
|
23928
|
+
if (current.type === import_utils128.AST_NODE_TYPES.TemplateLiteral && current.expressions.length === 0) return current.quasis[0]?.value.cooked ?? null;
|
|
23929
|
+
if (current.type === import_utils128.AST_NODE_TYPES.BinaryExpression && current.operator === "+") {
|
|
23813
23930
|
const left = stringValue(current.left);
|
|
23814
23931
|
const right = stringValue(current.right);
|
|
23815
23932
|
return left === null || right === null ? null : left + right;
|
|
@@ -23821,7 +23938,7 @@ function importSource(node) {
|
|
|
23821
23938
|
}
|
|
23822
23939
|
function requireSource(node) {
|
|
23823
23940
|
const current = unwrap6(node);
|
|
23824
|
-
if (current.type !==
|
|
23941
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression || current.callee.type !== import_utils128.AST_NODE_TYPES.Identifier || current.callee.name !== "require" || current.arguments.length !== 1 || current.arguments[0]?.type === import_utils128.AST_NODE_TYPES.SpreadElement) return null;
|
|
23825
23942
|
return stringValue(current.arguments[0]);
|
|
23826
23943
|
}
|
|
23827
23944
|
function newScope() {
|
|
@@ -23843,7 +23960,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23843
23960
|
const scopes = [newScope()];
|
|
23844
23961
|
const reportedOrigins = /* @__PURE__ */ new Set();
|
|
23845
23962
|
const currentScope = () => scopes.at(-1) ?? scopes[0];
|
|
23846
|
-
const bindingOf = (node) =>
|
|
23963
|
+
const bindingOf = (node) => import_utils128.ASTUtils.findVariable(context.sourceCode.getScope(node), node.name);
|
|
23847
23964
|
const assertionKind = (node) => {
|
|
23848
23965
|
const binding = bindingOf(node);
|
|
23849
23966
|
if (binding === null || binding.defs.length === 0) {
|
|
@@ -23877,75 +23994,75 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23877
23994
|
const current = unwrap6(node);
|
|
23878
23995
|
const value = stringValue(current);
|
|
23879
23996
|
if (value !== null) return sourceSuffixRe.test(value);
|
|
23880
|
-
if (current.type ===
|
|
23881
|
-
if (current.type ===
|
|
23997
|
+
if (current.type === import_utils128.AST_NODE_TYPES.Identifier) return visible("paths", current);
|
|
23998
|
+
if (current.type === import_utils128.AST_NODE_TYPES.CallExpression || current.type === import_utils128.AST_NODE_TYPES.NewExpression) {
|
|
23882
23999
|
const callee = unwrapExpression(current.callee);
|
|
23883
24000
|
const first = current.arguments[0];
|
|
23884
|
-
if (first === void 0 || first.type ===
|
|
23885
|
-
if (current.type ===
|
|
23886
|
-
if (callee.type ===
|
|
24001
|
+
if (first === void 0 || first.type === import_utils128.AST_NODE_TYPES.SpreadElement) return false;
|
|
24002
|
+
if (current.type === import_utils128.AST_NODE_TYPES.NewExpression && callee.type === import_utils128.AST_NODE_TYPES.Identifier && callee.name === "URL" && (bindingOf(callee)?.defs.length ?? 0) === 0) return sourcePath(first);
|
|
24003
|
+
if (callee.type === import_utils128.AST_NODE_TYPES.Identifier && bindingOf(callee)?.defs.some((definition) => definition.node.type === import_utils128.AST_NODE_TYPES.ImportSpecifier && definition.node.imported.type === import_utils128.AST_NODE_TYPES.Identifier && definition.node.imported.name === "fileURLToPath" && definition.node.parent.type === import_utils128.AST_NODE_TYPES.ImportDeclaration && ["node:url", "url"].includes(String(definition.node.parent.source.value)))) return sourcePath(first);
|
|
23887
24004
|
}
|
|
23888
24005
|
return false;
|
|
23889
24006
|
};
|
|
23890
24007
|
const rawRead = (node) => {
|
|
23891
24008
|
const current = unwrap6(node);
|
|
23892
|
-
if (current.type !==
|
|
24009
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression || current.arguments.length === 0) return false;
|
|
23893
24010
|
const callee = unwrap6(current.callee);
|
|
23894
|
-
const calleeReceiver = callee.type ===
|
|
23895
|
-
if (callee.type ===
|
|
24011
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24012
|
+
if (callee.type === import_utils128.AST_NODE_TYPES.Identifier) {
|
|
23896
24013
|
return visible("fsReaders", callee) && sourcePath(current.arguments[0]);
|
|
23897
24014
|
}
|
|
23898
|
-
if (callee.type !==
|
|
23899
|
-
const name2 =
|
|
24015
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return false;
|
|
24016
|
+
const name2 = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23900
24017
|
const object = unwrap6(calleeReceiver);
|
|
23901
|
-
return name2 !== null && FS_READERS.has(name2) && object.type ===
|
|
24018
|
+
return name2 !== null && FS_READERS.has(name2) && object.type === import_utils128.AST_NODE_TYPES.Identifier && visible("fsObjects", object) && sourcePath(current.arguments[0]);
|
|
23902
24019
|
};
|
|
23903
24020
|
const rawOrigins = (node) => {
|
|
23904
24021
|
const current = unwrap6(node);
|
|
23905
|
-
if (current.type ===
|
|
24022
|
+
if (current.type === import_utils128.AST_NODE_TYPES.Identifier) return visibleRawOrigins(current);
|
|
23906
24023
|
if (rawRead(current)) return /* @__PURE__ */ new Set([`${current.range[0]}:${current.range[1]}`]);
|
|
23907
|
-
if (current.type ===
|
|
23908
|
-
if (current.type ===
|
|
23909
|
-
if (current.type !==
|
|
24024
|
+
if (current.type === import_utils128.AST_NODE_TYPES.BinaryExpression && current.operator === "+") return /* @__PURE__ */ new Set([...rawOrigins(current.left), ...rawOrigins(current.right)]);
|
|
24025
|
+
if (current.type === import_utils128.AST_NODE_TYPES.MemberExpression && import_utils128.ASTUtils.getPropertyName(current) === "length") return rawOrigins(current.object);
|
|
24026
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
23910
24027
|
const callee = unwrap6(current.callee);
|
|
23911
|
-
const calleeReceiver = callee.type ===
|
|
23912
|
-
if (callee.type !==
|
|
23913
|
-
const name2 =
|
|
24028
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24029
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24030
|
+
const name2 = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23914
24031
|
return name2 !== null && TEXT_TRANSFORMS.has(name2) ? rawOrigins(calleeReceiver) : /* @__PURE__ */ new Set();
|
|
23915
24032
|
};
|
|
23916
24033
|
const evidenceOrigins = (node) => {
|
|
23917
24034
|
const current = unwrap6(node);
|
|
23918
24035
|
const direct = rawOrigins(current);
|
|
23919
24036
|
if (direct.size > 0) return direct;
|
|
23920
|
-
if (current.type ===
|
|
23921
|
-
if (current.type ===
|
|
23922
|
-
if (current.type !==
|
|
24037
|
+
if (current.type === import_utils128.AST_NODE_TYPES.BinaryExpression || current.type === import_utils128.AST_NODE_TYPES.LogicalExpression) return /* @__PURE__ */ new Set([...evidenceOrigins(current.left), ...evidenceOrigins(current.right)]);
|
|
24038
|
+
if (current.type === import_utils128.AST_NODE_TYPES.UnaryExpression) return evidenceOrigins(current.argument);
|
|
24039
|
+
if (current.type !== import_utils128.AST_NODE_TYPES.CallExpression) return /* @__PURE__ */ new Set();
|
|
23923
24040
|
const callee = unwrap6(current.callee);
|
|
23924
|
-
const calleeReceiver = callee.type ===
|
|
23925
|
-
if (callee.type !==
|
|
23926
|
-
const name2 =
|
|
24041
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24042
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24043
|
+
const name2 = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23927
24044
|
if (name2 !== null && TEXT_PREDICATES.has(name2)) return rawOrigins(calleeReceiver);
|
|
23928
|
-
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type ===
|
|
24045
|
+
if (name2 !== null && REGEXP_PREDICATES.has(name2)) return new Set(current.arguments.flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...rawOrigins(argument)]));
|
|
23929
24046
|
return /* @__PURE__ */ new Set();
|
|
23930
24047
|
};
|
|
23931
24048
|
const rawAssertionOrigins = (node) => {
|
|
23932
24049
|
const callee = unwrap6(node.callee);
|
|
23933
|
-
const calleeReceiver = callee.type ===
|
|
23934
|
-
if (callee.type ===
|
|
23935
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24050
|
+
const calleeReceiver = callee.type === import_utils128.AST_NODE_TYPES.MemberExpression ? unwrapExpression(callee.object) : callee;
|
|
24051
|
+
if (callee.type === import_utils128.AST_NODE_TYPES.Identifier && assertionKind(callee) === "assert") {
|
|
24052
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23936
24053
|
}
|
|
23937
|
-
if (callee.type !==
|
|
23938
|
-
const matcher =
|
|
24054
|
+
if (callee.type !== import_utils128.AST_NODE_TYPES.MemberExpression) return /* @__PURE__ */ new Set();
|
|
24055
|
+
const matcher = import_utils128.ASTUtils.getPropertyName(callee);
|
|
23939
24056
|
if (matcher === null) return /* @__PURE__ */ new Set();
|
|
23940
24057
|
let receiver = unwrap6(calleeReceiver);
|
|
23941
|
-
while (receiver.type ===
|
|
23942
|
-
const expectCallee = receiver.type ===
|
|
23943
|
-
if (receiver.type ===
|
|
24058
|
+
while (receiver.type === import_utils128.AST_NODE_TYPES.MemberExpression && EXPECT_MODIFIERS2.has(import_utils128.ASTUtils.getPropertyName(receiver) ?? "")) receiver = unwrap6(receiver.object);
|
|
24059
|
+
const expectCallee = receiver.type === import_utils128.AST_NODE_TYPES.CallExpression ? unwrapExpression(receiver.callee) : null;
|
|
24060
|
+
if (receiver.type === import_utils128.AST_NODE_TYPES.CallExpression && expectCallee?.type === import_utils128.AST_NODE_TYPES.Identifier && assertionKind(expectCallee) === "expect") {
|
|
23944
24061
|
if (!EXPECT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
23945
|
-
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type ===
|
|
24062
|
+
return new Set([...receiver.arguments, ...node.arguments].flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23946
24063
|
}
|
|
23947
|
-
if (receiver.type !==
|
|
23948
|
-
return new Set(node.arguments.flatMap((argument) => argument.type ===
|
|
24064
|
+
if (receiver.type !== import_utils128.AST_NODE_TYPES.Identifier || assertionKind(receiver) !== "assert" || !ASSERT_MATCHERS.has(matcher)) return /* @__PURE__ */ new Set();
|
|
24065
|
+
return new Set(node.arguments.flatMap((argument) => argument.type === import_utils128.AST_NODE_TYPES.SpreadElement ? [] : [...evidenceOrigins(argument)]));
|
|
23949
24066
|
};
|
|
23950
24067
|
const declare = (node, state) => {
|
|
23951
24068
|
const name2 = bindingOf(node);
|
|
@@ -23967,7 +24084,7 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23967
24084
|
};
|
|
23968
24085
|
const sourceCollection = (node) => {
|
|
23969
24086
|
const current = unwrap6(node);
|
|
23970
|
-
return current.type ===
|
|
24087
|
+
return current.type === import_utils128.AST_NODE_TYPES.ArrayExpression && current.elements.length > 0 && current.elements.every((element) => element !== null && element.type !== import_utils128.AST_NODE_TYPES.SpreadElement && sourcePath(element));
|
|
23971
24088
|
};
|
|
23972
24089
|
const enterFunction = () => {
|
|
23973
24090
|
scopes.push(newScope());
|
|
@@ -23977,8 +24094,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23977
24094
|
};
|
|
23978
24095
|
function declareFsReaders(pattern) {
|
|
23979
24096
|
for (const property of pattern.properties) {
|
|
23980
|
-
if (property.type !==
|
|
23981
|
-
const key = property.key.type ===
|
|
24097
|
+
if (property.type !== import_utils128.AST_NODE_TYPES.Property || property.value.type !== import_utils128.AST_NODE_TYPES.Identifier) continue;
|
|
24098
|
+
const key = property.key.type === import_utils128.AST_NODE_TYPES.Identifier ? property.key.name : property.key.type === import_utils128.AST_NODE_TYPES.Literal ? String(property.key.value) : "";
|
|
23982
24099
|
if (FS_READERS.has(key)) declare(property.value, { fsReader: true });
|
|
23983
24100
|
}
|
|
23984
24101
|
}
|
|
@@ -23987,8 +24104,8 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
23987
24104
|
const source = importSource(node);
|
|
23988
24105
|
if (source === null || !FS_MODULES.has(source)) return;
|
|
23989
24106
|
for (const specifier of node.specifiers) {
|
|
23990
|
-
if (specifier.type ===
|
|
23991
|
-
const imported = specifier.imported.type ===
|
|
24107
|
+
if (specifier.type === import_utils128.AST_NODE_TYPES.ImportSpecifier) {
|
|
24108
|
+
const imported = specifier.imported.type === import_utils128.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
23992
24109
|
if (FS_READERS.has(imported)) declare(specifier.local, { fsReader: true });
|
|
23993
24110
|
} else {
|
|
23994
24111
|
declare(specifier.local, { fsObject: true });
|
|
@@ -24001,26 +24118,26 @@ function createSourceCoupledRule(name, documentation, sourceSuffixRe) {
|
|
|
24001
24118
|
if (node.init === null) return;
|
|
24002
24119
|
const required = requireSource(node.init);
|
|
24003
24120
|
const initializer = unwrap6(node.init);
|
|
24004
|
-
if (required !== null && initializer.type ===
|
|
24005
|
-
if (required !== null && FS_MODULES.has(required) && node.id.type ===
|
|
24121
|
+
if (required !== null && initializer.type === import_utils128.AST_NODE_TYPES.CallExpression && initializer.callee.type === import_utils128.AST_NODE_TYPES.Identifier && (bindingOf(initializer.callee)?.defs.length ?? 0) > 0) return;
|
|
24122
|
+
if (required !== null && FS_MODULES.has(required) && node.id.type === import_utils128.AST_NODE_TYPES.Identifier) {
|
|
24006
24123
|
declare(node.id, { fsObject: true });
|
|
24007
24124
|
return;
|
|
24008
24125
|
}
|
|
24009
|
-
if (node.id.type ===
|
|
24126
|
+
if (node.id.type === import_utils128.AST_NODE_TYPES.ObjectPattern && required !== null && FS_MODULES.has(required)) {
|
|
24010
24127
|
declareFsReaders(node.id);
|
|
24011
24128
|
return;
|
|
24012
24129
|
}
|
|
24013
|
-
if (node.id.type !==
|
|
24130
|
+
if (node.id.type !== import_utils128.AST_NODE_TYPES.Identifier) return;
|
|
24014
24131
|
declare(node.id, { collection: sourceCollection(node.init), path: sourcePath(node.init), rawOrigins: rawOrigins(node.init) });
|
|
24015
24132
|
},
|
|
24016
24133
|
AssignmentExpression(node) {
|
|
24017
|
-
if (node.left.type ===
|
|
24134
|
+
if (node.left.type === import_utils128.AST_NODE_TYPES.Identifier) declare(node.left, {});
|
|
24018
24135
|
},
|
|
24019
24136
|
ForOfStatement(node) {
|
|
24020
24137
|
const right = unwrap6(node.right);
|
|
24021
|
-
const collection = right.type ===
|
|
24022
|
-
const left = node.left.type ===
|
|
24023
|
-
if (collection && left?.type ===
|
|
24138
|
+
const collection = right.type === import_utils128.AST_NODE_TYPES.Identifier && visible("collections", right);
|
|
24139
|
+
const left = node.left.type === import_utils128.AST_NODE_TYPES.VariableDeclaration ? node.left.declarations[0]?.id : node.left;
|
|
24140
|
+
if (collection && left?.type === import_utils128.AST_NODE_TYPES.Identifier) declare(left, { path: true });
|
|
24024
24141
|
},
|
|
24025
24142
|
CallExpression(node) {
|
|
24026
24143
|
const origins = rawAssertionOrigins(node);
|
|
@@ -24038,22 +24155,22 @@ var source_coupled_test_default = createSourceCoupledRule(
|
|
|
24038
24155
|
GENERAL_SOURCE_SUFFIX_RE
|
|
24039
24156
|
);
|
|
24040
24157
|
function importedAssertionKind(specifier) {
|
|
24041
|
-
if (specifier.type !==
|
|
24158
|
+
if (specifier.type !== import_utils128.AST_NODE_TYPES.ImportSpecifier && specifier.type !== import_utils128.AST_NODE_TYPES.ImportDefaultSpecifier && specifier.type !== import_utils128.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.parent.type !== import_utils128.AST_NODE_TYPES.ImportDeclaration) return null;
|
|
24042
24159
|
const source = importSource(specifier.parent);
|
|
24043
24160
|
if (source !== null && ASSERT_MODULES.has(source)) {
|
|
24044
|
-
if (specifier.type !==
|
|
24045
|
-
const imported2 = specifier.imported.type ===
|
|
24161
|
+
if (specifier.type !== import_utils128.AST_NODE_TYPES.ImportSpecifier) return "assert";
|
|
24162
|
+
const imported2 = specifier.imported.type === import_utils128.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
24046
24163
|
if (imported2 === "strict" || ASSERT_MATCHERS.has(imported2)) return "assert";
|
|
24047
24164
|
return null;
|
|
24048
24165
|
}
|
|
24049
|
-
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !==
|
|
24050
|
-
const imported = specifier.imported.type ===
|
|
24166
|
+
if (source === null || !EXPECT_MODULES.has(source) || specifier.type !== import_utils128.AST_NODE_TYPES.ImportSpecifier) return null;
|
|
24167
|
+
const imported = specifier.imported.type === import_utils128.AST_NODE_TYPES.Identifier ? specifier.imported.name : String(specifier.imported.value);
|
|
24051
24168
|
if (imported === "assert" || imported === "expect") return imported;
|
|
24052
24169
|
return null;
|
|
24053
24170
|
}
|
|
24054
24171
|
|
|
24055
24172
|
// src/rules/sole-export-matches-filename.ts
|
|
24056
|
-
var
|
|
24173
|
+
var import_utils129 = require("@typescript-eslint/utils");
|
|
24057
24174
|
|
|
24058
24175
|
// src/rules/_is-framework-entrypoint.ts
|
|
24059
24176
|
var import_node_fs2 = require("fs");
|
|
@@ -24169,7 +24286,7 @@ var sole_export_matches_filename_default = createRule({
|
|
|
24169
24286
|
if (only === void 0) return;
|
|
24170
24287
|
if (isFrameworkEntrypoint(normalizedFilename, only.key)) return;
|
|
24171
24288
|
if (only.name === "onRouterTransitionStart" && /(?:^|\/)instrumentation-client\.[jt]s$/u.test(normalizedFilename)) return;
|
|
24172
|
-
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type ===
|
|
24289
|
+
if (only.name === "collections" && /(?:^|\/)src\/content\.config\.(?:ts|js|mjs)$/u.test(normalizedFilename) && program.body.some((statement) => statement.type === import_utils129.AST_NODE_TYPES.ImportDeclaration && statement.source.value === "astro:content")) return;
|
|
24173
24290
|
const exportedStem = kebabCase(only.name);
|
|
24174
24291
|
if (exportedStem === "") return;
|
|
24175
24292
|
const expected = `${fileStem.startsWith("_") ? "_" : ""}${exportedStem}`;
|
|
@@ -24219,7 +24336,7 @@ var iac_source_coupled_test_default = createSourceCoupledRule(
|
|
|
24219
24336
|
);
|
|
24220
24337
|
|
|
24221
24338
|
// src/rules/require-pascal-case-zod-schema-name.ts
|
|
24222
|
-
var
|
|
24339
|
+
var import_utils130 = require("@typescript-eslint/utils");
|
|
24223
24340
|
var REQUIRE_PASCAL_CASE_ZOD_SCHEMA_NAME_DOCUMENTATION = {
|
|
24224
24341
|
summary: "Require confirmed module-level Zod schema contracts to use PascalCase with a `Schema` suffix.",
|
|
24225
24342
|
rationale: "A reusable Zod schema is a runtime type contract. PascalCase mirrors that role; SCREAMING_SNAKE_CASE should remain reserved for scalar values and lookup tables.",
|
|
@@ -24351,19 +24468,19 @@ var SCHEMA_RETURNING_METHODS = /* @__PURE__ */ new Set([
|
|
|
24351
24468
|
"superRefine",
|
|
24352
24469
|
"transform"
|
|
24353
24470
|
]);
|
|
24354
|
-
var terminalMethodName = (callee) =>
|
|
24471
|
+
var terminalMethodName = (callee) => import_utils130.ASTUtils.getPropertyName(callee) !== null ? import_utils130.ASTUtils.getPropertyName(callee) ?? "" : null;
|
|
24355
24472
|
var calleeChainRoot2 = (node) => {
|
|
24356
24473
|
let current = node;
|
|
24357
24474
|
for (; ; ) {
|
|
24358
24475
|
current = unwrapExpression(current);
|
|
24359
|
-
if (current.type ===
|
|
24476
|
+
if (current.type === import_utils130.AST_NODE_TYPES.Identifier) {
|
|
24360
24477
|
return current;
|
|
24361
24478
|
}
|
|
24362
|
-
if (current.type ===
|
|
24479
|
+
if (current.type === import_utils130.AST_NODE_TYPES.MemberExpression) {
|
|
24363
24480
|
current = current.object;
|
|
24364
24481
|
continue;
|
|
24365
24482
|
}
|
|
24366
|
-
if (current.type ===
|
|
24483
|
+
if (current.type === import_utils130.AST_NODE_TYPES.CallExpression) {
|
|
24367
24484
|
current = unwrapExpression(current.callee);
|
|
24368
24485
|
continue;
|
|
24369
24486
|
}
|
|
@@ -24375,13 +24492,13 @@ var chainMemberNames2 = (node) => {
|
|
|
24375
24492
|
let current = node;
|
|
24376
24493
|
for (; ; ) {
|
|
24377
24494
|
current = unwrapExpression(current);
|
|
24378
|
-
if (current.type ===
|
|
24379
|
-
if (
|
|
24380
|
-
names.push(
|
|
24495
|
+
if (current.type === import_utils130.AST_NODE_TYPES.MemberExpression) {
|
|
24496
|
+
if (import_utils130.ASTUtils.getPropertyName(current) === null) return [];
|
|
24497
|
+
names.push(import_utils130.ASTUtils.getPropertyName(current) ?? "");
|
|
24381
24498
|
current = current.object;
|
|
24382
24499
|
continue;
|
|
24383
24500
|
}
|
|
24384
|
-
if (current.type ===
|
|
24501
|
+
if (current.type === import_utils130.AST_NODE_TYPES.CallExpression) {
|
|
24385
24502
|
current = unwrapExpression(current.callee);
|
|
24386
24503
|
continue;
|
|
24387
24504
|
}
|
|
@@ -24392,9 +24509,9 @@ var chainMemberNames2 = (node) => {
|
|
|
24392
24509
|
};
|
|
24393
24510
|
var isModuleDeclarator = (node) => {
|
|
24394
24511
|
const declaration = node.parent;
|
|
24395
|
-
if (declaration.type !==
|
|
24512
|
+
if (declaration.type !== import_utils130.AST_NODE_TYPES.VariableDeclaration) return false;
|
|
24396
24513
|
const owner = declaration.parent;
|
|
24397
|
-
return owner.type ===
|
|
24514
|
+
return owner.type === import_utils130.AST_NODE_TYPES.Program || owner.type === import_utils130.AST_NODE_TYPES.ExportNamedDeclaration && owner.parent.type === import_utils130.AST_NODE_TYPES.Program;
|
|
24398
24515
|
};
|
|
24399
24516
|
var require_pascal_case_zod_schema_name_default = createRule({
|
|
24400
24517
|
name: "require-pascal-case-zod-schema-name",
|
|
@@ -24414,7 +24531,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24414
24531
|
const zodBindings = /* @__PURE__ */ new Set();
|
|
24415
24532
|
const schemaBindings = /* @__PURE__ */ new Set();
|
|
24416
24533
|
function resolvedBinding(identifier) {
|
|
24417
|
-
return
|
|
24534
|
+
return import_utils130.ASTUtils.findVariable(
|
|
24418
24535
|
context.sourceCode.getScope(identifier),
|
|
24419
24536
|
identifier.name
|
|
24420
24537
|
);
|
|
@@ -24425,10 +24542,10 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24425
24542
|
}
|
|
24426
24543
|
function isConfirmedSchema(expression) {
|
|
24427
24544
|
const init = unwrapExpression(expression);
|
|
24428
|
-
if (init.type ===
|
|
24429
|
-
if (init.type !==
|
|
24545
|
+
if (init.type === import_utils130.AST_NODE_TYPES.Identifier) return isSchemaBinding(init);
|
|
24546
|
+
if (init.type !== import_utils130.AST_NODE_TYPES.CallExpression) return false;
|
|
24430
24547
|
const callee = unwrapExpression(init.callee);
|
|
24431
|
-
if (callee.type !==
|
|
24548
|
+
if (callee.type !== import_utils130.AST_NODE_TYPES.MemberExpression) {
|
|
24432
24549
|
return false;
|
|
24433
24550
|
}
|
|
24434
24551
|
const terminal = terminalMethodName(callee);
|
|
@@ -24458,7 +24575,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24458
24575
|
ImportDeclaration(node) {
|
|
24459
24576
|
if (!isZodModule(node.source.value)) return;
|
|
24460
24577
|
for (const specifier of node.specifiers) {
|
|
24461
|
-
if (specifier.type ===
|
|
24578
|
+
if (specifier.type === import_utils130.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils130.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils130.AST_NODE_TYPES.ImportSpecifier && (specifier.imported.type === import_utils130.AST_NODE_TYPES.Identifier ? specifier.imported.name === "z" : specifier.imported.value === "z")) {
|
|
24462
24579
|
recordZodBinding(specifier.local);
|
|
24463
24580
|
}
|
|
24464
24581
|
}
|
|
@@ -24467,7 +24584,7 @@ var require_pascal_case_zod_schema_name_default = createRule({
|
|
|
24467
24584
|
if (!isModuleDeclarator(node)) return;
|
|
24468
24585
|
const init = node.init;
|
|
24469
24586
|
if (init === null || init === void 0) return;
|
|
24470
|
-
if (node.id.type !==
|
|
24587
|
+
if (node.id.type !== import_utils130.AST_NODE_TYPES.Identifier) return;
|
|
24471
24588
|
if (!isConfirmedSchema(init)) return;
|
|
24472
24589
|
const binding = resolvedBinding(node.id);
|
|
24473
24590
|
if (binding !== null) schemaBindings.add(binding);
|
|
@@ -24669,6 +24786,7 @@ var RULES = {
|
|
|
24669
24786
|
"prefer-whole-object-assertion": prefer_whole_object_assertion_default,
|
|
24670
24787
|
"repeated-static-call-cases": repeated_static_call_cases_default,
|
|
24671
24788
|
"prefer-zod-infer": prefer_zod_infer_default,
|
|
24789
|
+
"named-child-schema-type": named_child_schema_type_default,
|
|
24672
24790
|
"prefer-zod-parse-output-type": prefer_zod_parse_output_type_default,
|
|
24673
24791
|
"require-assert-never": require_assert_never_default,
|
|
24674
24792
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
@@ -24694,6 +24812,7 @@ var LIBRARY_IMPORT_POLICY = ["error", {
|
|
|
24694
24812
|
}];
|
|
24695
24813
|
var ADVISORY_RULES = [
|
|
24696
24814
|
"@sarj/excessive-commentary",
|
|
24815
|
+
"@sarj/named-child-schema-type",
|
|
24697
24816
|
"@sarj/no-bespoke-api-case-conversion",
|
|
24698
24817
|
"@sarj/no-duplicate-test-case",
|
|
24699
24818
|
"@sarj/no-json-stringify-object-equality",
|
|
@@ -24716,6 +24835,7 @@ var ADVISORY_RULES = [
|
|
|
24716
24835
|
"@sarj/require-sql-access-class"
|
|
24717
24836
|
];
|
|
24718
24837
|
var RECOMMENDED_RULES = {
|
|
24838
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24719
24839
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24720
24840
|
"@sarj/prefer-typed-reflection": "error",
|
|
24721
24841
|
"@sarj/no-broad-return-type": "error",
|
|
@@ -24833,6 +24953,7 @@ var RECOMMENDED_RULES = {
|
|
|
24833
24953
|
"@sarj/require-pascal-case-zod-schema-name": "error"
|
|
24834
24954
|
};
|
|
24835
24955
|
var STRICT_RULES = {
|
|
24956
|
+
"@sarj/named-child-schema-type": "warn",
|
|
24836
24957
|
"@sarj/no-conditional-empty-object-spread": "error",
|
|
24837
24958
|
"@sarj/prefer-typed-reflection": "error",
|
|
24838
24959
|
"@sarj/no-broad-return-type": "error",
|