@sarj/eslint-plugin 4.1.0 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/dist/index.cjs +682 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +687 -273
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3046,6 +3046,9 @@ var import_utils21 = require("@typescript-eslint/utils");
|
|
|
3046
3046
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
3047
3047
|
var ZOD_SUFFIX_RE = /Schema$/;
|
|
3048
3048
|
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
3049
|
+
function isZodModule(source) {
|
|
3050
|
+
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
3051
|
+
}
|
|
3049
3052
|
|
|
3050
3053
|
// src/rules/require-zod-form-validation.ts
|
|
3051
3054
|
var looksLikeZodSchema = (node) => {
|
|
@@ -4675,9 +4678,6 @@ var prefer_string_literal_union_default = import_utils30.ESLintUtils.RuleCreator
|
|
|
4675
4678
|
|
|
4676
4679
|
// src/rules/prefer-zod-enum.ts
|
|
4677
4680
|
var import_utils31 = require("@typescript-eslint/utils");
|
|
4678
|
-
function isZodModule(source) {
|
|
4679
|
-
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
4680
|
-
}
|
|
4681
4681
|
var prefer_zod_enum_default = import_utils31.ESLintUtils.RuleCreator(
|
|
4682
4682
|
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
4683
4683
|
)({
|
|
@@ -4763,11 +4763,414 @@ var prefer_zod_enum_default = import_utils31.ESLintUtils.RuleCreator(
|
|
|
4763
4763
|
}
|
|
4764
4764
|
});
|
|
4765
4765
|
|
|
4766
|
+
// src/rules/prefer-zod-infer.ts
|
|
4767
|
+
var import_utils32 = require("@typescript-eslint/utils");
|
|
4768
|
+
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
4769
|
+
"describe",
|
|
4770
|
+
"refine",
|
|
4771
|
+
"superRefine",
|
|
4772
|
+
"check",
|
|
4773
|
+
"meta",
|
|
4774
|
+
"register"
|
|
4775
|
+
]);
|
|
4776
|
+
var OPTIONAL_MODIFIERS = /* @__PURE__ */ new Set([
|
|
4777
|
+
"optional",
|
|
4778
|
+
"nullish",
|
|
4779
|
+
"default",
|
|
4780
|
+
"prefault",
|
|
4781
|
+
"catch"
|
|
4782
|
+
]);
|
|
4783
|
+
var NULLABLE_MODIFIERS = /* @__PURE__ */ new Set(["nullable", "nullish"]);
|
|
4784
|
+
var RESHAPING_MODIFIERS = /* @__PURE__ */ new Set([
|
|
4785
|
+
"transform",
|
|
4786
|
+
"pipe",
|
|
4787
|
+
"preprocess",
|
|
4788
|
+
"brand",
|
|
4789
|
+
"overwrite"
|
|
4790
|
+
]);
|
|
4791
|
+
var MODULE_LEVEL_RESHAPERS = /* @__PURE__ */ new Set([
|
|
4792
|
+
"transform",
|
|
4793
|
+
"pipe",
|
|
4794
|
+
"preprocess"
|
|
4795
|
+
]);
|
|
4796
|
+
var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
4797
|
+
"ZodType",
|
|
4798
|
+
"ZodSchema",
|
|
4799
|
+
"ZodTypeAny",
|
|
4800
|
+
"ZodMiniType",
|
|
4801
|
+
"Schema"
|
|
4802
|
+
]);
|
|
4803
|
+
var LEAF_NODE_TYPES = {
|
|
4804
|
+
string: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4805
|
+
email: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4806
|
+
url: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4807
|
+
uuid: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4808
|
+
ulid: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4809
|
+
cuid: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4810
|
+
cuid2: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4811
|
+
nanoid: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4812
|
+
iso: [import_utils32.AST_NODE_TYPES.TSStringKeyword],
|
|
4813
|
+
number: [import_utils32.AST_NODE_TYPES.TSNumberKeyword],
|
|
4814
|
+
int: [import_utils32.AST_NODE_TYPES.TSNumberKeyword],
|
|
4815
|
+
float32: [import_utils32.AST_NODE_TYPES.TSNumberKeyword],
|
|
4816
|
+
float64: [import_utils32.AST_NODE_TYPES.TSNumberKeyword],
|
|
4817
|
+
boolean: [import_utils32.AST_NODE_TYPES.TSBooleanKeyword],
|
|
4818
|
+
bigint: [import_utils32.AST_NODE_TYPES.TSBigIntKeyword],
|
|
4819
|
+
symbol: [import_utils32.AST_NODE_TYPES.TSSymbolKeyword],
|
|
4820
|
+
any: [import_utils32.AST_NODE_TYPES.TSAnyKeyword],
|
|
4821
|
+
unknown: [import_utils32.AST_NODE_TYPES.TSUnknownKeyword],
|
|
4822
|
+
never: [import_utils32.AST_NODE_TYPES.TSNeverKeyword],
|
|
4823
|
+
void: [import_utils32.AST_NODE_TYPES.TSVoidKeyword],
|
|
4824
|
+
null: [import_utils32.AST_NODE_TYPES.TSNullKeyword],
|
|
4825
|
+
undefined: [import_utils32.AST_NODE_TYPES.TSUndefinedKeyword],
|
|
4826
|
+
literal: [import_utils32.AST_NODE_TYPES.TSLiteralType],
|
|
4827
|
+
date: [import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4828
|
+
array: [import_utils32.AST_NODE_TYPES.TSArrayType, import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4829
|
+
tuple: [import_utils32.AST_NODE_TYPES.TSTupleType],
|
|
4830
|
+
object: [import_utils32.AST_NODE_TYPES.TSTypeLiteral, import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4831
|
+
strictObject: [import_utils32.AST_NODE_TYPES.TSTypeLiteral, import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4832
|
+
looseObject: [import_utils32.AST_NODE_TYPES.TSTypeLiteral, import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4833
|
+
record: [import_utils32.AST_NODE_TYPES.TSTypeReference, import_utils32.AST_NODE_TYPES.TSTypeLiteral],
|
|
4834
|
+
map: [import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4835
|
+
set: [import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4836
|
+
promise: [import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4837
|
+
enum: [import_utils32.AST_NODE_TYPES.TSUnionType, import_utils32.AST_NODE_TYPES.TSTypeReference, import_utils32.AST_NODE_TYPES.TSLiteralType],
|
|
4838
|
+
nativeEnum: [import_utils32.AST_NODE_TYPES.TSUnionType, import_utils32.AST_NODE_TYPES.TSTypeReference, import_utils32.AST_NODE_TYPES.TSLiteralType],
|
|
4839
|
+
union: [import_utils32.AST_NODE_TYPES.TSUnionType, import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4840
|
+
discriminatedUnion: [import_utils32.AST_NODE_TYPES.TSUnionType, import_utils32.AST_NODE_TYPES.TSTypeReference],
|
|
4841
|
+
intersection: [import_utils32.AST_NODE_TYPES.TSIntersectionType, import_utils32.AST_NODE_TYPES.TSTypeReference]
|
|
4842
|
+
};
|
|
4843
|
+
function normalizeSchemaName(name) {
|
|
4844
|
+
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
4845
|
+
}
|
|
4846
|
+
function normalizeTypeName(name) {
|
|
4847
|
+
return name.replace(/Type$/, "").toLowerCase();
|
|
4848
|
+
}
|
|
4849
|
+
function unwrapNullish(annotation) {
|
|
4850
|
+
if (annotation.type !== import_utils32.AST_NODE_TYPES.TSUnionType) {
|
|
4851
|
+
return {
|
|
4852
|
+
core: annotation,
|
|
4853
|
+
nullable: annotation.type === import_utils32.AST_NODE_TYPES.TSNullKeyword
|
|
4854
|
+
};
|
|
4855
|
+
}
|
|
4856
|
+
const rest = [];
|
|
4857
|
+
let nullable = false;
|
|
4858
|
+
for (const member of annotation.types) {
|
|
4859
|
+
if (member.type === import_utils32.AST_NODE_TYPES.TSNullKeyword) {
|
|
4860
|
+
nullable = true;
|
|
4861
|
+
continue;
|
|
4862
|
+
}
|
|
4863
|
+
if (member.type === import_utils32.AST_NODE_TYPES.TSUndefinedKeyword) {
|
|
4864
|
+
continue;
|
|
4865
|
+
}
|
|
4866
|
+
rest.push(member);
|
|
4867
|
+
}
|
|
4868
|
+
if (rest.length === 1) {
|
|
4869
|
+
return { core: rest[0] ?? null, nullable };
|
|
4870
|
+
}
|
|
4871
|
+
return { core: rest.length === 0 ? null : annotation, nullable };
|
|
4872
|
+
}
|
|
4873
|
+
function leafAgrees(leaf, annotation) {
|
|
4874
|
+
if (leaf === null || annotation === null) {
|
|
4875
|
+
return null;
|
|
4876
|
+
}
|
|
4877
|
+
const expected = LEAF_NODE_TYPES[leaf];
|
|
4878
|
+
if (expected === void 0) {
|
|
4879
|
+
return null;
|
|
4880
|
+
}
|
|
4881
|
+
const { core } = unwrapNullish(annotation);
|
|
4882
|
+
if (core === null) {
|
|
4883
|
+
return null;
|
|
4884
|
+
}
|
|
4885
|
+
return expected.includes(core.type);
|
|
4886
|
+
}
|
|
4887
|
+
var prefer_zod_infer_default = import_utils32.ESLintUtils.RuleCreator(
|
|
4888
|
+
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
4889
|
+
)({
|
|
4890
|
+
name: "prefer-zod-infer",
|
|
4891
|
+
meta: {
|
|
4892
|
+
type: "problem",
|
|
4893
|
+
docs: {
|
|
4894
|
+
description: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it."
|
|
4895
|
+
},
|
|
4896
|
+
schema: [
|
|
4897
|
+
{
|
|
4898
|
+
type: "object",
|
|
4899
|
+
additionalProperties: false,
|
|
4900
|
+
properties: {
|
|
4901
|
+
ignoreTypeNames: {
|
|
4902
|
+
type: "array",
|
|
4903
|
+
items: { type: "string" }
|
|
4904
|
+
},
|
|
4905
|
+
requireIdenticalShape: { type: "boolean" }
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
],
|
|
4909
|
+
messages: {
|
|
4910
|
+
handWrittenTwin: "`{{typeName}}` restates the shape of the Zod schema `{{schemaName}}` declared in this module. Derive it instead \u2014 `type {{typeName}} = z.infer<typeof {{schemaName}}>` \u2014 so a field added to the schema cannot silently leave the type behind."
|
|
4911
|
+
}
|
|
4912
|
+
},
|
|
4913
|
+
defaultOptions: [{}],
|
|
4914
|
+
create(context, [optionsArg]) {
|
|
4915
|
+
const ignorePatterns = (optionsArg?.ignoreTypeNames ?? []).map(
|
|
4916
|
+
(source) => new RegExp(source, "u")
|
|
4917
|
+
);
|
|
4918
|
+
const requireIdenticalShape = optionsArg?.requireIdenticalShape ?? true;
|
|
4919
|
+
if (isTestFile(context.filename) || isStoryFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
4920
|
+
return {};
|
|
4921
|
+
}
|
|
4922
|
+
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
4923
|
+
const schemas = [];
|
|
4924
|
+
const typeDeclarations = [];
|
|
4925
|
+
const constrainedTypeNames = /* @__PURE__ */ new Set();
|
|
4926
|
+
const reshapedSchemaNames = /* @__PURE__ */ new Set();
|
|
4927
|
+
function zodCallChain(node) {
|
|
4928
|
+
const chain = [];
|
|
4929
|
+
let current = node;
|
|
4930
|
+
while (current.type === import_utils32.AST_NODE_TYPES.CallExpression) {
|
|
4931
|
+
const callee = current.callee;
|
|
4932
|
+
if (callee.type !== import_utils32.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils32.AST_NODE_TYPES.Identifier) {
|
|
4933
|
+
return null;
|
|
4934
|
+
}
|
|
4935
|
+
chain.push(current);
|
|
4936
|
+
const receiver = callee.object;
|
|
4937
|
+
if (receiver.type === import_utils32.AST_NODE_TYPES.Identifier) {
|
|
4938
|
+
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
4939
|
+
}
|
|
4940
|
+
current = receiver;
|
|
4941
|
+
}
|
|
4942
|
+
return null;
|
|
4943
|
+
}
|
|
4944
|
+
function methodName(call) {
|
|
4945
|
+
const callee = call.callee;
|
|
4946
|
+
return callee.type === import_utils32.AST_NODE_TYPES.MemberExpression && callee.property.type === import_utils32.AST_NODE_TYPES.Identifier ? callee.property.name : "";
|
|
4947
|
+
}
|
|
4948
|
+
function schemaField(node) {
|
|
4949
|
+
const modifiers = [];
|
|
4950
|
+
let current = node;
|
|
4951
|
+
let leaf = null;
|
|
4952
|
+
while (current.type === import_utils32.AST_NODE_TYPES.CallExpression) {
|
|
4953
|
+
const callee = current.callee;
|
|
4954
|
+
if (callee.type !== import_utils32.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils32.AST_NODE_TYPES.Identifier) {
|
|
4955
|
+
break;
|
|
4956
|
+
}
|
|
4957
|
+
const receiver = callee.object;
|
|
4958
|
+
if (receiver.type === import_utils32.AST_NODE_TYPES.Identifier && zodNamespaces.has(receiver.name)) {
|
|
4959
|
+
leaf = callee.property.name;
|
|
4960
|
+
break;
|
|
4961
|
+
}
|
|
4962
|
+
modifiers.push(callee.property.name);
|
|
4963
|
+
current = receiver;
|
|
4964
|
+
}
|
|
4965
|
+
return {
|
|
4966
|
+
leaf,
|
|
4967
|
+
optional: modifiers.some((name) => OPTIONAL_MODIFIERS.has(name)),
|
|
4968
|
+
nullable: modifiers.some((name) => NULLABLE_MODIFIERS.has(name)),
|
|
4969
|
+
reshaped: modifiers.some((name) => RESHAPING_MODIFIERS.has(name))
|
|
4970
|
+
};
|
|
4971
|
+
}
|
|
4972
|
+
function schemaFields(init) {
|
|
4973
|
+
const chain = zodCallChain(init);
|
|
4974
|
+
if (chain === null || chain.length === 0) {
|
|
4975
|
+
return null;
|
|
4976
|
+
}
|
|
4977
|
+
const [base, ...rest] = chain;
|
|
4978
|
+
if (base === void 0) {
|
|
4979
|
+
return null;
|
|
4980
|
+
}
|
|
4981
|
+
const baseMethod = methodName(base);
|
|
4982
|
+
if (baseMethod !== "object" && baseMethod !== "strictObject") {
|
|
4983
|
+
return null;
|
|
4984
|
+
}
|
|
4985
|
+
if (rest.some((call) => !SHAPE_PRESERVING_METHODS.has(methodName(call)))) {
|
|
4986
|
+
return null;
|
|
4987
|
+
}
|
|
4988
|
+
const shape = base.arguments[0];
|
|
4989
|
+
if (shape === void 0 || shape.type !== import_utils32.AST_NODE_TYPES.ObjectExpression) {
|
|
4990
|
+
return null;
|
|
4991
|
+
}
|
|
4992
|
+
const fields = /* @__PURE__ */ new Map();
|
|
4993
|
+
for (const property of shape.properties) {
|
|
4994
|
+
if (property.type !== import_utils32.AST_NODE_TYPES.Property || property.computed) {
|
|
4995
|
+
return null;
|
|
4996
|
+
}
|
|
4997
|
+
const { key } = property;
|
|
4998
|
+
const name = key.type === import_utils32.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils32.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
4999
|
+
if (name === null) {
|
|
5000
|
+
return null;
|
|
5001
|
+
}
|
|
5002
|
+
fields.set(name, schemaField(property.value));
|
|
5003
|
+
}
|
|
5004
|
+
return fields.size === 0 ? null : fields;
|
|
5005
|
+
}
|
|
5006
|
+
function typeMembers(members) {
|
|
5007
|
+
const result = /* @__PURE__ */ new Map();
|
|
5008
|
+
for (const member of members) {
|
|
5009
|
+
if (member.type !== import_utils32.AST_NODE_TYPES.TSPropertySignature || member.computed) {
|
|
5010
|
+
return null;
|
|
5011
|
+
}
|
|
5012
|
+
const { key } = member;
|
|
5013
|
+
const name = key.type === import_utils32.AST_NODE_TYPES.Identifier ? key.name : key.type === import_utils32.AST_NODE_TYPES.Literal && typeof key.value === "string" ? key.value : null;
|
|
5014
|
+
if (name === null) {
|
|
5015
|
+
return null;
|
|
5016
|
+
}
|
|
5017
|
+
const annotation = member.typeAnnotation?.typeAnnotation ?? null;
|
|
5018
|
+
result.set(name, {
|
|
5019
|
+
optional: member.optional === true,
|
|
5020
|
+
nullable: annotation !== null && unwrapNullish(annotation).nullable,
|
|
5021
|
+
annotation
|
|
5022
|
+
});
|
|
5023
|
+
}
|
|
5024
|
+
return result.size === 0 ? null : result;
|
|
5025
|
+
}
|
|
5026
|
+
function collectConstrainedNames(node) {
|
|
5027
|
+
if (node.type === import_utils32.AST_NODE_TYPES.TSTypeReference) {
|
|
5028
|
+
if (node.typeName.type === import_utils32.AST_NODE_TYPES.Identifier) {
|
|
5029
|
+
constrainedTypeNames.add(node.typeName.name);
|
|
5030
|
+
}
|
|
5031
|
+
for (const argument of node.typeArguments?.params ?? []) {
|
|
5032
|
+
collectConstrainedNames(argument);
|
|
5033
|
+
}
|
|
5034
|
+
return;
|
|
5035
|
+
}
|
|
5036
|
+
if (node.type === import_utils32.AST_NODE_TYPES.TSArrayType) {
|
|
5037
|
+
collectConstrainedNames(node.elementType);
|
|
5038
|
+
return;
|
|
5039
|
+
}
|
|
5040
|
+
if (node.type === import_utils32.AST_NODE_TYPES.TSUnionType || node.type === import_utils32.AST_NODE_TYPES.TSIntersectionType) {
|
|
5041
|
+
for (const member of node.types) {
|
|
5042
|
+
collectConstrainedNames(member);
|
|
5043
|
+
}
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
function isTwin(fields, members) {
|
|
5047
|
+
if (!requireIdenticalShape) {
|
|
5048
|
+
return true;
|
|
5049
|
+
}
|
|
5050
|
+
if (fields.size !== members.size) {
|
|
5051
|
+
return false;
|
|
5052
|
+
}
|
|
5053
|
+
let agreements = 0;
|
|
5054
|
+
for (const [name, field] of fields) {
|
|
5055
|
+
const member = members.get(name);
|
|
5056
|
+
if (member === void 0) {
|
|
5057
|
+
return false;
|
|
5058
|
+
}
|
|
5059
|
+
if (field.reshaped) {
|
|
5060
|
+
return false;
|
|
5061
|
+
}
|
|
5062
|
+
if (field.optional !== member.optional) {
|
|
5063
|
+
return false;
|
|
5064
|
+
}
|
|
5065
|
+
if (field.nullable !== member.nullable) {
|
|
5066
|
+
return false;
|
|
5067
|
+
}
|
|
5068
|
+
const agrees = leafAgrees(field.leaf, member.annotation);
|
|
5069
|
+
if (agrees === false) {
|
|
5070
|
+
return false;
|
|
5071
|
+
}
|
|
5072
|
+
if (agrees === true) {
|
|
5073
|
+
agreements += 1;
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
return agreements > 0;
|
|
5077
|
+
}
|
|
5078
|
+
return {
|
|
5079
|
+
ImportDeclaration(node) {
|
|
5080
|
+
if (!isZodModule(node.source.value)) {
|
|
5081
|
+
return;
|
|
5082
|
+
}
|
|
5083
|
+
for (const specifier of node.specifiers) {
|
|
5084
|
+
if (specifier.type === import_utils32.AST_NODE_TYPES.ImportNamespaceSpecifier || specifier.type === import_utils32.AST_NODE_TYPES.ImportDefaultSpecifier || specifier.type === import_utils32.AST_NODE_TYPES.ImportSpecifier && specifier.imported.type === import_utils32.AST_NODE_TYPES.Identifier && specifier.imported.name === "z") {
|
|
5085
|
+
zodNamespaces.add(specifier.local.name);
|
|
5086
|
+
}
|
|
5087
|
+
}
|
|
5088
|
+
},
|
|
5089
|
+
VariableDeclarator(node) {
|
|
5090
|
+
if (node.id.type !== import_utils32.AST_NODE_TYPES.Identifier || node.init == null) {
|
|
5091
|
+
return;
|
|
5092
|
+
}
|
|
5093
|
+
const fields = schemaFields(node.init);
|
|
5094
|
+
if (fields !== null) {
|
|
5095
|
+
schemas.push({ name: node.id.name, fields });
|
|
5096
|
+
}
|
|
5097
|
+
},
|
|
5098
|
+
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
5099
|
+
"MemberExpression[computed=false]"(node) {
|
|
5100
|
+
if (node.object.type === import_utils32.AST_NODE_TYPES.Identifier && node.property.type === import_utils32.AST_NODE_TYPES.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
5101
|
+
reshapedSchemaNames.add(node.object.name);
|
|
5102
|
+
}
|
|
5103
|
+
},
|
|
5104
|
+
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
5105
|
+
TSTypeReference(node) {
|
|
5106
|
+
const { typeName } = node;
|
|
5107
|
+
const referenced = typeName.type === import_utils32.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils32.AST_NODE_TYPES.TSQualifiedName && typeName.right.type === import_utils32.AST_NODE_TYPES.Identifier ? typeName.right.name : null;
|
|
5108
|
+
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
5109
|
+
return;
|
|
5110
|
+
}
|
|
5111
|
+
for (const argument of node.typeArguments?.params ?? []) {
|
|
5112
|
+
collectConstrainedNames(argument);
|
|
5113
|
+
}
|
|
5114
|
+
},
|
|
5115
|
+
TSInterfaceDeclaration(node) {
|
|
5116
|
+
if (node.typeParameters !== void 0 || (node.extends?.length ?? 0) > 0) {
|
|
5117
|
+
return;
|
|
5118
|
+
}
|
|
5119
|
+
const members = typeMembers(node.body.body);
|
|
5120
|
+
if (members !== null) {
|
|
5121
|
+
typeDeclarations.push({ name: node.id.name, node: node.id, members });
|
|
5122
|
+
}
|
|
5123
|
+
},
|
|
5124
|
+
TSTypeAliasDeclaration(node) {
|
|
5125
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== import_utils32.AST_NODE_TYPES.TSTypeLiteral) {
|
|
5126
|
+
return;
|
|
5127
|
+
}
|
|
5128
|
+
const members = typeMembers(node.typeAnnotation.members);
|
|
5129
|
+
if (members !== null) {
|
|
5130
|
+
typeDeclarations.push({ name: node.id.name, node: node.id, members });
|
|
5131
|
+
}
|
|
5132
|
+
},
|
|
5133
|
+
"Program:exit"() {
|
|
5134
|
+
if (schemas.length === 0 || typeDeclarations.length === 0) {
|
|
5135
|
+
return;
|
|
5136
|
+
}
|
|
5137
|
+
const byName = /* @__PURE__ */ new Map();
|
|
5138
|
+
for (const schema of schemas) {
|
|
5139
|
+
const key = normalizeSchemaName(schema.name);
|
|
5140
|
+
if (key !== "" && !byName.has(key)) {
|
|
5141
|
+
byName.set(key, schema);
|
|
5142
|
+
}
|
|
5143
|
+
}
|
|
5144
|
+
for (const declaration of typeDeclarations) {
|
|
5145
|
+
if (constrainedTypeNames.has(declaration.name)) {
|
|
5146
|
+
continue;
|
|
5147
|
+
}
|
|
5148
|
+
if (ignorePatterns.some((pattern) => pattern.test(declaration.name))) {
|
|
5149
|
+
continue;
|
|
5150
|
+
}
|
|
5151
|
+
const schema = byName.get(normalizeTypeName(declaration.name));
|
|
5152
|
+
if (schema === void 0 || reshapedSchemaNames.has(schema.name)) {
|
|
5153
|
+
continue;
|
|
5154
|
+
}
|
|
5155
|
+
if (!isTwin(schema.fields, declaration.members)) {
|
|
5156
|
+
continue;
|
|
5157
|
+
}
|
|
5158
|
+
context.report({
|
|
5159
|
+
node: declaration.node,
|
|
5160
|
+
messageId: "handWrittenTwin",
|
|
5161
|
+
data: { typeName: declaration.name, schemaName: schema.name }
|
|
5162
|
+
});
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
};
|
|
5166
|
+
}
|
|
5167
|
+
});
|
|
5168
|
+
|
|
4766
5169
|
// src/rules/no-offset-pagination.ts
|
|
4767
|
-
var
|
|
5170
|
+
var import_utils34 = require("@typescript-eslint/utils");
|
|
4768
5171
|
|
|
4769
5172
|
// src/rules/_sql.ts
|
|
4770
|
-
var
|
|
5173
|
+
var import_utils33 = require("@typescript-eslint/utils");
|
|
4771
5174
|
function stripSqlNoise(text) {
|
|
4772
5175
|
const out = [...text];
|
|
4773
5176
|
const n = text.length;
|
|
@@ -4828,13 +5231,13 @@ function stripSqlNoise(text) {
|
|
|
4828
5231
|
var SUBSTITUTION_MARKER = "?";
|
|
4829
5232
|
function sqlTextOf(node) {
|
|
4830
5233
|
switch (node.type) {
|
|
4831
|
-
case
|
|
5234
|
+
case import_utils33.AST_NODE_TYPES.Literal:
|
|
4832
5235
|
return typeof node.value === "string" ? node.value : null;
|
|
4833
|
-
case
|
|
5236
|
+
case import_utils33.AST_NODE_TYPES.TemplateLiteral:
|
|
4834
5237
|
return node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(SUBSTITUTION_MARKER);
|
|
4835
|
-
case
|
|
5238
|
+
case import_utils33.AST_NODE_TYPES.TaggedTemplateExpression:
|
|
4836
5239
|
return sqlTextOf(node.quasi);
|
|
4837
|
-
case
|
|
5240
|
+
case import_utils33.AST_NODE_TYPES.BinaryExpression: {
|
|
4838
5241
|
if (node.operator !== "+") {
|
|
4839
5242
|
return null;
|
|
4840
5243
|
}
|
|
@@ -4842,7 +5245,7 @@ function sqlTextOf(node) {
|
|
|
4842
5245
|
const right = sqlTextOf(node.right);
|
|
4843
5246
|
return left !== null && right !== null ? left + right : null;
|
|
4844
5247
|
}
|
|
4845
|
-
case
|
|
5248
|
+
case import_utils33.AST_NODE_TYPES.ArrayExpression: {
|
|
4846
5249
|
const parts = [];
|
|
4847
5250
|
for (const element of node.elements) {
|
|
4848
5251
|
if (element === null) {
|
|
@@ -4862,7 +5265,7 @@ function sqlTextOf(node) {
|
|
|
4862
5265
|
}
|
|
4863
5266
|
function isJoinedFragmentArray(node) {
|
|
4864
5267
|
const parent = node.parent;
|
|
4865
|
-
return parent?.type ===
|
|
5268
|
+
return parent?.type === import_utils33.AST_NODE_TYPES.MemberExpression && parent.object === node && !parent.computed && parent.property.type === import_utils33.AST_NODE_TYPES.Identifier && parent.property.name === "join" && parent.parent?.type === import_utils33.AST_NODE_TYPES.CallExpression;
|
|
4866
5269
|
}
|
|
4867
5270
|
function markConsumed(node, consumed) {
|
|
4868
5271
|
consumed.add(node);
|
|
@@ -4912,7 +5315,7 @@ function createSqlListener(handler) {
|
|
|
4912
5315
|
// src/rules/no-offset-pagination.ts
|
|
4913
5316
|
var OFFSET_PAGINATION = /\bOFFSET\s+(?:%s|%\(\w+\)s|\?\d*|:\w+|@\w+|\$\d+|\d+)/i;
|
|
4914
5317
|
var OFFSET_GATE = /offset/i;
|
|
4915
|
-
var no_offset_pagination_default =
|
|
5318
|
+
var no_offset_pagination_default = import_utils34.ESLintUtils.RuleCreator(
|
|
4916
5319
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
4917
5320
|
)({
|
|
4918
5321
|
name: "no-offset-pagination",
|
|
@@ -4941,15 +5344,15 @@ var no_offset_pagination_default = import_utils33.ESLintUtils.RuleCreator(
|
|
|
4941
5344
|
});
|
|
4942
5345
|
|
|
4943
5346
|
// src/rules/no-positional-tuple-return.ts
|
|
4944
|
-
var
|
|
5347
|
+
var import_utils35 = require("@typescript-eslint/utils");
|
|
4945
5348
|
var MIN_ELEMENTS = 2;
|
|
4946
5349
|
var ACCESSOR_PAIR_LENGTH = 2;
|
|
4947
5350
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
4948
5351
|
function tupleReturnType(node) {
|
|
4949
|
-
if (node.type ===
|
|
5352
|
+
if (node.type === import_utils35.AST_NODE_TYPES.TSTupleType) {
|
|
4950
5353
|
return node;
|
|
4951
5354
|
}
|
|
4952
|
-
if (node.type ===
|
|
5355
|
+
if (node.type === import_utils35.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils35.AST_NODE_TYPES.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
4953
5356
|
const argument = node.typeArguments?.params[0];
|
|
4954
5357
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
4955
5358
|
}
|
|
@@ -4963,30 +5366,30 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
4963
5366
|
if (elements.length < MIN_ELEMENTS) {
|
|
4964
5367
|
return true;
|
|
4965
5368
|
}
|
|
4966
|
-
if (elements.some((element) => element.type ===
|
|
5369
|
+
if (elements.some((element) => element.type === import_utils35.AST_NODE_TYPES.TSRestType)) {
|
|
4967
5370
|
return true;
|
|
4968
5371
|
}
|
|
4969
|
-
if (elements.some((element) => element.type ===
|
|
5372
|
+
if (elements.some((element) => element.type === import_utils35.AST_NODE_TYPES.TSNamedTupleMember)) {
|
|
4970
5373
|
return true;
|
|
4971
5374
|
}
|
|
4972
|
-
if (elements[0]?.type ===
|
|
5375
|
+
if (elements[0]?.type === import_utils35.AST_NODE_TYPES.TSLiteralType) {
|
|
4973
5376
|
return true;
|
|
4974
5377
|
}
|
|
4975
|
-
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type ===
|
|
5378
|
+
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type === import_utils35.AST_NODE_TYPES.TSFunctionType)) {
|
|
4976
5379
|
return true;
|
|
4977
5380
|
}
|
|
4978
5381
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
4979
5382
|
return texts.size === 1;
|
|
4980
5383
|
}
|
|
4981
5384
|
function functionName(node) {
|
|
4982
|
-
if (node.type ===
|
|
5385
|
+
if (node.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration) {
|
|
4983
5386
|
return node.id?.name ?? null;
|
|
4984
5387
|
}
|
|
4985
5388
|
const parent = node.parent;
|
|
4986
|
-
if (parent?.type ===
|
|
5389
|
+
if (parent?.type === import_utils35.AST_NODE_TYPES.VariableDeclarator && parent.id.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4987
5390
|
return parent.id.name;
|
|
4988
5391
|
}
|
|
4989
|
-
if ((parent?.type ===
|
|
5392
|
+
if ((parent?.type === import_utils35.AST_NODE_TYPES.MethodDefinition || parent?.type === import_utils35.AST_NODE_TYPES.PropertyDefinition || parent?.type === import_utils35.AST_NODE_TYPES.Property) && parent.key.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
4990
5393
|
return parent.key.name;
|
|
4991
5394
|
}
|
|
4992
5395
|
return null;
|
|
@@ -4994,7 +5397,7 @@ function functionName(node) {
|
|
|
4994
5397
|
function isInlineExported(node) {
|
|
4995
5398
|
for (let current = node; current != null; current = current.parent) {
|
|
4996
5399
|
const parent = current.parent;
|
|
4997
|
-
if (parent?.type ===
|
|
5400
|
+
if (parent?.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration || parent?.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
4998
5401
|
return true;
|
|
4999
5402
|
}
|
|
5000
5403
|
}
|
|
@@ -5003,18 +5406,18 @@ function isInlineExported(node) {
|
|
|
5003
5406
|
function moduleScopeBindingName(node) {
|
|
5004
5407
|
let current = node;
|
|
5005
5408
|
let child = node;
|
|
5006
|
-
while (current.parent != null && current.parent.type !==
|
|
5409
|
+
while (current.parent != null && current.parent.type !== import_utils35.AST_NODE_TYPES.Program) {
|
|
5007
5410
|
child = current;
|
|
5008
5411
|
current = current.parent;
|
|
5009
5412
|
}
|
|
5010
|
-
if (current.parent?.type !==
|
|
5413
|
+
if (current.parent?.type !== import_utils35.AST_NODE_TYPES.Program) {
|
|
5011
5414
|
return null;
|
|
5012
5415
|
}
|
|
5013
|
-
if (current.type ===
|
|
5416
|
+
if (current.type === import_utils35.AST_NODE_TYPES.FunctionDeclaration || current.type === import_utils35.AST_NODE_TYPES.ClassDeclaration) {
|
|
5014
5417
|
return current.id?.name ?? null;
|
|
5015
5418
|
}
|
|
5016
|
-
if (current.type ===
|
|
5017
|
-
if (child.type !==
|
|
5419
|
+
if (current.type === import_utils35.AST_NODE_TYPES.VariableDeclaration) {
|
|
5420
|
+
if (child.type !== import_utils35.AST_NODE_TYPES.VariableDeclarator || child.id.type !== import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5018
5421
|
return null;
|
|
5019
5422
|
}
|
|
5020
5423
|
return child.id.name;
|
|
@@ -5024,19 +5427,19 @@ function moduleScopeBindingName(node) {
|
|
|
5024
5427
|
function specifierExportedNames(program) {
|
|
5025
5428
|
const names = /* @__PURE__ */ new Set();
|
|
5026
5429
|
for (const statement of program.body) {
|
|
5027
|
-
if (statement.type ===
|
|
5430
|
+
if (statement.type === import_utils35.AST_NODE_TYPES.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
5028
5431
|
for (const specifier of statement.specifiers) {
|
|
5029
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
5432
|
+
if (specifier.exportKind !== "type" && specifier.local.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5030
5433
|
names.add(specifier.local.name);
|
|
5031
5434
|
}
|
|
5032
5435
|
}
|
|
5033
5436
|
continue;
|
|
5034
5437
|
}
|
|
5035
|
-
if (statement.type ===
|
|
5438
|
+
if (statement.type === import_utils35.AST_NODE_TYPES.ExportDefaultDeclaration && statement.declaration.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5036
5439
|
names.add(statement.declaration.name);
|
|
5037
5440
|
continue;
|
|
5038
5441
|
}
|
|
5039
|
-
if (statement.type ===
|
|
5442
|
+
if (statement.type === import_utils35.AST_NODE_TYPES.TSExportAssignment && statement.expression.type === import_utils35.AST_NODE_TYPES.Identifier) {
|
|
5040
5443
|
names.add(statement.expression.name);
|
|
5041
5444
|
}
|
|
5042
5445
|
}
|
|
@@ -5052,7 +5455,7 @@ function isExported(node, specifierExports) {
|
|
|
5052
5455
|
const binding = moduleScopeBindingName(node);
|
|
5053
5456
|
return binding !== null && specifierExports.has(binding);
|
|
5054
5457
|
}
|
|
5055
|
-
var no_positional_tuple_return_default =
|
|
5458
|
+
var no_positional_tuple_return_default = import_utils35.ESLintUtils.RuleCreator(
|
|
5056
5459
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5057
5460
|
)({
|
|
5058
5461
|
name: "no-positional-tuple-return",
|
|
@@ -5100,16 +5503,16 @@ var no_positional_tuple_return_default = import_utils34.ESLintUtils.RuleCreator(
|
|
|
5100
5503
|
});
|
|
5101
5504
|
|
|
5102
5505
|
// src/rules/no-repeated-string-literal.ts
|
|
5103
|
-
var
|
|
5506
|
+
var import_utils36 = require("@typescript-eslint/utils");
|
|
5104
5507
|
var MIN_LENGTH = 40;
|
|
5105
5508
|
var MIN_DISTINCT_SCOPES = 2;
|
|
5106
5509
|
var PREVIEW_LENGTH = 40;
|
|
5107
5510
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
5108
5511
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
5109
5512
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5513
|
+
import_utils36.AST_NODE_TYPES.FunctionDeclaration,
|
|
5514
|
+
import_utils36.AST_NODE_TYPES.FunctionExpression,
|
|
5515
|
+
import_utils36.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5113
5516
|
]);
|
|
5114
5517
|
function isStructured(value) {
|
|
5115
5518
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -5131,9 +5534,9 @@ function isScaffolding(node) {
|
|
|
5131
5534
|
if (parent === void 0) {
|
|
5132
5535
|
return true;
|
|
5133
5536
|
}
|
|
5134
|
-
return parent.type ===
|
|
5537
|
+
return parent.type === import_utils36.AST_NODE_TYPES.ImportDeclaration || parent.type === import_utils36.AST_NODE_TYPES.ExportNamedDeclaration || parent.type === import_utils36.AST_NODE_TYPES.ExportAllDeclaration || parent.type === import_utils36.AST_NODE_TYPES.TSImportType || parent.type === import_utils36.AST_NODE_TYPES.JSXAttribute || parent.type === import_utils36.AST_NODE_TYPES.TSLiteralType;
|
|
5135
5538
|
}
|
|
5136
|
-
var no_repeated_string_literal_default =
|
|
5539
|
+
var no_repeated_string_literal_default = import_utils36.ESLintUtils.RuleCreator(
|
|
5137
5540
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5138
5541
|
)({
|
|
5139
5542
|
name: "no-repeated-string-literal",
|
|
@@ -5173,7 +5576,7 @@ var no_repeated_string_literal_default = import_utils35.ESLintUtils.RuleCreator(
|
|
|
5173
5576
|
}
|
|
5174
5577
|
},
|
|
5175
5578
|
TemplateLiteral(node) {
|
|
5176
|
-
if (node.parent.type ===
|
|
5579
|
+
if (node.parent.type === import_utils36.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5177
5580
|
return;
|
|
5178
5581
|
}
|
|
5179
5582
|
const [only] = node.quasis;
|
|
@@ -5207,7 +5610,7 @@ var no_repeated_string_literal_default = import_utils35.ESLintUtils.RuleCreator(
|
|
|
5207
5610
|
});
|
|
5208
5611
|
|
|
5209
5612
|
// src/rules/no-select-star.ts
|
|
5210
|
-
var
|
|
5613
|
+
var import_utils37 = require("@typescript-eslint/utils");
|
|
5211
5614
|
var QUERY_SHAPE = /\bSELECT\b[\s\S]*?\bFROM\b/i;
|
|
5212
5615
|
var SELECT_KEYWORD = /\bSELECT\b/gi;
|
|
5213
5616
|
var FROM_KEYWORD = /^FROM\b/i;
|
|
@@ -5247,7 +5650,7 @@ function hasRealSelectStar(sql) {
|
|
|
5247
5650
|
}
|
|
5248
5651
|
return false;
|
|
5249
5652
|
}
|
|
5250
|
-
var no_select_star_default =
|
|
5653
|
+
var no_select_star_default = import_utils37.ESLintUtils.RuleCreator(
|
|
5251
5654
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5252
5655
|
)({
|
|
5253
5656
|
name: "no-select-star",
|
|
@@ -5276,7 +5679,7 @@ var no_select_star_default = import_utils36.ESLintUtils.RuleCreator(
|
|
|
5276
5679
|
});
|
|
5277
5680
|
|
|
5278
5681
|
// src/rules/no-sleep-in-test-body.ts
|
|
5279
|
-
var
|
|
5682
|
+
var import_utils38 = require("@typescript-eslint/utils");
|
|
5280
5683
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
5281
5684
|
var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
5282
5685
|
"it",
|
|
@@ -5285,34 +5688,34 @@ var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
|
5285
5688
|
"afterEach"
|
|
5286
5689
|
]);
|
|
5287
5690
|
var FUNCTION_TYPES2 = /* @__PURE__ */ new Set([
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5691
|
+
import_utils38.AST_NODE_TYPES.FunctionDeclaration,
|
|
5692
|
+
import_utils38.AST_NODE_TYPES.FunctionExpression,
|
|
5693
|
+
import_utils38.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5291
5694
|
]);
|
|
5292
5695
|
function isNonzeroNumericLiteral(node) {
|
|
5293
|
-
return node?.type ===
|
|
5696
|
+
return node?.type === import_utils38.AST_NODE_TYPES.Literal && typeof node.value === "number" && node.value !== 0;
|
|
5294
5697
|
}
|
|
5295
5698
|
function isTimedSetTimeout(node) {
|
|
5296
|
-
return node.type ===
|
|
5699
|
+
return node.type === import_utils38.AST_NODE_TYPES.CallExpression && node.callee.type === import_utils38.AST_NODE_TYPES.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
5297
5700
|
}
|
|
5298
5701
|
function isPromiseSleep(node) {
|
|
5299
|
-
if (node.callee.type !==
|
|
5702
|
+
if (node.callee.type !== import_utils38.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise") {
|
|
5300
5703
|
return false;
|
|
5301
5704
|
}
|
|
5302
5705
|
const executor = node.arguments[0];
|
|
5303
|
-
if (executor?.type !==
|
|
5706
|
+
if (executor?.type !== import_utils38.AST_NODE_TYPES.ArrowFunctionExpression && executor?.type !== import_utils38.AST_NODE_TYPES.FunctionExpression) {
|
|
5304
5707
|
return false;
|
|
5305
5708
|
}
|
|
5306
5709
|
const body = executor.body;
|
|
5307
|
-
if (body.type !==
|
|
5710
|
+
if (body.type !== import_utils38.AST_NODE_TYPES.BlockStatement) {
|
|
5308
5711
|
return isTimedSetTimeout(body);
|
|
5309
5712
|
}
|
|
5310
5713
|
return body.body.some(
|
|
5311
|
-
(stmt) => stmt.type ===
|
|
5714
|
+
(stmt) => stmt.type === import_utils38.AST_NODE_TYPES.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
5312
5715
|
);
|
|
5313
5716
|
}
|
|
5314
5717
|
function isHelperSleep(node) {
|
|
5315
|
-
return node.callee.type ===
|
|
5718
|
+
return node.callee.type === import_utils38.AST_NODE_TYPES.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
5316
5719
|
}
|
|
5317
5720
|
function nearestEnclosingFunction(node) {
|
|
5318
5721
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5320,7 +5723,7 @@ function nearestEnclosingFunction(node) {
|
|
|
5320
5723
|
continue;
|
|
5321
5724
|
}
|
|
5322
5725
|
const grandparent = current.parent;
|
|
5323
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
5726
|
+
const isPromiseExecutor = grandparent?.type === import_utils38.AST_NODE_TYPES.NewExpression && isPromiseSleep(grandparent);
|
|
5324
5727
|
if (!isPromiseExecutor) {
|
|
5325
5728
|
return current;
|
|
5326
5729
|
}
|
|
@@ -5328,29 +5731,29 @@ function nearestEnclosingFunction(node) {
|
|
|
5328
5731
|
return null;
|
|
5329
5732
|
}
|
|
5330
5733
|
function testCallerName(callee) {
|
|
5331
|
-
if (callee.type ===
|
|
5734
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.Identifier) {
|
|
5332
5735
|
return callee.name;
|
|
5333
5736
|
}
|
|
5334
|
-
if (callee.type ===
|
|
5737
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.MemberExpression) {
|
|
5335
5738
|
return testCallerName(callee.object);
|
|
5336
5739
|
}
|
|
5337
|
-
if (callee.type ===
|
|
5740
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.CallExpression) {
|
|
5338
5741
|
return testCallerName(callee.callee);
|
|
5339
5742
|
}
|
|
5340
|
-
if (callee.type ===
|
|
5743
|
+
if (callee.type === import_utils38.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5341
5744
|
return testCallerName(callee.tag);
|
|
5342
5745
|
}
|
|
5343
5746
|
return null;
|
|
5344
5747
|
}
|
|
5345
5748
|
function isTestBody(fn) {
|
|
5346
5749
|
const call = fn.parent;
|
|
5347
|
-
if (call?.type !==
|
|
5750
|
+
if (call?.type !== import_utils38.AST_NODE_TYPES.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5348
5751
|
return false;
|
|
5349
5752
|
}
|
|
5350
5753
|
const name = testCallerName(call.callee);
|
|
5351
5754
|
return name !== null && TEST_CALLERS.has(name);
|
|
5352
5755
|
}
|
|
5353
|
-
var no_sleep_in_test_body_default =
|
|
5756
|
+
var no_sleep_in_test_body_default = import_utils38.ESLintUtils.RuleCreator(
|
|
5354
5757
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5355
5758
|
)({
|
|
5356
5759
|
name: "no-sleep-in-test-body",
|
|
@@ -5392,12 +5795,12 @@ var no_sleep_in_test_body_default = import_utils37.ESLintUtils.RuleCreator(
|
|
|
5392
5795
|
});
|
|
5393
5796
|
|
|
5394
5797
|
// src/rules/no-conditional-in-test.ts
|
|
5395
|
-
var
|
|
5798
|
+
var import_utils39 = require("@typescript-eslint/utils");
|
|
5396
5799
|
var TEST_CALLERS2 = /* @__PURE__ */ new Set(["it", "test"]);
|
|
5397
5800
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5801
|
+
import_utils39.AST_NODE_TYPES.FunctionDeclaration,
|
|
5802
|
+
import_utils39.AST_NODE_TYPES.FunctionExpression,
|
|
5803
|
+
import_utils39.AST_NODE_TYPES.ArrowFunctionExpression
|
|
5401
5804
|
]);
|
|
5402
5805
|
function nearestEnclosingFunction2(node) {
|
|
5403
5806
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5408,29 +5811,29 @@ function nearestEnclosingFunction2(node) {
|
|
|
5408
5811
|
return null;
|
|
5409
5812
|
}
|
|
5410
5813
|
function testCallerName2(callee) {
|
|
5411
|
-
if (callee.type ===
|
|
5814
|
+
if (callee.type === import_utils39.AST_NODE_TYPES.Identifier) {
|
|
5412
5815
|
return callee.name;
|
|
5413
5816
|
}
|
|
5414
|
-
if (callee.type ===
|
|
5817
|
+
if (callee.type === import_utils39.AST_NODE_TYPES.MemberExpression) {
|
|
5415
5818
|
return testCallerName2(callee.object);
|
|
5416
5819
|
}
|
|
5417
|
-
if (callee.type ===
|
|
5820
|
+
if (callee.type === import_utils39.AST_NODE_TYPES.CallExpression) {
|
|
5418
5821
|
return testCallerName2(callee.callee);
|
|
5419
5822
|
}
|
|
5420
|
-
if (callee.type ===
|
|
5823
|
+
if (callee.type === import_utils39.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
5421
5824
|
return testCallerName2(callee.tag);
|
|
5422
5825
|
}
|
|
5423
5826
|
return null;
|
|
5424
5827
|
}
|
|
5425
5828
|
function isTestBody2(fn) {
|
|
5426
5829
|
const call = fn.parent;
|
|
5427
|
-
if (call?.type !==
|
|
5830
|
+
if (call?.type !== import_utils39.AST_NODE_TYPES.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5428
5831
|
return false;
|
|
5429
5832
|
}
|
|
5430
5833
|
const name = testCallerName2(call.callee);
|
|
5431
5834
|
return name !== null && TEST_CALLERS2.has(name);
|
|
5432
5835
|
}
|
|
5433
|
-
var no_conditional_in_test_default =
|
|
5836
|
+
var no_conditional_in_test_default = import_utils39.ESLintUtils.RuleCreator(
|
|
5434
5837
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5435
5838
|
)({
|
|
5436
5839
|
name: "no-conditional-in-test",
|
|
@@ -5474,7 +5877,7 @@ var no_conditional_in_test_default = import_utils38.ESLintUtils.RuleCreator(
|
|
|
5474
5877
|
});
|
|
5475
5878
|
|
|
5476
5879
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5477
|
-
var
|
|
5880
|
+
var import_utils40 = require("@typescript-eslint/utils");
|
|
5478
5881
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5479
5882
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5480
5883
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5487,36 +5890,36 @@ function isConstantReference(identifier) {
|
|
|
5487
5890
|
}
|
|
5488
5891
|
function isExcludedOperand(node) {
|
|
5489
5892
|
switch (node.type) {
|
|
5490
|
-
case
|
|
5893
|
+
case import_utils40.AST_NODE_TYPES.Literal:
|
|
5491
5894
|
return true;
|
|
5492
|
-
case
|
|
5895
|
+
case import_utils40.AST_NODE_TYPES.TemplateLiteral:
|
|
5493
5896
|
return node.expressions.length === 0;
|
|
5494
|
-
case
|
|
5897
|
+
case import_utils40.AST_NODE_TYPES.Identifier:
|
|
5495
5898
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5496
|
-
case
|
|
5497
|
-
return !node.computed && node.property.type ===
|
|
5899
|
+
case import_utils40.AST_NODE_TYPES.MemberExpression:
|
|
5900
|
+
return !node.computed && node.property.type === import_utils40.AST_NODE_TYPES.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5498
5901
|
default:
|
|
5499
5902
|
return false;
|
|
5500
5903
|
}
|
|
5501
5904
|
}
|
|
5502
5905
|
function operandName(node) {
|
|
5503
|
-
if (node.type ===
|
|
5906
|
+
if (node.type === import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5504
5907
|
return node.name;
|
|
5505
5908
|
}
|
|
5506
|
-
if (node.type ===
|
|
5909
|
+
if (node.type === import_utils40.AST_NODE_TYPES.MemberExpression && !node.computed && node.property.type === import_utils40.AST_NODE_TYPES.Identifier) {
|
|
5507
5910
|
return node.property.name;
|
|
5508
5911
|
}
|
|
5509
5912
|
return null;
|
|
5510
5913
|
}
|
|
5511
5914
|
function isSecretOperand(node) {
|
|
5512
|
-
if (node.type ===
|
|
5915
|
+
if (node.type === import_utils40.AST_NODE_TYPES.TemplateLiteral) {
|
|
5513
5916
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5514
5917
|
}
|
|
5515
5918
|
const name = operandName(node);
|
|
5516
5919
|
return name !== null && isAuthSecretName(name);
|
|
5517
5920
|
}
|
|
5518
5921
|
function secretNameOf(node) {
|
|
5519
|
-
if (node.type ===
|
|
5922
|
+
if (node.type === import_utils40.AST_NODE_TYPES.TemplateLiteral) {
|
|
5520
5923
|
for (const expression of node.expressions) {
|
|
5521
5924
|
const nested = secretNameOf(expression);
|
|
5522
5925
|
if (nested !== null) {
|
|
@@ -5527,7 +5930,7 @@ function secretNameOf(node) {
|
|
|
5527
5930
|
}
|
|
5528
5931
|
return operandName(node);
|
|
5529
5932
|
}
|
|
5530
|
-
var prefer_constant_time_secret_compare_default =
|
|
5933
|
+
var prefer_constant_time_secret_compare_default = import_utils40.ESLintUtils.RuleCreator(
|
|
5531
5934
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5532
5935
|
)({
|
|
5533
5936
|
name: "prefer-constant-time-secret-compare",
|
|
@@ -5570,11 +5973,11 @@ var prefer_constant_time_secret_compare_default = import_utils39.ESLintUtils.Rul
|
|
|
5570
5973
|
});
|
|
5571
5974
|
|
|
5572
5975
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
5573
|
-
var
|
|
5976
|
+
var import_utils41 = require("@typescript-eslint/utils");
|
|
5574
5977
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
5575
5978
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
5576
5979
|
var INSERT_GATE = /insert/i;
|
|
5577
|
-
var store_insert_requires_on_conflict_default =
|
|
5980
|
+
var store_insert_requires_on_conflict_default = import_utils41.ESLintUtils.RuleCreator(
|
|
5578
5981
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5579
5982
|
)({
|
|
5580
5983
|
name: "store-insert-requires-on-conflict",
|
|
@@ -5603,17 +6006,17 @@ var store_insert_requires_on_conflict_default = import_utils40.ESLintUtils.RuleC
|
|
|
5603
6006
|
});
|
|
5604
6007
|
|
|
5605
6008
|
// src/rules/no-dynamic-sql.ts
|
|
5606
|
-
var
|
|
6009
|
+
var import_utils42 = require("@typescript-eslint/utils");
|
|
5607
6010
|
var DEFAULT_METHODS = ["prepare", "exec", "query"];
|
|
5608
6011
|
var CONSTANT_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
5609
6012
|
function isStaticFragment(expression) {
|
|
5610
|
-
if (expression.type ===
|
|
6013
|
+
if (expression.type === import_utils42.AST_NODE_TYPES.Identifier) {
|
|
5611
6014
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
5612
6015
|
}
|
|
5613
|
-
if (expression.type ===
|
|
6016
|
+
if (expression.type === import_utils42.AST_NODE_TYPES.MemberExpression && !expression.computed && expression.property.type === import_utils42.AST_NODE_TYPES.Identifier) {
|
|
5614
6017
|
return CONSTANT_CASE_RE.test(expression.property.name);
|
|
5615
6018
|
}
|
|
5616
|
-
if (expression.type ===
|
|
6019
|
+
if (expression.type === import_utils42.AST_NODE_TYPES.Literal) {
|
|
5617
6020
|
return typeof expression.value === "string";
|
|
5618
6021
|
}
|
|
5619
6022
|
return false;
|
|
@@ -5624,36 +6027,36 @@ function runtimeInterpolations(template) {
|
|
|
5624
6027
|
);
|
|
5625
6028
|
}
|
|
5626
6029
|
function concatOperands(node) {
|
|
5627
|
-
if (node.type ===
|
|
6030
|
+
if (node.type === import_utils42.AST_NODE_TYPES.BinaryExpression && node.operator === "+") {
|
|
5628
6031
|
return [...concatOperands(node.left), ...concatOperands(node.right)];
|
|
5629
6032
|
}
|
|
5630
6033
|
return [node];
|
|
5631
6034
|
}
|
|
5632
6035
|
function runtimeConcatOperands(node) {
|
|
5633
|
-
if (node.type !==
|
|
6036
|
+
if (node.type !== import_utils42.AST_NODE_TYPES.BinaryExpression || node.operator !== "+") {
|
|
5634
6037
|
return [];
|
|
5635
6038
|
}
|
|
5636
6039
|
const operands = concatOperands(node);
|
|
5637
6040
|
const hasStringLiteral = operands.some(
|
|
5638
|
-
(operand) => operand.type ===
|
|
6041
|
+
(operand) => operand.type === import_utils42.AST_NODE_TYPES.Literal && typeof operand.value === "string"
|
|
5639
6042
|
);
|
|
5640
6043
|
if (!hasStringLiteral) {
|
|
5641
6044
|
return [];
|
|
5642
6045
|
}
|
|
5643
6046
|
return operands.filter(
|
|
5644
|
-
(operand) => operand.type !==
|
|
6047
|
+
(operand) => operand.type !== import_utils42.AST_NODE_TYPES.Literal && !isStaticFragment(operand)
|
|
5645
6048
|
);
|
|
5646
6049
|
}
|
|
5647
6050
|
var SQL_STATEMENT_RE = /\b(?:select\s|insert\s+into\b|insert\s+or\b|update\s+\w|delete\s+from\b|replace\s+into\b|merge\s+into\b|upsert\s+into\b|create\s+(?:temp(?:orary)?\s+)?(?:table|index|view|trigger|schema|database)\b|alter\s+table\b|drop\s+(?:table|index|view|trigger)\b|truncate\s+table\b|pragma\s+\w|with\s+\w+\s+as\s*\(|from\s+\w+\s+where\b)/i;
|
|
5648
6051
|
var RUNTIME_MARKER = " ? ";
|
|
5649
6052
|
function staticStatementText(node) {
|
|
5650
|
-
if (node.type ===
|
|
6053
|
+
if (node.type === import_utils42.AST_NODE_TYPES.TemplateLiteral) {
|
|
5651
6054
|
return node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join(RUNTIME_MARKER);
|
|
5652
6055
|
}
|
|
5653
|
-
if (node.type ===
|
|
6056
|
+
if (node.type === import_utils42.AST_NODE_TYPES.Literal) {
|
|
5654
6057
|
return typeof node.value === "string" ? node.value : RUNTIME_MARKER;
|
|
5655
6058
|
}
|
|
5656
|
-
if (node.type ===
|
|
6059
|
+
if (node.type === import_utils42.AST_NODE_TYPES.BinaryExpression && node.operator === "+") {
|
|
5657
6060
|
return staticStatementText(node.left) + staticStatementText(node.right);
|
|
5658
6061
|
}
|
|
5659
6062
|
return RUNTIME_MARKER;
|
|
@@ -5663,13 +6066,13 @@ function looksLikeSql(node) {
|
|
|
5663
6066
|
}
|
|
5664
6067
|
function statementMethodName(node, methods) {
|
|
5665
6068
|
const callee = node.callee;
|
|
5666
|
-
if (callee.type !==
|
|
6069
|
+
if (callee.type !== import_utils42.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils42.AST_NODE_TYPES.Identifier) {
|
|
5667
6070
|
return null;
|
|
5668
6071
|
}
|
|
5669
6072
|
const name = callee.property.name;
|
|
5670
6073
|
return methods.has(name) ? name : null;
|
|
5671
6074
|
}
|
|
5672
|
-
var no_dynamic_sql_default =
|
|
6075
|
+
var no_dynamic_sql_default = import_utils42.ESLintUtils.RuleCreator(
|
|
5673
6076
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5674
6077
|
)({
|
|
5675
6078
|
name: "no-dynamic-sql",
|
|
@@ -5708,7 +6111,7 @@ var no_dynamic_sql_default = import_utils41.ESLintUtils.RuleCreator(
|
|
|
5708
6111
|
if (statement === void 0 || !looksLikeSql(statement)) {
|
|
5709
6112
|
return;
|
|
5710
6113
|
}
|
|
5711
|
-
const offenders = statement.type ===
|
|
6114
|
+
const offenders = statement.type === import_utils42.AST_NODE_TYPES.TemplateLiteral ? runtimeInterpolations(statement) : runtimeConcatOperands(statement);
|
|
5712
6115
|
for (const offender of offenders) {
|
|
5713
6116
|
context.report({
|
|
5714
6117
|
node: offender,
|
|
@@ -5722,7 +6125,7 @@ var no_dynamic_sql_default = import_utils41.ESLintUtils.RuleCreator(
|
|
|
5722
6125
|
});
|
|
5723
6126
|
|
|
5724
6127
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
5725
|
-
var
|
|
6128
|
+
var import_utils43 = require("@typescript-eslint/utils");
|
|
5726
6129
|
var DEFAULT_ALLOW = [
|
|
5727
6130
|
"[\\\\/]clients?[\\\\/]",
|
|
5728
6131
|
"-client\\.[cm]?[jt]sx?$",
|
|
@@ -5786,7 +6189,7 @@ function compile(patterns) {
|
|
|
5786
6189
|
}
|
|
5787
6190
|
return compiled;
|
|
5788
6191
|
}
|
|
5789
|
-
var no_raw_fetch_outside_clients_default =
|
|
6192
|
+
var no_raw_fetch_outside_clients_default = import_utils43.ESLintUtils.RuleCreator(
|
|
5790
6193
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5791
6194
|
)({
|
|
5792
6195
|
name: "no-raw-fetch-outside-clients",
|
|
@@ -5834,7 +6237,7 @@ var no_raw_fetch_outside_clients_default = import_utils42.ESLintUtils.RuleCreato
|
|
|
5834
6237
|
});
|
|
5835
6238
|
|
|
5836
6239
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5837
|
-
var
|
|
6240
|
+
var import_utils44 = require("@typescript-eslint/utils");
|
|
5838
6241
|
var DEFAULT_METHODS2 = [
|
|
5839
6242
|
"prepare",
|
|
5840
6243
|
"put",
|
|
@@ -5853,7 +6256,7 @@ function compile2(patterns) {
|
|
|
5853
6256
|
}
|
|
5854
6257
|
function storageMethodName(node, methods) {
|
|
5855
6258
|
const callee = node.callee;
|
|
5856
|
-
if (callee.type !==
|
|
6259
|
+
if (callee.type !== import_utils44.AST_NODE_TYPES.MemberExpression || callee.computed || callee.property.type !== import_utils44.AST_NODE_TYPES.Identifier) {
|
|
5857
6260
|
return null;
|
|
5858
6261
|
}
|
|
5859
6262
|
const name = callee.property.name;
|
|
@@ -5865,7 +6268,7 @@ function storageMethodName(node, methods) {
|
|
|
5865
6268
|
}
|
|
5866
6269
|
return name;
|
|
5867
6270
|
}
|
|
5868
|
-
var no_storage_in_stateless_modules_default =
|
|
6271
|
+
var no_storage_in_stateless_modules_default = import_utils44.ESLintUtils.RuleCreator(
|
|
5869
6272
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5870
6273
|
)({
|
|
5871
6274
|
name: "no-storage-in-stateless-modules",
|
|
@@ -5923,7 +6326,7 @@ var no_storage_in_stateless_modules_default = import_utils43.ESLintUtils.RuleCre
|
|
|
5923
6326
|
});
|
|
5924
6327
|
|
|
5925
6328
|
// src/rules/no-zod-native-enum.ts
|
|
5926
|
-
var
|
|
6329
|
+
var import_utils45 = require("@typescript-eslint/utils");
|
|
5927
6330
|
var ts2 = __toESM(require("typescript"), 1);
|
|
5928
6331
|
var IGNORE_PATTERNS2 = [
|
|
5929
6332
|
/[\\/]generated[\\/]/,
|
|
@@ -5941,7 +6344,7 @@ function isZodModule2(source) {
|
|
|
5941
6344
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5942
6345
|
}
|
|
5943
6346
|
function unwrap3(node) {
|
|
5944
|
-
if (node.type ===
|
|
6347
|
+
if (node.type === import_utils45.AST_NODE_TYPES.TSAsExpression || node.type === import_utils45.AST_NODE_TYPES.TSSatisfiesExpression) {
|
|
5945
6348
|
return unwrap3(node.expression);
|
|
5946
6349
|
}
|
|
5947
6350
|
return node;
|
|
@@ -5949,14 +6352,14 @@ function unwrap3(node) {
|
|
|
5949
6352
|
function stringValueTexts(node, sourceCode) {
|
|
5950
6353
|
const texts = [];
|
|
5951
6354
|
for (const prop of node.properties) {
|
|
5952
|
-
if (prop.type !==
|
|
6355
|
+
if (prop.type !== import_utils45.AST_NODE_TYPES.Property) {
|
|
5953
6356
|
return null;
|
|
5954
6357
|
}
|
|
5955
6358
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5956
6359
|
return null;
|
|
5957
6360
|
}
|
|
5958
6361
|
const value = prop.value;
|
|
5959
|
-
if (value.type !==
|
|
6362
|
+
if (value.type !== import_utils45.AST_NODE_TYPES.Literal || typeof value.value !== "string") {
|
|
5960
6363
|
return null;
|
|
5961
6364
|
}
|
|
5962
6365
|
const text = sourceCode.getText(value);
|
|
@@ -5972,7 +6375,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5972
6375
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5973
6376
|
if (variable !== void 0) {
|
|
5974
6377
|
return variable.defs.some(
|
|
5975
|
-
(def) => def.node.type ===
|
|
6378
|
+
(def) => def.node.type === import_utils45.AST_NODE_TYPES.TSEnumDeclaration
|
|
5976
6379
|
);
|
|
5977
6380
|
}
|
|
5978
6381
|
current = current.upper;
|
|
@@ -5992,7 +6395,7 @@ function resolvesToImportedEnum(node, services) {
|
|
|
5992
6395
|
}
|
|
5993
6396
|
return (symbol.flags & ENUM_SYMBOL_FLAGS) !== 0;
|
|
5994
6397
|
}
|
|
5995
|
-
var no_zod_native_enum_default =
|
|
6398
|
+
var no_zod_native_enum_default = import_utils45.ESLintUtils.RuleCreator(
|
|
5996
6399
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5997
6400
|
)({
|
|
5998
6401
|
name: "no-zod-native-enum",
|
|
@@ -6019,32 +6422,32 @@ var no_zod_native_enum_default = import_utils44.ESLintUtils.RuleCreator(
|
|
|
6019
6422
|
}
|
|
6020
6423
|
let services;
|
|
6021
6424
|
try {
|
|
6022
|
-
services =
|
|
6425
|
+
services = import_utils45.ESLintUtils.getParserServices(context);
|
|
6023
6426
|
} catch {
|
|
6024
6427
|
services = null;
|
|
6025
6428
|
}
|
|
6026
6429
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6027
6430
|
function isZodMemberCall(node, api) {
|
|
6028
6431
|
const callee = node.callee;
|
|
6029
|
-
if (callee.type ===
|
|
6432
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6030
6433
|
return callee.property.name === api;
|
|
6031
6434
|
}
|
|
6032
|
-
if (callee.type ===
|
|
6435
|
+
if (callee.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6033
6436
|
return zodImportedNames.get(callee.name) === api;
|
|
6034
6437
|
}
|
|
6035
6438
|
return false;
|
|
6036
6439
|
}
|
|
6037
6440
|
function buildFix(node) {
|
|
6038
6441
|
const callee = node.callee;
|
|
6039
|
-
if (callee.type !==
|
|
6442
|
+
if (callee.type !== import_utils45.AST_NODE_TYPES.MemberExpression || callee.property.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6040
6443
|
return null;
|
|
6041
6444
|
}
|
|
6042
6445
|
const arg = node.arguments[0];
|
|
6043
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6446
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === import_utils45.AST_NODE_TYPES.SpreadElement) {
|
|
6044
6447
|
return null;
|
|
6045
6448
|
}
|
|
6046
6449
|
const inner = unwrap3(arg);
|
|
6047
|
-
if (inner.type !==
|
|
6450
|
+
if (inner.type !== import_utils45.AST_NODE_TYPES.ObjectExpression) {
|
|
6048
6451
|
return null;
|
|
6049
6452
|
}
|
|
6050
6453
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6064,7 +6467,7 @@ var no_zod_native_enum_default = import_utils44.ESLintUtils.RuleCreator(
|
|
|
6064
6467
|
return;
|
|
6065
6468
|
}
|
|
6066
6469
|
for (const spec of node.specifiers) {
|
|
6067
|
-
if (spec.type ===
|
|
6470
|
+
if (spec.type === import_utils45.AST_NODE_TYPES.ImportSpecifier && spec.imported.type === import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6068
6471
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6069
6472
|
}
|
|
6070
6473
|
}
|
|
@@ -6083,7 +6486,7 @@ var no_zod_native_enum_default = import_utils44.ESLintUtils.RuleCreator(
|
|
|
6083
6486
|
return;
|
|
6084
6487
|
}
|
|
6085
6488
|
const arg = node.arguments[0];
|
|
6086
|
-
if (arg === void 0 || arg.type !==
|
|
6489
|
+
if (arg === void 0 || arg.type !== import_utils45.AST_NODE_TYPES.Identifier) {
|
|
6087
6490
|
return;
|
|
6088
6491
|
}
|
|
6089
6492
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6100,7 +6503,7 @@ var no_zod_native_enum_default = import_utils44.ESLintUtils.RuleCreator(
|
|
|
6100
6503
|
});
|
|
6101
6504
|
|
|
6102
6505
|
// src/rules/prefer-module-level-constant.ts
|
|
6103
|
-
var
|
|
6506
|
+
var import_utils46 = require("@typescript-eslint/utils");
|
|
6104
6507
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6105
6508
|
var MAX_LITERAL_DEPTH = 4;
|
|
6106
6509
|
var IGNORE_PATTERNS3 = [
|
|
@@ -6136,9 +6539,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6136
6539
|
"assign"
|
|
6137
6540
|
]);
|
|
6138
6541
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6542
|
+
import_utils46.AST_NODE_TYPES.FunctionDeclaration,
|
|
6543
|
+
import_utils46.AST_NODE_TYPES.FunctionExpression,
|
|
6544
|
+
import_utils46.AST_NODE_TYPES.ArrowFunctionExpression
|
|
6142
6545
|
]);
|
|
6143
6546
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6144
6547
|
function isIgnoredFile3(filename, sourceText) {
|
|
@@ -6151,13 +6554,13 @@ function isTestFile2(filename) {
|
|
|
6151
6554
|
return TEST_FILE_PATTERNS.some((re) => re.test(filename));
|
|
6152
6555
|
}
|
|
6153
6556
|
function unwrap4(node) {
|
|
6154
|
-
if (node.type ===
|
|
6557
|
+
if (node.type === import_utils46.AST_NODE_TYPES.TSAsExpression || node.type === import_utils46.AST_NODE_TYPES.TSSatisfiesExpression || node.type === import_utils46.AST_NODE_TYPES.TSNonNullExpression) {
|
|
6155
6558
|
return unwrap4(node.expression);
|
|
6156
6559
|
}
|
|
6157
6560
|
return node;
|
|
6158
6561
|
}
|
|
6159
6562
|
function isRegexLiteral(node) {
|
|
6160
|
-
return node.type ===
|
|
6563
|
+
return node.type === import_utils46.AST_NODE_TYPES.Literal && "regex" in node && node.regex !== void 0;
|
|
6161
6564
|
}
|
|
6162
6565
|
function isLiteralOnly(node, depth) {
|
|
6163
6566
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6165,29 +6568,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6165
6568
|
}
|
|
6166
6569
|
const inner = unwrap4(node);
|
|
6167
6570
|
switch (inner.type) {
|
|
6168
|
-
case
|
|
6571
|
+
case import_utils46.AST_NODE_TYPES.Literal: {
|
|
6169
6572
|
return true;
|
|
6170
6573
|
}
|
|
6171
|
-
case
|
|
6574
|
+
case import_utils46.AST_NODE_TYPES.TemplateLiteral: {
|
|
6172
6575
|
return inner.expressions.length === 0;
|
|
6173
6576
|
}
|
|
6174
|
-
case
|
|
6175
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6577
|
+
case import_utils46.AST_NODE_TYPES.UnaryExpression: {
|
|
6578
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === import_utils46.AST_NODE_TYPES.Literal && typeof inner.argument.value === "number";
|
|
6176
6579
|
}
|
|
6177
|
-
case
|
|
6580
|
+
case import_utils46.AST_NODE_TYPES.ArrayExpression: {
|
|
6178
6581
|
return inner.elements.every(
|
|
6179
|
-
(el) => el !== null && el.type !==
|
|
6582
|
+
(el) => el !== null && el.type !== import_utils46.AST_NODE_TYPES.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6180
6583
|
);
|
|
6181
6584
|
}
|
|
6182
|
-
case
|
|
6585
|
+
case import_utils46.AST_NODE_TYPES.ObjectExpression: {
|
|
6183
6586
|
return inner.properties.every((prop) => {
|
|
6184
|
-
if (prop.type !==
|
|
6587
|
+
if (prop.type !== import_utils46.AST_NODE_TYPES.Property) {
|
|
6185
6588
|
return false;
|
|
6186
6589
|
}
|
|
6187
6590
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6188
6591
|
return false;
|
|
6189
6592
|
}
|
|
6190
|
-
if (prop.computed && prop.key.type !==
|
|
6593
|
+
if (prop.computed && prop.key.type !== import_utils46.AST_NODE_TYPES.Literal) {
|
|
6191
6594
|
return false;
|
|
6192
6595
|
}
|
|
6193
6596
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6200,7 +6603,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6200
6603
|
}
|
|
6201
6604
|
function unwrapObjectFreeze(node) {
|
|
6202
6605
|
const inner = unwrap4(node);
|
|
6203
|
-
if (inner.type ===
|
|
6606
|
+
if (inner.type === import_utils46.AST_NODE_TYPES.CallExpression && inner.callee.type === import_utils46.AST_NODE_TYPES.MemberExpression && !inner.callee.computed && inner.callee.object.type === import_utils46.AST_NODE_TYPES.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === import_utils46.AST_NODE_TYPES.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== import_utils46.AST_NODE_TYPES.SpreadElement) {
|
|
6204
6607
|
return unwrap4(inner.arguments[0]);
|
|
6205
6608
|
}
|
|
6206
6609
|
return inner;
|
|
@@ -6216,19 +6619,19 @@ function classify(init, checkRegex) {
|
|
|
6216
6619
|
}
|
|
6217
6620
|
return { kind: "regex", size: 1 };
|
|
6218
6621
|
}
|
|
6219
|
-
if (node.type ===
|
|
6622
|
+
if (node.type === import_utils46.AST_NODE_TYPES.ArrayExpression) {
|
|
6220
6623
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6221
6624
|
}
|
|
6222
|
-
if (node.type ===
|
|
6625
|
+
if (node.type === import_utils46.AST_NODE_TYPES.ObjectExpression) {
|
|
6223
6626
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6224
6627
|
}
|
|
6225
|
-
if (node.type ===
|
|
6628
|
+
if (node.type === import_utils46.AST_NODE_TYPES.NewExpression && node.callee.type === import_utils46.AST_NODE_TYPES.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6226
6629
|
const arg = node.arguments[0];
|
|
6227
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6630
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === import_utils46.AST_NODE_TYPES.SpreadElement) {
|
|
6228
6631
|
return null;
|
|
6229
6632
|
}
|
|
6230
6633
|
const entries = unwrap4(arg);
|
|
6231
|
-
if (entries.type !==
|
|
6634
|
+
if (entries.type !== import_utils46.AST_NODE_TYPES.ArrayExpression) {
|
|
6232
6635
|
return null;
|
|
6233
6636
|
}
|
|
6234
6637
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6257,10 +6660,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6257
6660
|
);
|
|
6258
6661
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6259
6662
|
const callee = node.callee;
|
|
6260
|
-
if (callee.type ===
|
|
6663
|
+
if (callee.type === import_utils46.AST_NODE_TYPES.Identifier && callee.name === "structuredClone") {
|
|
6261
6664
|
return true;
|
|
6262
6665
|
}
|
|
6263
|
-
if (callee.type !==
|
|
6666
|
+
if (callee.type !== import_utils46.AST_NODE_TYPES.MemberExpression || callee.computed || callee.object.type !== import_utils46.AST_NODE_TYPES.Identifier || callee.property.type !== import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6264
6667
|
return false;
|
|
6265
6668
|
}
|
|
6266
6669
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6274,43 +6677,43 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6274
6677
|
}
|
|
6275
6678
|
function isSafeRead(identifier) {
|
|
6276
6679
|
const parent = identifier.parent;
|
|
6277
|
-
if (parent.type ===
|
|
6680
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.MemberExpression) {
|
|
6278
6681
|
if (parent.object !== identifier) {
|
|
6279
6682
|
return true;
|
|
6280
6683
|
}
|
|
6281
6684
|
const grandparent = parent.parent;
|
|
6282
|
-
if (grandparent.type ===
|
|
6685
|
+
if (grandparent.type === import_utils46.AST_NODE_TYPES.AssignmentExpression && grandparent.left === parent) {
|
|
6283
6686
|
return false;
|
|
6284
6687
|
}
|
|
6285
|
-
if (grandparent.type ===
|
|
6688
|
+
if (grandparent.type === import_utils46.AST_NODE_TYPES.UpdateExpression) {
|
|
6286
6689
|
return false;
|
|
6287
6690
|
}
|
|
6288
|
-
if (grandparent.type ===
|
|
6691
|
+
if (grandparent.type === import_utils46.AST_NODE_TYPES.UnaryExpression && grandparent.operator === "delete") {
|
|
6289
6692
|
return false;
|
|
6290
6693
|
}
|
|
6291
|
-
if (!parent.computed && parent.property.type ===
|
|
6694
|
+
if (!parent.computed && parent.property.type === import_utils46.AST_NODE_TYPES.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === import_utils46.AST_NODE_TYPES.CallExpression && grandparent.callee === parent) {
|
|
6292
6695
|
return false;
|
|
6293
6696
|
}
|
|
6294
6697
|
return true;
|
|
6295
6698
|
}
|
|
6296
|
-
if (parent.type ===
|
|
6699
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.ForOfStatement && parent.right === identifier) {
|
|
6297
6700
|
return true;
|
|
6298
6701
|
}
|
|
6299
|
-
if (parent.type ===
|
|
6702
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.SpreadElement) {
|
|
6300
6703
|
return true;
|
|
6301
6704
|
}
|
|
6302
|
-
if (parent.type ===
|
|
6705
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.BinaryExpression) {
|
|
6303
6706
|
return true;
|
|
6304
6707
|
}
|
|
6305
|
-
if (parent.type ===
|
|
6708
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6306
6709
|
return true;
|
|
6307
6710
|
}
|
|
6308
|
-
if (parent.type ===
|
|
6711
|
+
if (parent.type === import_utils46.AST_NODE_TYPES.UnaryExpression && parent.operator !== "delete") {
|
|
6309
6712
|
return true;
|
|
6310
6713
|
}
|
|
6311
6714
|
return false;
|
|
6312
6715
|
}
|
|
6313
|
-
var prefer_module_level_constant_default =
|
|
6716
|
+
var prefer_module_level_constant_default = import_utils46.ESLintUtils.RuleCreator(
|
|
6314
6717
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6315
6718
|
)({
|
|
6316
6719
|
name: "prefer-module-level-constant",
|
|
@@ -6362,7 +6765,7 @@ var prefer_module_level_constant_default = import_utils45.ESLintUtils.RuleCreato
|
|
|
6362
6765
|
if (reference.isWrite()) {
|
|
6363
6766
|
return false;
|
|
6364
6767
|
}
|
|
6365
|
-
if (reference.identifier.type !==
|
|
6768
|
+
if (reference.identifier.type !== import_utils46.AST_NODE_TYPES.Identifier) {
|
|
6366
6769
|
return false;
|
|
6367
6770
|
}
|
|
6368
6771
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6374,10 +6777,10 @@ var prefer_module_level_constant_default = import_utils45.ESLintUtils.RuleCreato
|
|
|
6374
6777
|
return {
|
|
6375
6778
|
VariableDeclarator(node) {
|
|
6376
6779
|
const declaration = node.parent;
|
|
6377
|
-
if (declaration.type !==
|
|
6780
|
+
if (declaration.type !== import_utils46.AST_NODE_TYPES.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6378
6781
|
return;
|
|
6379
6782
|
}
|
|
6380
|
-
if (node.id.type !==
|
|
6783
|
+
if (node.id.type !== import_utils46.AST_NODE_TYPES.Identifier || node.init === null) {
|
|
6381
6784
|
return;
|
|
6382
6785
|
}
|
|
6383
6786
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6404,7 +6807,7 @@ var prefer_module_level_constant_default = import_utils45.ESLintUtils.RuleCreato
|
|
|
6404
6807
|
});
|
|
6405
6808
|
|
|
6406
6809
|
// src/rules/jsdoc-restates-signature.ts
|
|
6407
|
-
var
|
|
6810
|
+
var import_utils47 = require("@typescript-eslint/utils");
|
|
6408
6811
|
var VALUE_TAGS = /* @__PURE__ */ new Set([
|
|
6409
6812
|
"alpha",
|
|
6410
6813
|
"author",
|
|
@@ -6487,30 +6890,30 @@ function declarationNames(node) {
|
|
|
6487
6890
|
switch (node.type) {
|
|
6488
6891
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
6489
6892
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
6490
|
-
case
|
|
6491
|
-
case
|
|
6893
|
+
case import_utils47.AST_NODE_TYPES.ExportNamedDeclaration:
|
|
6894
|
+
case import_utils47.AST_NODE_TYPES.ExportDefaultDeclaration:
|
|
6492
6895
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
6493
|
-
case
|
|
6494
|
-
case
|
|
6896
|
+
case import_utils47.AST_NODE_TYPES.FunctionDeclaration:
|
|
6897
|
+
case import_utils47.AST_NODE_TYPES.TSDeclareFunction:
|
|
6495
6898
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
6496
|
-
case
|
|
6497
|
-
case
|
|
6498
|
-
case
|
|
6499
|
-
case
|
|
6899
|
+
case import_utils47.AST_NODE_TYPES.ClassDeclaration:
|
|
6900
|
+
case import_utils47.AST_NODE_TYPES.TSInterfaceDeclaration:
|
|
6901
|
+
case import_utils47.AST_NODE_TYPES.TSTypeAliasDeclaration:
|
|
6902
|
+
case import_utils47.AST_NODE_TYPES.TSEnumDeclaration:
|
|
6500
6903
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
6501
|
-
case
|
|
6904
|
+
case import_utils47.AST_NODE_TYPES.VariableDeclaration: {
|
|
6502
6905
|
const declarator = node.declarations[0];
|
|
6503
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
6906
|
+
if (declarator === void 0 || declarator.id.type !== import_utils47.AST_NODE_TYPES.Identifier) return null;
|
|
6504
6907
|
const init = declarator.init;
|
|
6505
|
-
const params = init != null && (init.type ===
|
|
6908
|
+
const params = init != null && (init.type === import_utils47.AST_NODE_TYPES.ArrowFunctionExpression || init.type === import_utils47.AST_NODE_TYPES.FunctionExpression) ? paramNames(init.params) : [];
|
|
6506
6909
|
return { name: declarator.id.name, params };
|
|
6507
6910
|
}
|
|
6508
|
-
case
|
|
6509
|
-
case
|
|
6510
|
-
case
|
|
6511
|
-
case
|
|
6512
|
-
if (node.key.type !==
|
|
6513
|
-
const params = node.type ===
|
|
6911
|
+
case import_utils47.AST_NODE_TYPES.MethodDefinition:
|
|
6912
|
+
case import_utils47.AST_NODE_TYPES.PropertyDefinition:
|
|
6913
|
+
case import_utils47.AST_NODE_TYPES.TSMethodSignature:
|
|
6914
|
+
case import_utils47.AST_NODE_TYPES.TSPropertySignature: {
|
|
6915
|
+
if (node.key.type !== import_utils47.AST_NODE_TYPES.Identifier) return null;
|
|
6916
|
+
const params = node.type === import_utils47.AST_NODE_TYPES.MethodDefinition ? paramNames(node.value.params) : node.type === import_utils47.AST_NODE_TYPES.TSMethodSignature ? paramNames(node.params) : [];
|
|
6514
6917
|
return { name: node.key.name, params };
|
|
6515
6918
|
}
|
|
6516
6919
|
default:
|
|
@@ -6520,9 +6923,9 @@ function declarationNames(node) {
|
|
|
6520
6923
|
function paramNames(params) {
|
|
6521
6924
|
const names = [];
|
|
6522
6925
|
for (const param of params) {
|
|
6523
|
-
const target = param.type ===
|
|
6524
|
-
if (target.type ===
|
|
6525
|
-
else if (target.type ===
|
|
6926
|
+
const target = param.type === import_utils47.AST_NODE_TYPES.AssignmentPattern ? param.left : param;
|
|
6927
|
+
if (target.type === import_utils47.AST_NODE_TYPES.Identifier) names.push(target.name);
|
|
6928
|
+
else if (target.type === import_utils47.AST_NODE_TYPES.TSParameterProperty) continue;
|
|
6526
6929
|
}
|
|
6527
6930
|
return names;
|
|
6528
6931
|
}
|
|
@@ -6531,7 +6934,7 @@ function tokensOf(names) {
|
|
|
6531
6934
|
for (const name of names) for (const part of splitIdentifier(name)) tokens.add(part);
|
|
6532
6935
|
return tokens;
|
|
6533
6936
|
}
|
|
6534
|
-
var jsdoc_restates_signature_default =
|
|
6937
|
+
var jsdoc_restates_signature_default = import_utils47.ESLintUtils.RuleCreator(
|
|
6535
6938
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6536
6939
|
)({
|
|
6537
6940
|
name: "jsdoc-restates-signature",
|
|
@@ -6567,7 +6970,7 @@ var jsdoc_restates_signature_default = import_utils46.ESLintUtils.RuleCreator(
|
|
|
6567
6970
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
6568
6971
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
6569
6972
|
let declaration = null;
|
|
6570
|
-
while (node != null && node.type !==
|
|
6973
|
+
while (node != null && node.type !== import_utils47.AST_NODE_TYPES.Program) {
|
|
6571
6974
|
declaration = declarationNames(node);
|
|
6572
6975
|
if (declaration !== null) break;
|
|
6573
6976
|
node = node.parent ?? null;
|
|
@@ -6622,7 +7025,7 @@ var jsdoc_restates_signature_default = import_utils46.ESLintUtils.RuleCreator(
|
|
|
6622
7025
|
});
|
|
6623
7026
|
|
|
6624
7027
|
// src/rules/no-restated-comment.ts
|
|
6625
|
-
var
|
|
7028
|
+
var import_utils48 = require("@typescript-eslint/utils");
|
|
6626
7029
|
var MAX_WORDS = 8;
|
|
6627
7030
|
var MIN_CONTENT_TOKENS = 2;
|
|
6628
7031
|
var DIRECTIVE_RE3 = /^(eslint\b|eslint-|sarj-noqa\b|@ts-|prettier-ignore|prettier\b|biome-|c8\b|v8\b|istanbul\b|@type\b|@vite|webpack|<reference|<amd|global\b|noinspection|todo\b|fixme\b|hack\b|xxx\b)/i;
|
|
@@ -6646,7 +7049,7 @@ function headsSiblingRun(node) {
|
|
|
6646
7049
|
const next = index >= 0 ? body[index + 1] : void 0;
|
|
6647
7050
|
return next !== void 0 && next.type === node.type;
|
|
6648
7051
|
}
|
|
6649
|
-
var no_restated_comment_default =
|
|
7052
|
+
var no_restated_comment_default = import_utils48.ESLintUtils.RuleCreator(
|
|
6650
7053
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6651
7054
|
)({
|
|
6652
7055
|
name: "no-restated-comment",
|
|
@@ -6674,7 +7077,7 @@ var no_restated_comment_default = import_utils47.ESLintUtils.RuleCreator(
|
|
|
6674
7077
|
function labelsASiblingRun(comment) {
|
|
6675
7078
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
6676
7079
|
if (token === null) return false;
|
|
6677
|
-
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !==
|
|
7080
|
+
for (let node = sourceCode.getNodeByRangeIndex(token.range[0]); node != null && node.type !== import_utils48.AST_NODE_TYPES.Program; node = node.parent) {
|
|
6678
7081
|
if (headsSiblingRun(node)) return true;
|
|
6679
7082
|
}
|
|
6680
7083
|
return false;
|
|
@@ -6714,7 +7117,7 @@ var no_restated_comment_default = import_utils47.ESLintUtils.RuleCreator(
|
|
|
6714
7117
|
});
|
|
6715
7118
|
|
|
6716
7119
|
// src/rules/trailing-value-narration.ts
|
|
6717
|
-
var
|
|
7120
|
+
var import_utils49 = require("@typescript-eslint/utils");
|
|
6718
7121
|
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
6719
7122
|
var WORD_RE3 = /[A-Za-z]+(?:'[a-z]+)?|\d+(?:\.\d+)?/g;
|
|
6720
7123
|
var UNIT_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -6798,7 +7201,7 @@ function narratesValue(body, code) {
|
|
|
6798
7201
|
(word) => STOPWORDS3.has(word) || UNIT_WORDS.has(word) || commentNumbers.has(word) || identifiers.has(word) || stems.has(stem(word))
|
|
6799
7202
|
);
|
|
6800
7203
|
}
|
|
6801
|
-
var trailing_value_narration_default =
|
|
7204
|
+
var trailing_value_narration_default = import_utils49.ESLintUtils.RuleCreator(
|
|
6802
7205
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6803
7206
|
)({
|
|
6804
7207
|
name: "trailing-value-narration",
|
|
@@ -6839,7 +7242,7 @@ var trailing_value_narration_default = import_utils48.ESLintUtils.RuleCreator(
|
|
|
6839
7242
|
});
|
|
6840
7243
|
|
|
6841
7244
|
// src/rules/no-tautological-expect.ts
|
|
6842
|
-
var
|
|
7245
|
+
var import_utils50 = require("@typescript-eslint/utils");
|
|
6843
7246
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
6844
7247
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
6845
7248
|
"toBeDefined",
|
|
@@ -6853,17 +7256,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
6853
7256
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
6854
7257
|
function isLiteral(node) {
|
|
6855
7258
|
switch (node.type) {
|
|
6856
|
-
case
|
|
7259
|
+
case import_utils50.AST_NODE_TYPES.Literal:
|
|
6857
7260
|
return true;
|
|
6858
|
-
case
|
|
7261
|
+
case import_utils50.AST_NODE_TYPES.TemplateLiteral:
|
|
6859
7262
|
return node.expressions.length === 0;
|
|
6860
|
-
case
|
|
7263
|
+
case import_utils50.AST_NODE_TYPES.UnaryExpression:
|
|
6861
7264
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
6862
|
-
case
|
|
7265
|
+
case import_utils50.AST_NODE_TYPES.ArrayExpression:
|
|
6863
7266
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
6864
|
-
case
|
|
7267
|
+
case import_utils50.AST_NODE_TYPES.ObjectExpression:
|
|
6865
7268
|
return node.properties.every(
|
|
6866
|
-
(property) => property.type ===
|
|
7269
|
+
(property) => property.type === import_utils50.AST_NODE_TYPES.Property && !property.computed && isLiteral(property.value)
|
|
6867
7270
|
);
|
|
6868
7271
|
default:
|
|
6869
7272
|
return false;
|
|
@@ -6871,12 +7274,12 @@ function isLiteral(node) {
|
|
|
6871
7274
|
}
|
|
6872
7275
|
function expectOperand(callee) {
|
|
6873
7276
|
const receiver = callee.object;
|
|
6874
|
-
if (receiver.type !==
|
|
7277
|
+
if (receiver.type !== import_utils50.AST_NODE_TYPES.CallExpression || receiver.callee.type !== import_utils50.AST_NODE_TYPES.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
6875
7278
|
return null;
|
|
6876
7279
|
}
|
|
6877
7280
|
return receiver.arguments[0] ?? null;
|
|
6878
7281
|
}
|
|
6879
|
-
var no_tautological_expect_default =
|
|
7282
|
+
var no_tautological_expect_default = import_utils50.ESLintUtils.RuleCreator(
|
|
6880
7283
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6881
7284
|
)({
|
|
6882
7285
|
name: "no-tautological-expect",
|
|
@@ -6903,10 +7306,10 @@ var no_tautological_expect_default = import_utils49.ESLintUtils.RuleCreator(
|
|
|
6903
7306
|
return {
|
|
6904
7307
|
CallExpression(node) {
|
|
6905
7308
|
const callee = node.callee;
|
|
6906
|
-
if (callee.type !==
|
|
7309
|
+
if (callee.type !== import_utils50.AST_NODE_TYPES.MemberExpression || callee.computed) {
|
|
6907
7310
|
return;
|
|
6908
7311
|
}
|
|
6909
|
-
if (callee.property.type !==
|
|
7312
|
+
if (callee.property.type !== import_utils50.AST_NODE_TYPES.Identifier) {
|
|
6910
7313
|
return;
|
|
6911
7314
|
}
|
|
6912
7315
|
const matcher = callee.property.name;
|
|
@@ -6940,26 +7343,26 @@ var no_tautological_expect_default = import_utils49.ESLintUtils.RuleCreator(
|
|
|
6940
7343
|
});
|
|
6941
7344
|
|
|
6942
7345
|
// src/rules/require-interface-for-injected-service.ts
|
|
6943
|
-
var
|
|
7346
|
+
var import_utils51 = require("@typescript-eslint/utils");
|
|
6944
7347
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
6945
7348
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
6946
7349
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
6947
7350
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
6948
7351
|
var ROUTER_FACTORY_NAME = "Router";
|
|
6949
7352
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
6950
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
6951
|
-
var qualifiedName = (name) => name.type ===
|
|
7353
|
+
var isExportedClass = (node) => node.parent.type === import_utils51.AST_NODE_TYPES.ExportNamedDeclaration || node.parent.type === import_utils51.AST_NODE_TYPES.ExportDefaultDeclaration;
|
|
7354
|
+
var qualifiedName = (name) => name.type === import_utils51.AST_NODE_TYPES.Identifier ? name.name : name.type === import_utils51.AST_NODE_TYPES.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
6952
7355
|
var typeReferenceName = (annotated) => {
|
|
6953
7356
|
let target = annotated;
|
|
6954
|
-
if (target.type ===
|
|
6955
|
-
if (target.type ===
|
|
6956
|
-
if (target.type !==
|
|
7357
|
+
if (target.type === import_utils51.AST_NODE_TYPES.TSParameterProperty) target = target.parameter;
|
|
7358
|
+
if (target.type === import_utils51.AST_NODE_TYPES.AssignmentPattern) target = target.left;
|
|
7359
|
+
if (target.type !== import_utils51.AST_NODE_TYPES.Identifier) return null;
|
|
6957
7360
|
const annotation = target.typeAnnotation?.typeAnnotation;
|
|
6958
|
-
if (annotation === void 0 || annotation.type !==
|
|
7361
|
+
if (annotation === void 0 || annotation.type !== import_utils51.AST_NODE_TYPES.TSTypeReference) {
|
|
6959
7362
|
return null;
|
|
6960
7363
|
}
|
|
6961
7364
|
const { typeName } = annotation;
|
|
6962
|
-
const rightmost = typeName.type ===
|
|
7365
|
+
const rightmost = typeName.type === import_utils51.AST_NODE_TYPES.Identifier ? typeName.name : typeName.type === import_utils51.AST_NODE_TYPES.TSQualifiedName ? typeName.right.name : null;
|
|
6963
7366
|
if (rightmost === null) return null;
|
|
6964
7367
|
return { name: target.name, typeName: rightmost, display: qualifiedName(typeName) };
|
|
6965
7368
|
};
|
|
@@ -6969,17 +7372,17 @@ var readConstructor = (ctor) => {
|
|
|
6969
7372
|
let constructedFields = 0;
|
|
6970
7373
|
if (body !== null && body !== void 0) {
|
|
6971
7374
|
for (const statement of body.body) {
|
|
6972
|
-
if (statement.type !==
|
|
7375
|
+
if (statement.type !== import_utils51.AST_NODE_TYPES.ExpressionStatement) continue;
|
|
6973
7376
|
const expression = statement.expression;
|
|
6974
|
-
if (expression.type !==
|
|
7377
|
+
if (expression.type !== import_utils51.AST_NODE_TYPES.AssignmentExpression || expression.operator !== "=" || expression.left.type !== import_utils51.AST_NODE_TYPES.MemberExpression || expression.left.object.type !== import_utils51.AST_NODE_TYPES.ThisExpression) {
|
|
6975
7378
|
continue;
|
|
6976
7379
|
}
|
|
6977
7380
|
const source = expression.right;
|
|
6978
|
-
if (source.type ===
|
|
7381
|
+
if (source.type === import_utils51.AST_NODE_TYPES.NewExpression) {
|
|
6979
7382
|
constructedFields += 1;
|
|
6980
|
-
} else if (source.type ===
|
|
7383
|
+
} else if (source.type === import_utils51.AST_NODE_TYPES.Identifier) {
|
|
6981
7384
|
storedFrom.add(source.name);
|
|
6982
|
-
} else if (source.type ===
|
|
7385
|
+
} else if (source.type === import_utils51.AST_NODE_TYPES.MemberExpression && source.object.type === import_utils51.AST_NODE_TYPES.Identifier) {
|
|
6983
7386
|
storedFrom.add(source.object.name);
|
|
6984
7387
|
}
|
|
6985
7388
|
}
|
|
@@ -6988,7 +7391,7 @@ var readConstructor = (ctor) => {
|
|
|
6988
7391
|
for (const parameter of ctor.value.params) {
|
|
6989
7392
|
const reference = typeReferenceName(parameter);
|
|
6990
7393
|
if (reference === null) continue;
|
|
6991
|
-
const stored = parameter.type ===
|
|
7394
|
+
const stored = parameter.type === import_utils51.AST_NODE_TYPES.TSParameterProperty || storedFrom.has(reference.name);
|
|
6992
7395
|
if (!stored) continue;
|
|
6993
7396
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
6994
7397
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -7018,19 +7421,19 @@ var subtreeHas = (root, found) => {
|
|
|
7018
7421
|
return hit;
|
|
7019
7422
|
};
|
|
7020
7423
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
7021
|
-
if (node.type ===
|
|
7424
|
+
if (node.type === import_utils51.AST_NODE_TYPES.CallExpression) {
|
|
7022
7425
|
const { callee } = node;
|
|
7023
|
-
if (callee.type ===
|
|
7024
|
-
return callee.type ===
|
|
7426
|
+
if (callee.type === import_utils51.AST_NODE_TYPES.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
7427
|
+
return callee.type === import_utils51.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils51.AST_NODE_TYPES.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
7025
7428
|
}
|
|
7026
|
-
return node.type ===
|
|
7429
|
+
return node.type === import_utils51.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils51.AST_NODE_TYPES.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
7027
7430
|
});
|
|
7028
7431
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
7029
7432
|
var fileInterfaceNames = (program) => {
|
|
7030
7433
|
const names = [];
|
|
7031
7434
|
for (const statement of program.body) {
|
|
7032
|
-
const declaration = statement.type ===
|
|
7033
|
-
if (declaration?.type ===
|
|
7435
|
+
const declaration = statement.type === import_utils51.AST_NODE_TYPES.ExportNamedDeclaration ? statement.declaration : statement;
|
|
7436
|
+
if (declaration?.type === import_utils51.AST_NODE_TYPES.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
7034
7437
|
}
|
|
7035
7438
|
return names;
|
|
7036
7439
|
};
|
|
@@ -7048,16 +7451,16 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
7048
7451
|
var publicMethodNames = (body) => {
|
|
7049
7452
|
const names = [];
|
|
7050
7453
|
for (const member of body.body) {
|
|
7051
|
-
if (member.type !==
|
|
7454
|
+
if (member.type !== import_utils51.AST_NODE_TYPES.MethodDefinition) continue;
|
|
7052
7455
|
if (member.kind !== "method" || member.static) continue;
|
|
7053
7456
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
7054
|
-
if (member.key.type ===
|
|
7055
|
-
if (member.key.type ===
|
|
7457
|
+
if (member.key.type === import_utils51.AST_NODE_TYPES.PrivateIdentifier) continue;
|
|
7458
|
+
if (member.key.type === import_utils51.AST_NODE_TYPES.Identifier) names.push(member.key.name);
|
|
7056
7459
|
else names.push("\u2026");
|
|
7057
7460
|
}
|
|
7058
7461
|
return names;
|
|
7059
7462
|
};
|
|
7060
|
-
var require_interface_for_injected_service_default =
|
|
7463
|
+
var require_interface_for_injected_service_default = import_utils51.ESLintUtils.RuleCreator(
|
|
7061
7464
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7062
7465
|
)({
|
|
7063
7466
|
name: "require-interface-for-injected-service",
|
|
@@ -7085,7 +7488,7 @@ var require_interface_for_injected_service_default = import_utils50.ESLintUtils.
|
|
|
7085
7488
|
if (node.implements.length > 0) return;
|
|
7086
7489
|
if (node.decorators.length > 0) return;
|
|
7087
7490
|
const ctor = node.body.body.find(
|
|
7088
|
-
(member) => member.type ===
|
|
7491
|
+
(member) => member.type === import_utils51.AST_NODE_TYPES.MethodDefinition && member.kind === "constructor"
|
|
7089
7492
|
);
|
|
7090
7493
|
if (ctor === void 0) return;
|
|
7091
7494
|
const { collaborators, constructedFields } = readConstructor(ctor);
|
|
@@ -7110,26 +7513,26 @@ var require_interface_for_injected_service_default = import_utils50.ESLintUtils.
|
|
|
7110
7513
|
});
|
|
7111
7514
|
|
|
7112
7515
|
// src/rules/prefer-non-nullable-collection.ts
|
|
7113
|
-
var
|
|
7516
|
+
var import_utils52 = require("@typescript-eslint/utils");
|
|
7114
7517
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7115
7518
|
function propertyName(node) {
|
|
7116
7519
|
const key = node.key;
|
|
7117
|
-
if (key.type ===
|
|
7118
|
-
if (key.type ===
|
|
7520
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Identifier) return key.name;
|
|
7521
|
+
if (key.type === import_utils52.AST_NODE_TYPES.Literal) return String(key.value);
|
|
7119
7522
|
return "collection";
|
|
7120
7523
|
}
|
|
7121
7524
|
function isArrayType(node) {
|
|
7122
|
-
if (node.type ===
|
|
7123
|
-
return node.type ===
|
|
7525
|
+
if (node.type === import_utils52.AST_NODE_TYPES.TSArrayType) return true;
|
|
7526
|
+
return node.type === import_utils52.AST_NODE_TYPES.TSTypeReference && node.typeName.type === import_utils52.AST_NODE_TYPES.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7124
7527
|
}
|
|
7125
7528
|
function isNullishType(node) {
|
|
7126
|
-
return node.type ===
|
|
7529
|
+
return node.type === import_utils52.AST_NODE_TYPES.TSNullKeyword || node.type === import_utils52.AST_NODE_TYPES.TSUndefinedKeyword;
|
|
7127
7530
|
}
|
|
7128
7531
|
function isNullableArrayOnly(node) {
|
|
7129
7532
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
7130
7533
|
return values.length > 0 && values.length < node.types.length && values.every(isArrayType);
|
|
7131
7534
|
}
|
|
7132
|
-
var prefer_non_nullable_collection_default =
|
|
7535
|
+
var prefer_non_nullable_collection_default = import_utils52.ESLintUtils.RuleCreator(
|
|
7133
7536
|
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
7134
7537
|
)({
|
|
7135
7538
|
name: "prefer-non-nullable-collection",
|
|
@@ -7152,7 +7555,7 @@ var prefer_non_nullable_collection_default = import_utils51.ESLintUtils.RuleCrea
|
|
|
7152
7555
|
function checkOptionalProperty(node) {
|
|
7153
7556
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7154
7557
|
if (annotation === void 0) return;
|
|
7155
|
-
if (annotation.type !==
|
|
7558
|
+
if (annotation.type !== import_utils52.AST_NODE_TYPES.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7156
7559
|
return;
|
|
7157
7560
|
}
|
|
7158
7561
|
context.report({
|
|
@@ -7165,7 +7568,7 @@ var prefer_non_nullable_collection_default = import_utils51.ESLintUtils.RuleCrea
|
|
|
7165
7568
|
TSPropertySignature: checkOptionalProperty,
|
|
7166
7569
|
PropertyDefinition: checkOptionalProperty,
|
|
7167
7570
|
TSTypeAliasDeclaration(node) {
|
|
7168
|
-
if (node.typeAnnotation.type !==
|
|
7571
|
+
if (node.typeAnnotation.type !== import_utils52.AST_NODE_TYPES.TSUnionType) return;
|
|
7169
7572
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7170
7573
|
context.report({
|
|
7171
7574
|
node,
|
|
@@ -7178,7 +7581,7 @@ var prefer_non_nullable_collection_default = import_utils51.ESLintUtils.RuleCrea
|
|
|
7178
7581
|
});
|
|
7179
7582
|
|
|
7180
7583
|
// src/rules/no-implicit-attribute-access.ts
|
|
7181
|
-
var
|
|
7584
|
+
var import_utils53 = require("@typescript-eslint/utils");
|
|
7182
7585
|
var EXCLUDED_BASES = /* @__PURE__ */ new Set([
|
|
7183
7586
|
"environ",
|
|
7184
7587
|
"headers",
|
|
@@ -7194,15 +7597,15 @@ var EXCLUDED_BASES = /* @__PURE__ */ new Set([
|
|
|
7194
7597
|
"sessionStorage"
|
|
7195
7598
|
]);
|
|
7196
7599
|
function getBaseName(node) {
|
|
7197
|
-
if (node.type ===
|
|
7600
|
+
if (node.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7198
7601
|
return node.name;
|
|
7199
7602
|
}
|
|
7200
|
-
if (node.type ===
|
|
7603
|
+
if (node.type === import_utils53.AST_NODE_TYPES.MemberExpression && node.property.type === import_utils53.AST_NODE_TYPES.Identifier) {
|
|
7201
7604
|
return node.property.name;
|
|
7202
7605
|
}
|
|
7203
7606
|
return null;
|
|
7204
7607
|
}
|
|
7205
|
-
var no_implicit_attribute_access_default =
|
|
7608
|
+
var no_implicit_attribute_access_default = import_utils53.ESLintUtils.RuleCreator(
|
|
7206
7609
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7207
7610
|
)({
|
|
7208
7611
|
name: "no-implicit-attribute-access",
|
|
@@ -7223,7 +7626,7 @@ var no_implicit_attribute_access_default = import_utils52.ESLintUtils.RuleCreato
|
|
|
7223
7626
|
if (!node.computed) {
|
|
7224
7627
|
return;
|
|
7225
7628
|
}
|
|
7226
|
-
if (node.property.type ===
|
|
7629
|
+
if (node.property.type === import_utils53.AST_NODE_TYPES.Literal && typeof node.property.value === "string") {
|
|
7227
7630
|
const baseName = getBaseName(node.object);
|
|
7228
7631
|
if (!baseName || !EXCLUDED_BASES.has(baseName)) {
|
|
7229
7632
|
context.report({
|
|
@@ -7236,11 +7639,11 @@ var no_implicit_attribute_access_default = import_utils52.ESLintUtils.RuleCreato
|
|
|
7236
7639
|
},
|
|
7237
7640
|
CallExpression(node) {
|
|
7238
7641
|
const callee = node.callee;
|
|
7239
|
-
if (callee.type ===
|
|
7240
|
-
const method = callee.property.type ===
|
|
7642
|
+
if (callee.type === import_utils53.AST_NODE_TYPES.MemberExpression) {
|
|
7643
|
+
const method = callee.property.type === import_utils53.AST_NODE_TYPES.Identifier ? callee.property.name : null;
|
|
7241
7644
|
if (method === "get") {
|
|
7242
7645
|
const arg = node.arguments[0];
|
|
7243
|
-
if (arg && arg.type ===
|
|
7646
|
+
if (arg && arg.type === import_utils53.AST_NODE_TYPES.Literal && typeof arg.value === "string") {
|
|
7244
7647
|
const baseName = getBaseName(callee.object);
|
|
7245
7648
|
if (!baseName || !EXCLUDED_BASES.has(baseName)) {
|
|
7246
7649
|
context.report({
|
|
@@ -7258,8 +7661,8 @@ var no_implicit_attribute_access_default = import_utils52.ESLintUtils.RuleCreato
|
|
|
7258
7661
|
});
|
|
7259
7662
|
|
|
7260
7663
|
// src/rules/strict-test-assertions.ts
|
|
7261
|
-
var
|
|
7262
|
-
var strict_test_assertions_default =
|
|
7664
|
+
var import_utils54 = require("@typescript-eslint/utils");
|
|
7665
|
+
var strict_test_assertions_default = import_utils54.ESLintUtils.RuleCreator.withoutDocs({
|
|
7263
7666
|
meta: {
|
|
7264
7667
|
type: "suggestion",
|
|
7265
7668
|
docs: {
|
|
@@ -7277,9 +7680,9 @@ var strict_test_assertions_default = import_utils53.ESLintUtils.RuleCreator.with
|
|
|
7277
7680
|
let currentObject = null;
|
|
7278
7681
|
let sequence = [];
|
|
7279
7682
|
function getExpectObject(expr) {
|
|
7280
|
-
if (expr.type ===
|
|
7683
|
+
if (expr.type === import_utils54.AST_NODE_TYPES.CallExpression && expr.callee.type === import_utils54.AST_NODE_TYPES.MemberExpression && expr.callee.object.type === import_utils54.AST_NODE_TYPES.CallExpression && expr.callee.object.callee.type === import_utils54.AST_NODE_TYPES.Identifier && expr.callee.object.callee.name === "expect" && expr.callee.object.arguments.length === 1) {
|
|
7281
7684
|
const arg = expr.callee.object.arguments.at(0);
|
|
7282
|
-
if (arg?.type ===
|
|
7685
|
+
if (arg?.type === import_utils54.AST_NODE_TYPES.MemberExpression) {
|
|
7283
7686
|
return arg.object;
|
|
7284
7687
|
}
|
|
7285
7688
|
}
|
|
@@ -7295,12 +7698,12 @@ var strict_test_assertions_default = import_utils53.ESLintUtils.RuleCreator.with
|
|
|
7295
7698
|
if (!currentObject) return null;
|
|
7296
7699
|
const objectText = context.sourceCode.getText(currentObject);
|
|
7297
7700
|
const props = sequence.map((stmt) => {
|
|
7298
|
-
if (stmt.expression.type !==
|
|
7701
|
+
if (stmt.expression.type !== import_utils54.AST_NODE_TYPES.CallExpression || stmt.expression.callee.type !== import_utils54.AST_NODE_TYPES.MemberExpression || stmt.expression.callee.object.type !== import_utils54.AST_NODE_TYPES.CallExpression) {
|
|
7299
7702
|
return null;
|
|
7300
7703
|
}
|
|
7301
7704
|
const actual = stmt.expression.callee.object.arguments.at(0);
|
|
7302
7705
|
const expected = stmt.expression.arguments.at(0);
|
|
7303
|
-
if (actual?.type ===
|
|
7706
|
+
if (actual?.type === import_utils54.AST_NODE_TYPES.MemberExpression && actual.property.type === import_utils54.AST_NODE_TYPES.Identifier && expected) {
|
|
7304
7707
|
const propName2 = actual.property.name;
|
|
7305
7708
|
const valText = context.sourceCode.getText(expected);
|
|
7306
7709
|
return `${propName2}: ${valText}`;
|
|
@@ -7318,7 +7721,7 @@ var strict_test_assertions_default = import_utils53.ESLintUtils.RuleCreator.with
|
|
|
7318
7721
|
}
|
|
7319
7722
|
}
|
|
7320
7723
|
for (const statement of body) {
|
|
7321
|
-
if (statement.type ===
|
|
7724
|
+
if (statement.type === import_utils54.AST_NODE_TYPES.ExpressionStatement) {
|
|
7322
7725
|
const obj = getExpectObject(statement.expression);
|
|
7323
7726
|
if (obj && currentObject && context.sourceCode.getText(obj) === context.sourceCode.getText(currentObject)) {
|
|
7324
7727
|
sequence.push(statement);
|
|
@@ -7352,8 +7755,8 @@ var strict_test_assertions_default = import_utils53.ESLintUtils.RuleCreator.with
|
|
|
7352
7755
|
});
|
|
7353
7756
|
|
|
7354
7757
|
// src/rules/no-async-callback-in-waitfor.ts
|
|
7355
|
-
var
|
|
7356
|
-
var no_async_callback_in_waitfor_default =
|
|
7758
|
+
var import_utils55 = require("@typescript-eslint/utils");
|
|
7759
|
+
var no_async_callback_in_waitfor_default = import_utils55.ESLintUtils.RuleCreator(
|
|
7357
7760
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7358
7761
|
)({
|
|
7359
7762
|
name: "no-async-callback-in-waitfor",
|
|
@@ -7374,9 +7777,9 @@ var no_async_callback_in_waitfor_default = import_utils54.ESLintUtils.RuleCreato
|
|
|
7374
7777
|
}
|
|
7375
7778
|
return {
|
|
7376
7779
|
CallExpression(node) {
|
|
7377
|
-
if (node.callee.type ===
|
|
7780
|
+
if (node.callee.type === import_utils55.AST_NODE_TYPES.Identifier && node.callee.name === "waitFor") {
|
|
7378
7781
|
const callback = node.arguments[0];
|
|
7379
|
-
if (callback && (callback.type ===
|
|
7782
|
+
if (callback && (callback.type === import_utils55.AST_NODE_TYPES.ArrowFunctionExpression || callback.type === import_utils55.AST_NODE_TYPES.FunctionExpression) && callback.async) {
|
|
7380
7783
|
context.report({
|
|
7381
7784
|
node: callback,
|
|
7382
7785
|
messageId: "noAsyncCallbackInWaitFor"
|
|
@@ -7389,7 +7792,7 @@ var no_async_callback_in_waitfor_default = import_utils54.ESLintUtils.RuleCreato
|
|
|
7389
7792
|
});
|
|
7390
7793
|
|
|
7391
7794
|
// src/rules/no-hand-rolled-sleep.ts
|
|
7392
|
-
var
|
|
7795
|
+
var import_utils56 = require("@typescript-eslint/utils");
|
|
7393
7796
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
7394
7797
|
"globalThis",
|
|
7395
7798
|
"window",
|
|
@@ -7408,66 +7811,66 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
7408
7811
|
return false;
|
|
7409
7812
|
}
|
|
7410
7813
|
function isSetTimeoutCallee(callee) {
|
|
7411
|
-
if (callee.type ===
|
|
7814
|
+
if (callee.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
7412
7815
|
return callee.name === "setTimeout";
|
|
7413
7816
|
}
|
|
7414
|
-
return callee.type ===
|
|
7817
|
+
return callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !callee.computed && callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && callee.property.name === "setTimeout" && callee.object.type === import_utils56.AST_NODE_TYPES.Identifier && GLOBAL_OBJECTS2.has(callee.object.name);
|
|
7415
7818
|
}
|
|
7416
7819
|
function soleCall(fn) {
|
|
7417
|
-
if (fn.body.type !==
|
|
7418
|
-
return fn.body.type ===
|
|
7820
|
+
if (fn.body.type !== import_utils56.AST_NODE_TYPES.BlockStatement) {
|
|
7821
|
+
return fn.body.type === import_utils56.AST_NODE_TYPES.CallExpression ? fn.body : null;
|
|
7419
7822
|
}
|
|
7420
7823
|
if (fn.body.body.length !== 1) {
|
|
7421
7824
|
return null;
|
|
7422
7825
|
}
|
|
7423
7826
|
const [only] = fn.body.body;
|
|
7424
|
-
if (only?.type !==
|
|
7827
|
+
if (only?.type !== import_utils56.AST_NODE_TYPES.ExpressionStatement) {
|
|
7425
7828
|
return null;
|
|
7426
7829
|
}
|
|
7427
|
-
return only.expression.type ===
|
|
7830
|
+
return only.expression.type === import_utils56.AST_NODE_TYPES.CallExpression ? only.expression : null;
|
|
7428
7831
|
}
|
|
7429
7832
|
function isTimedDelay(delay) {
|
|
7430
7833
|
if (delay === void 0) {
|
|
7431
7834
|
return false;
|
|
7432
7835
|
}
|
|
7433
|
-
if (delay.type ===
|
|
7836
|
+
if (delay.type === import_utils56.AST_NODE_TYPES.Literal && typeof delay.value === "number") {
|
|
7434
7837
|
return delay.value !== 0;
|
|
7435
7838
|
}
|
|
7436
7839
|
return true;
|
|
7437
7840
|
}
|
|
7438
7841
|
function settlesWithoutValue(callback, name) {
|
|
7439
|
-
if (callback.type ===
|
|
7842
|
+
if (callback.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
7440
7843
|
return callback.name === name;
|
|
7441
7844
|
}
|
|
7442
|
-
if (callback.type !==
|
|
7845
|
+
if (callback.type !== import_utils56.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils56.AST_NODE_TYPES.FunctionExpression) {
|
|
7443
7846
|
return false;
|
|
7444
7847
|
}
|
|
7445
7848
|
const call = soleCall(callback);
|
|
7446
|
-
return call !== null && call.arguments.length === 0 && call.callee.type ===
|
|
7849
|
+
return call !== null && call.arguments.length === 0 && call.callee.type === import_utils56.AST_NODE_TYPES.Identifier && call.callee.name === name;
|
|
7447
7850
|
}
|
|
7448
7851
|
function rejectsInCallback(callback, name) {
|
|
7449
|
-
if (callback.type ===
|
|
7852
|
+
if (callback.type === import_utils56.AST_NODE_TYPES.Identifier) {
|
|
7450
7853
|
return callback.name === name;
|
|
7451
7854
|
}
|
|
7452
|
-
if (callback.type !==
|
|
7855
|
+
if (callback.type !== import_utils56.AST_NODE_TYPES.ArrowFunctionExpression && callback.type !== import_utils56.AST_NODE_TYPES.FunctionExpression) {
|
|
7453
7856
|
return false;
|
|
7454
7857
|
}
|
|
7455
7858
|
const call = soleCall(callback);
|
|
7456
|
-
return call !== null && call.callee.type ===
|
|
7859
|
+
return call !== null && call.callee.type === import_utils56.AST_NODE_TYPES.Identifier && call.callee.name === name;
|
|
7457
7860
|
}
|
|
7458
7861
|
function parameterName(fn, index) {
|
|
7459
7862
|
const parameter = fn.params[index];
|
|
7460
|
-
return parameter?.type ===
|
|
7863
|
+
return parameter?.type === import_utils56.AST_NODE_TYPES.Identifier ? parameter.name : null;
|
|
7461
7864
|
}
|
|
7462
7865
|
function isRaceArm(node) {
|
|
7463
7866
|
const array = node.parent;
|
|
7464
|
-
if (array?.type !==
|
|
7867
|
+
if (array?.type !== import_utils56.AST_NODE_TYPES.ArrayExpression) {
|
|
7465
7868
|
return false;
|
|
7466
7869
|
}
|
|
7467
7870
|
const call = array.parent;
|
|
7468
|
-
return call?.type ===
|
|
7871
|
+
return call?.type === import_utils56.AST_NODE_TYPES.CallExpression && call.arguments[0] === array && call.callee.type === import_utils56.AST_NODE_TYPES.MemberExpression && !call.callee.computed && call.callee.object.type === import_utils56.AST_NODE_TYPES.Identifier && call.callee.object.name === "Promise" && call.callee.property.type === import_utils56.AST_NODE_TYPES.Identifier && RACE_METHODS.has(call.callee.property.name);
|
|
7469
7872
|
}
|
|
7470
|
-
var no_hand_rolled_sleep_default =
|
|
7873
|
+
var no_hand_rolled_sleep_default = import_utils56.ESLintUtils.RuleCreator(
|
|
7471
7874
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7472
7875
|
)({
|
|
7473
7876
|
name: "no-hand-rolled-sleep",
|
|
@@ -7515,10 +7918,10 @@ var no_hand_rolled_sleep_default = import_utils55.ESLintUtils.RuleCreator(
|
|
|
7515
7918
|
}
|
|
7516
7919
|
const program = sourceCode.ast;
|
|
7517
7920
|
for (const statement of program.body) {
|
|
7518
|
-
if (statement.type ===
|
|
7921
|
+
if (statement.type === import_utils56.AST_NODE_TYPES.ExpressionStatement && statement.expression.type === import_utils56.AST_NODE_TYPES.Literal && statement.expression.value === "use client") {
|
|
7519
7922
|
return true;
|
|
7520
7923
|
}
|
|
7521
|
-
if (statement.type ===
|
|
7924
|
+
if (statement.type === import_utils56.AST_NODE_TYPES.ImportDeclaration && typeof statement.source.value === "string" && CLIENT_ONLY_MODULES.test(statement.source.value)) {
|
|
7522
7925
|
return true;
|
|
7523
7926
|
}
|
|
7524
7927
|
}
|
|
@@ -7534,11 +7937,11 @@ var no_hand_rolled_sleep_default = import_utils55.ESLintUtils.RuleCreator(
|
|
|
7534
7937
|
};
|
|
7535
7938
|
return {
|
|
7536
7939
|
NewExpression(node) {
|
|
7537
|
-
if (node.callee.type !==
|
|
7940
|
+
if (node.callee.type !== import_utils56.AST_NODE_TYPES.Identifier || node.callee.name !== "Promise") {
|
|
7538
7941
|
return;
|
|
7539
7942
|
}
|
|
7540
7943
|
const executor = node.arguments[0];
|
|
7541
|
-
if (executor?.type !==
|
|
7944
|
+
if (executor?.type !== import_utils56.AST_NODE_TYPES.ArrowFunctionExpression && executor?.type !== import_utils56.AST_NODE_TYPES.FunctionExpression) {
|
|
7542
7945
|
return;
|
|
7543
7946
|
}
|
|
7544
7947
|
const call = soleCall(executor);
|
|
@@ -7566,8 +7969,8 @@ var no_hand_rolled_sleep_default = import_utils55.ESLintUtils.RuleCreator(
|
|
|
7566
7969
|
});
|
|
7567
7970
|
|
|
7568
7971
|
// src/rules/prefer-setup-file-mocks.ts
|
|
7569
|
-
var
|
|
7570
|
-
var prefer_setup_file_mocks_default =
|
|
7972
|
+
var import_utils57 = require("@typescript-eslint/utils");
|
|
7973
|
+
var prefer_setup_file_mocks_default = import_utils57.ESLintUtils.RuleCreator(
|
|
7571
7974
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7572
7975
|
)({
|
|
7573
7976
|
name: "prefer-setup-file-mocks",
|
|
@@ -7588,7 +7991,7 @@ var prefer_setup_file_mocks_default = import_utils56.ESLintUtils.RuleCreator(
|
|
|
7588
7991
|
}
|
|
7589
7992
|
return {
|
|
7590
7993
|
CallExpression(node) {
|
|
7591
|
-
if (node.callee.type ===
|
|
7994
|
+
if (node.callee.type === import_utils57.AST_NODE_TYPES.MemberExpression && node.callee.object.type === import_utils57.AST_NODE_TYPES.Identifier && (node.callee.object.name === "vi" || node.callee.object.name === "jest") && node.callee.property.type === import_utils57.AST_NODE_TYPES.Identifier && node.callee.property.name === "mock") {
|
|
7592
7995
|
context.report({
|
|
7593
7996
|
node,
|
|
7594
7997
|
messageId: "preferSetupFileMocks"
|
|
@@ -7626,6 +8029,7 @@ var rules = {
|
|
|
7626
8029
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
7627
8030
|
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
7628
8031
|
"prefer-zod-enum": prefer_zod_enum_default,
|
|
8032
|
+
"prefer-zod-infer": prefer_zod_infer_default,
|
|
7629
8033
|
"no-silent-promise-catch": no_silent_promise_catch_default,
|
|
7630
8034
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
7631
8035
|
"no-offset-pagination": no_offset_pagination_default,
|
|
@@ -7656,7 +8060,7 @@ var rules = {
|
|
|
7656
8060
|
var plugin = {
|
|
7657
8061
|
meta: {
|
|
7658
8062
|
name: "@sarj/eslint-plugin",
|
|
7659
|
-
version: "4.
|
|
8063
|
+
version: "4.2.0"
|
|
7660
8064
|
},
|
|
7661
8065
|
rules,
|
|
7662
8066
|
configs: {
|
|
@@ -7692,6 +8096,11 @@ var plugin = {
|
|
|
7692
8096
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
7693
8097
|
"@sarj/prefer-string-literal-union": "warn",
|
|
7694
8098
|
"@sarj/prefer-zod-enum": "warn",
|
|
8099
|
+
// A type hand-written beside the Zod schema it restates drifts the
|
|
8100
|
+
// moment the schema gains a field. 30,759-file, 17-repo sweep
|
|
8101
|
+
// (2026-07): 5 reports, 5 true positives, all in public repos.
|
|
8102
|
+
// `requireIdenticalShape: false` widens it to 8 reports, 1 of them noise.
|
|
8103
|
+
"@sarj/prefer-zod-infer": "warn",
|
|
7695
8104
|
// Mined from 2y of PR review feedback + 5-repo code-smell audit (2026-07).
|
|
7696
8105
|
"@sarj/require-fetch-timeout": "warn",
|
|
7697
8106
|
"@sarj/no-silent-promise-catch": "warn",
|
|
@@ -7787,6 +8196,8 @@ var plugin = {
|
|
|
7787
8196
|
// Promoted to error 2026-07-25 — strict means strict (user directive).
|
|
7788
8197
|
"@sarj/prefer-string-literal-union": "error",
|
|
7789
8198
|
"@sarj/prefer-zod-enum": "error",
|
|
8199
|
+
// See the `recommended` block for the measured counts.
|
|
8200
|
+
"@sarj/prefer-zod-infer": "error",
|
|
7790
8201
|
// Mined from 2y of PR review feedback + 5-repo code-smell audit (2026-07).
|
|
7791
8202
|
"@sarj/require-fetch-timeout": "error",
|
|
7792
8203
|
"@sarj/no-silent-promise-catch": "error",
|