@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.js
CHANGED
|
@@ -3024,6 +3024,9 @@ import { ESLintUtils as ESLintUtils18, AST_NODE_TYPES as AST_NODE_TYPES11 } from
|
|
|
3024
3024
|
var ZOD_PREFIX_RE = /^Z[A-Z]/;
|
|
3025
3025
|
var ZOD_SUFFIX_RE = /Schema$/;
|
|
3026
3026
|
var ZOD_SCHEMA_NAME_RE = /Schema$|^Z[A-Z]/;
|
|
3027
|
+
function isZodModule(source) {
|
|
3028
|
+
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
3029
|
+
}
|
|
3027
3030
|
|
|
3028
3031
|
// src/rules/require-zod-form-validation.ts
|
|
3029
3032
|
var looksLikeZodSchema = (node) => {
|
|
@@ -4666,9 +4669,6 @@ import {
|
|
|
4666
4669
|
AST_NODE_TYPES as AST_NODE_TYPES18,
|
|
4667
4670
|
ESLintUtils as ESLintUtils27
|
|
4668
4671
|
} from "@typescript-eslint/utils";
|
|
4669
|
-
function isZodModule(source) {
|
|
4670
|
-
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
4671
|
-
}
|
|
4672
4672
|
var prefer_zod_enum_default = ESLintUtils27.RuleCreator(
|
|
4673
4673
|
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
4674
4674
|
)({
|
|
@@ -4754,11 +4754,417 @@ var prefer_zod_enum_default = ESLintUtils27.RuleCreator(
|
|
|
4754
4754
|
}
|
|
4755
4755
|
});
|
|
4756
4756
|
|
|
4757
|
+
// src/rules/prefer-zod-infer.ts
|
|
4758
|
+
import {
|
|
4759
|
+
AST_NODE_TYPES as AST_NODE_TYPES19,
|
|
4760
|
+
ESLintUtils as ESLintUtils28
|
|
4761
|
+
} from "@typescript-eslint/utils";
|
|
4762
|
+
var SHAPE_PRESERVING_METHODS = /* @__PURE__ */ new Set([
|
|
4763
|
+
"describe",
|
|
4764
|
+
"refine",
|
|
4765
|
+
"superRefine",
|
|
4766
|
+
"check",
|
|
4767
|
+
"meta",
|
|
4768
|
+
"register"
|
|
4769
|
+
]);
|
|
4770
|
+
var OPTIONAL_MODIFIERS = /* @__PURE__ */ new Set([
|
|
4771
|
+
"optional",
|
|
4772
|
+
"nullish",
|
|
4773
|
+
"default",
|
|
4774
|
+
"prefault",
|
|
4775
|
+
"catch"
|
|
4776
|
+
]);
|
|
4777
|
+
var NULLABLE_MODIFIERS = /* @__PURE__ */ new Set(["nullable", "nullish"]);
|
|
4778
|
+
var RESHAPING_MODIFIERS = /* @__PURE__ */ new Set([
|
|
4779
|
+
"transform",
|
|
4780
|
+
"pipe",
|
|
4781
|
+
"preprocess",
|
|
4782
|
+
"brand",
|
|
4783
|
+
"overwrite"
|
|
4784
|
+
]);
|
|
4785
|
+
var MODULE_LEVEL_RESHAPERS = /* @__PURE__ */ new Set([
|
|
4786
|
+
"transform",
|
|
4787
|
+
"pipe",
|
|
4788
|
+
"preprocess"
|
|
4789
|
+
]);
|
|
4790
|
+
var ZOD_TYPE_CONSTRAINTS = /* @__PURE__ */ new Set([
|
|
4791
|
+
"ZodType",
|
|
4792
|
+
"ZodSchema",
|
|
4793
|
+
"ZodTypeAny",
|
|
4794
|
+
"ZodMiniType",
|
|
4795
|
+
"Schema"
|
|
4796
|
+
]);
|
|
4797
|
+
var LEAF_NODE_TYPES = {
|
|
4798
|
+
string: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4799
|
+
email: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4800
|
+
url: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4801
|
+
uuid: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4802
|
+
ulid: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4803
|
+
cuid: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4804
|
+
cuid2: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4805
|
+
nanoid: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4806
|
+
iso: [AST_NODE_TYPES19.TSStringKeyword],
|
|
4807
|
+
number: [AST_NODE_TYPES19.TSNumberKeyword],
|
|
4808
|
+
int: [AST_NODE_TYPES19.TSNumberKeyword],
|
|
4809
|
+
float32: [AST_NODE_TYPES19.TSNumberKeyword],
|
|
4810
|
+
float64: [AST_NODE_TYPES19.TSNumberKeyword],
|
|
4811
|
+
boolean: [AST_NODE_TYPES19.TSBooleanKeyword],
|
|
4812
|
+
bigint: [AST_NODE_TYPES19.TSBigIntKeyword],
|
|
4813
|
+
symbol: [AST_NODE_TYPES19.TSSymbolKeyword],
|
|
4814
|
+
any: [AST_NODE_TYPES19.TSAnyKeyword],
|
|
4815
|
+
unknown: [AST_NODE_TYPES19.TSUnknownKeyword],
|
|
4816
|
+
never: [AST_NODE_TYPES19.TSNeverKeyword],
|
|
4817
|
+
void: [AST_NODE_TYPES19.TSVoidKeyword],
|
|
4818
|
+
null: [AST_NODE_TYPES19.TSNullKeyword],
|
|
4819
|
+
undefined: [AST_NODE_TYPES19.TSUndefinedKeyword],
|
|
4820
|
+
literal: [AST_NODE_TYPES19.TSLiteralType],
|
|
4821
|
+
date: [AST_NODE_TYPES19.TSTypeReference],
|
|
4822
|
+
array: [AST_NODE_TYPES19.TSArrayType, AST_NODE_TYPES19.TSTypeReference],
|
|
4823
|
+
tuple: [AST_NODE_TYPES19.TSTupleType],
|
|
4824
|
+
object: [AST_NODE_TYPES19.TSTypeLiteral, AST_NODE_TYPES19.TSTypeReference],
|
|
4825
|
+
strictObject: [AST_NODE_TYPES19.TSTypeLiteral, AST_NODE_TYPES19.TSTypeReference],
|
|
4826
|
+
looseObject: [AST_NODE_TYPES19.TSTypeLiteral, AST_NODE_TYPES19.TSTypeReference],
|
|
4827
|
+
record: [AST_NODE_TYPES19.TSTypeReference, AST_NODE_TYPES19.TSTypeLiteral],
|
|
4828
|
+
map: [AST_NODE_TYPES19.TSTypeReference],
|
|
4829
|
+
set: [AST_NODE_TYPES19.TSTypeReference],
|
|
4830
|
+
promise: [AST_NODE_TYPES19.TSTypeReference],
|
|
4831
|
+
enum: [AST_NODE_TYPES19.TSUnionType, AST_NODE_TYPES19.TSTypeReference, AST_NODE_TYPES19.TSLiteralType],
|
|
4832
|
+
nativeEnum: [AST_NODE_TYPES19.TSUnionType, AST_NODE_TYPES19.TSTypeReference, AST_NODE_TYPES19.TSLiteralType],
|
|
4833
|
+
union: [AST_NODE_TYPES19.TSUnionType, AST_NODE_TYPES19.TSTypeReference],
|
|
4834
|
+
discriminatedUnion: [AST_NODE_TYPES19.TSUnionType, AST_NODE_TYPES19.TSTypeReference],
|
|
4835
|
+
intersection: [AST_NODE_TYPES19.TSIntersectionType, AST_NODE_TYPES19.TSTypeReference]
|
|
4836
|
+
};
|
|
4837
|
+
function normalizeSchemaName(name) {
|
|
4838
|
+
return name.replace(/Schema$/i, "").replace(/^Z(?=[A-Z])/, "").toLowerCase();
|
|
4839
|
+
}
|
|
4840
|
+
function normalizeTypeName(name) {
|
|
4841
|
+
return name.replace(/Type$/, "").toLowerCase();
|
|
4842
|
+
}
|
|
4843
|
+
function unwrapNullish(annotation) {
|
|
4844
|
+
if (annotation.type !== AST_NODE_TYPES19.TSUnionType) {
|
|
4845
|
+
return {
|
|
4846
|
+
core: annotation,
|
|
4847
|
+
nullable: annotation.type === AST_NODE_TYPES19.TSNullKeyword
|
|
4848
|
+
};
|
|
4849
|
+
}
|
|
4850
|
+
const rest = [];
|
|
4851
|
+
let nullable = false;
|
|
4852
|
+
for (const member of annotation.types) {
|
|
4853
|
+
if (member.type === AST_NODE_TYPES19.TSNullKeyword) {
|
|
4854
|
+
nullable = true;
|
|
4855
|
+
continue;
|
|
4856
|
+
}
|
|
4857
|
+
if (member.type === AST_NODE_TYPES19.TSUndefinedKeyword) {
|
|
4858
|
+
continue;
|
|
4859
|
+
}
|
|
4860
|
+
rest.push(member);
|
|
4861
|
+
}
|
|
4862
|
+
if (rest.length === 1) {
|
|
4863
|
+
return { core: rest[0] ?? null, nullable };
|
|
4864
|
+
}
|
|
4865
|
+
return { core: rest.length === 0 ? null : annotation, nullable };
|
|
4866
|
+
}
|
|
4867
|
+
function leafAgrees(leaf, annotation) {
|
|
4868
|
+
if (leaf === null || annotation === null) {
|
|
4869
|
+
return null;
|
|
4870
|
+
}
|
|
4871
|
+
const expected = LEAF_NODE_TYPES[leaf];
|
|
4872
|
+
if (expected === void 0) {
|
|
4873
|
+
return null;
|
|
4874
|
+
}
|
|
4875
|
+
const { core } = unwrapNullish(annotation);
|
|
4876
|
+
if (core === null) {
|
|
4877
|
+
return null;
|
|
4878
|
+
}
|
|
4879
|
+
return expected.includes(core.type);
|
|
4880
|
+
}
|
|
4881
|
+
var prefer_zod_infer_default = ESLintUtils28.RuleCreator(
|
|
4882
|
+
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
4883
|
+
)({
|
|
4884
|
+
name: "prefer-zod-infer",
|
|
4885
|
+
meta: {
|
|
4886
|
+
type: "problem",
|
|
4887
|
+
docs: {
|
|
4888
|
+
description: "Derive a type from its Zod schema with `z.infer` instead of hand-writing a twin declaration beside it."
|
|
4889
|
+
},
|
|
4890
|
+
schema: [
|
|
4891
|
+
{
|
|
4892
|
+
type: "object",
|
|
4893
|
+
additionalProperties: false,
|
|
4894
|
+
properties: {
|
|
4895
|
+
ignoreTypeNames: {
|
|
4896
|
+
type: "array",
|
|
4897
|
+
items: { type: "string" }
|
|
4898
|
+
},
|
|
4899
|
+
requireIdenticalShape: { type: "boolean" }
|
|
4900
|
+
}
|
|
4901
|
+
}
|
|
4902
|
+
],
|
|
4903
|
+
messages: {
|
|
4904
|
+
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."
|
|
4905
|
+
}
|
|
4906
|
+
},
|
|
4907
|
+
defaultOptions: [{}],
|
|
4908
|
+
create(context, [optionsArg]) {
|
|
4909
|
+
const ignorePatterns = (optionsArg?.ignoreTypeNames ?? []).map(
|
|
4910
|
+
(source) => new RegExp(source, "u")
|
|
4911
|
+
);
|
|
4912
|
+
const requireIdenticalShape = optionsArg?.requireIdenticalShape ?? true;
|
|
4913
|
+
if (isTestFile(context.filename) || isStoryFile(context.filename) || isGeneratedFile(context.filename, context.sourceCode.text)) {
|
|
4914
|
+
return {};
|
|
4915
|
+
}
|
|
4916
|
+
const zodNamespaces = /* @__PURE__ */ new Set();
|
|
4917
|
+
const schemas = [];
|
|
4918
|
+
const typeDeclarations = [];
|
|
4919
|
+
const constrainedTypeNames = /* @__PURE__ */ new Set();
|
|
4920
|
+
const reshapedSchemaNames = /* @__PURE__ */ new Set();
|
|
4921
|
+
function zodCallChain(node) {
|
|
4922
|
+
const chain = [];
|
|
4923
|
+
let current = node;
|
|
4924
|
+
while (current.type === AST_NODE_TYPES19.CallExpression) {
|
|
4925
|
+
const callee = current.callee;
|
|
4926
|
+
if (callee.type !== AST_NODE_TYPES19.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES19.Identifier) {
|
|
4927
|
+
return null;
|
|
4928
|
+
}
|
|
4929
|
+
chain.push(current);
|
|
4930
|
+
const receiver = callee.object;
|
|
4931
|
+
if (receiver.type === AST_NODE_TYPES19.Identifier) {
|
|
4932
|
+
return zodNamespaces.has(receiver.name) ? chain.reverse() : null;
|
|
4933
|
+
}
|
|
4934
|
+
current = receiver;
|
|
4935
|
+
}
|
|
4936
|
+
return null;
|
|
4937
|
+
}
|
|
4938
|
+
function methodName(call) {
|
|
4939
|
+
const callee = call.callee;
|
|
4940
|
+
return callee.type === AST_NODE_TYPES19.MemberExpression && callee.property.type === AST_NODE_TYPES19.Identifier ? callee.property.name : "";
|
|
4941
|
+
}
|
|
4942
|
+
function schemaField(node) {
|
|
4943
|
+
const modifiers = [];
|
|
4944
|
+
let current = node;
|
|
4945
|
+
let leaf = null;
|
|
4946
|
+
while (current.type === AST_NODE_TYPES19.CallExpression) {
|
|
4947
|
+
const callee = current.callee;
|
|
4948
|
+
if (callee.type !== AST_NODE_TYPES19.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES19.Identifier) {
|
|
4949
|
+
break;
|
|
4950
|
+
}
|
|
4951
|
+
const receiver = callee.object;
|
|
4952
|
+
if (receiver.type === AST_NODE_TYPES19.Identifier && zodNamespaces.has(receiver.name)) {
|
|
4953
|
+
leaf = callee.property.name;
|
|
4954
|
+
break;
|
|
4955
|
+
}
|
|
4956
|
+
modifiers.push(callee.property.name);
|
|
4957
|
+
current = receiver;
|
|
4958
|
+
}
|
|
4959
|
+
return {
|
|
4960
|
+
leaf,
|
|
4961
|
+
optional: modifiers.some((name) => OPTIONAL_MODIFIERS.has(name)),
|
|
4962
|
+
nullable: modifiers.some((name) => NULLABLE_MODIFIERS.has(name)),
|
|
4963
|
+
reshaped: modifiers.some((name) => RESHAPING_MODIFIERS.has(name))
|
|
4964
|
+
};
|
|
4965
|
+
}
|
|
4966
|
+
function schemaFields(init) {
|
|
4967
|
+
const chain = zodCallChain(init);
|
|
4968
|
+
if (chain === null || chain.length === 0) {
|
|
4969
|
+
return null;
|
|
4970
|
+
}
|
|
4971
|
+
const [base, ...rest] = chain;
|
|
4972
|
+
if (base === void 0) {
|
|
4973
|
+
return null;
|
|
4974
|
+
}
|
|
4975
|
+
const baseMethod = methodName(base);
|
|
4976
|
+
if (baseMethod !== "object" && baseMethod !== "strictObject") {
|
|
4977
|
+
return null;
|
|
4978
|
+
}
|
|
4979
|
+
if (rest.some((call) => !SHAPE_PRESERVING_METHODS.has(methodName(call)))) {
|
|
4980
|
+
return null;
|
|
4981
|
+
}
|
|
4982
|
+
const shape = base.arguments[0];
|
|
4983
|
+
if (shape === void 0 || shape.type !== AST_NODE_TYPES19.ObjectExpression) {
|
|
4984
|
+
return null;
|
|
4985
|
+
}
|
|
4986
|
+
const fields = /* @__PURE__ */ new Map();
|
|
4987
|
+
for (const property of shape.properties) {
|
|
4988
|
+
if (property.type !== AST_NODE_TYPES19.Property || property.computed) {
|
|
4989
|
+
return null;
|
|
4990
|
+
}
|
|
4991
|
+
const { key } = property;
|
|
4992
|
+
const name = key.type === AST_NODE_TYPES19.Identifier ? key.name : key.type === AST_NODE_TYPES19.Literal && typeof key.value === "string" ? key.value : null;
|
|
4993
|
+
if (name === null) {
|
|
4994
|
+
return null;
|
|
4995
|
+
}
|
|
4996
|
+
fields.set(name, schemaField(property.value));
|
|
4997
|
+
}
|
|
4998
|
+
return fields.size === 0 ? null : fields;
|
|
4999
|
+
}
|
|
5000
|
+
function typeMembers(members) {
|
|
5001
|
+
const result = /* @__PURE__ */ new Map();
|
|
5002
|
+
for (const member of members) {
|
|
5003
|
+
if (member.type !== AST_NODE_TYPES19.TSPropertySignature || member.computed) {
|
|
5004
|
+
return null;
|
|
5005
|
+
}
|
|
5006
|
+
const { key } = member;
|
|
5007
|
+
const name = key.type === AST_NODE_TYPES19.Identifier ? key.name : key.type === AST_NODE_TYPES19.Literal && typeof key.value === "string" ? key.value : null;
|
|
5008
|
+
if (name === null) {
|
|
5009
|
+
return null;
|
|
5010
|
+
}
|
|
5011
|
+
const annotation = member.typeAnnotation?.typeAnnotation ?? null;
|
|
5012
|
+
result.set(name, {
|
|
5013
|
+
optional: member.optional === true,
|
|
5014
|
+
nullable: annotation !== null && unwrapNullish(annotation).nullable,
|
|
5015
|
+
annotation
|
|
5016
|
+
});
|
|
5017
|
+
}
|
|
5018
|
+
return result.size === 0 ? null : result;
|
|
5019
|
+
}
|
|
5020
|
+
function collectConstrainedNames(node) {
|
|
5021
|
+
if (node.type === AST_NODE_TYPES19.TSTypeReference) {
|
|
5022
|
+
if (node.typeName.type === AST_NODE_TYPES19.Identifier) {
|
|
5023
|
+
constrainedTypeNames.add(node.typeName.name);
|
|
5024
|
+
}
|
|
5025
|
+
for (const argument of node.typeArguments?.params ?? []) {
|
|
5026
|
+
collectConstrainedNames(argument);
|
|
5027
|
+
}
|
|
5028
|
+
return;
|
|
5029
|
+
}
|
|
5030
|
+
if (node.type === AST_NODE_TYPES19.TSArrayType) {
|
|
5031
|
+
collectConstrainedNames(node.elementType);
|
|
5032
|
+
return;
|
|
5033
|
+
}
|
|
5034
|
+
if (node.type === AST_NODE_TYPES19.TSUnionType || node.type === AST_NODE_TYPES19.TSIntersectionType) {
|
|
5035
|
+
for (const member of node.types) {
|
|
5036
|
+
collectConstrainedNames(member);
|
|
5037
|
+
}
|
|
5038
|
+
}
|
|
5039
|
+
}
|
|
5040
|
+
function isTwin(fields, members) {
|
|
5041
|
+
if (!requireIdenticalShape) {
|
|
5042
|
+
return true;
|
|
5043
|
+
}
|
|
5044
|
+
if (fields.size !== members.size) {
|
|
5045
|
+
return false;
|
|
5046
|
+
}
|
|
5047
|
+
let agreements = 0;
|
|
5048
|
+
for (const [name, field] of fields) {
|
|
5049
|
+
const member = members.get(name);
|
|
5050
|
+
if (member === void 0) {
|
|
5051
|
+
return false;
|
|
5052
|
+
}
|
|
5053
|
+
if (field.reshaped) {
|
|
5054
|
+
return false;
|
|
5055
|
+
}
|
|
5056
|
+
if (field.optional !== member.optional) {
|
|
5057
|
+
return false;
|
|
5058
|
+
}
|
|
5059
|
+
if (field.nullable !== member.nullable) {
|
|
5060
|
+
return false;
|
|
5061
|
+
}
|
|
5062
|
+
const agrees = leafAgrees(field.leaf, member.annotation);
|
|
5063
|
+
if (agrees === false) {
|
|
5064
|
+
return false;
|
|
5065
|
+
}
|
|
5066
|
+
if (agrees === true) {
|
|
5067
|
+
agreements += 1;
|
|
5068
|
+
}
|
|
5069
|
+
}
|
|
5070
|
+
return agreements > 0;
|
|
5071
|
+
}
|
|
5072
|
+
return {
|
|
5073
|
+
ImportDeclaration(node) {
|
|
5074
|
+
if (!isZodModule(node.source.value)) {
|
|
5075
|
+
return;
|
|
5076
|
+
}
|
|
5077
|
+
for (const specifier of node.specifiers) {
|
|
5078
|
+
if (specifier.type === AST_NODE_TYPES19.ImportNamespaceSpecifier || specifier.type === AST_NODE_TYPES19.ImportDefaultSpecifier || specifier.type === AST_NODE_TYPES19.ImportSpecifier && specifier.imported.type === AST_NODE_TYPES19.Identifier && specifier.imported.name === "z") {
|
|
5079
|
+
zodNamespaces.add(specifier.local.name);
|
|
5080
|
+
}
|
|
5081
|
+
}
|
|
5082
|
+
},
|
|
5083
|
+
VariableDeclarator(node) {
|
|
5084
|
+
if (node.id.type !== AST_NODE_TYPES19.Identifier || node.init == null) {
|
|
5085
|
+
return;
|
|
5086
|
+
}
|
|
5087
|
+
const fields = schemaFields(node.init);
|
|
5088
|
+
if (fields !== null) {
|
|
5089
|
+
schemas.push({ name: node.id.name, fields });
|
|
5090
|
+
}
|
|
5091
|
+
},
|
|
5092
|
+
/** Guard (f): `XSchema.transform(...)` anywhere in the module. */
|
|
5093
|
+
"MemberExpression[computed=false]"(node) {
|
|
5094
|
+
if (node.object.type === AST_NODE_TYPES19.Identifier && node.property.type === AST_NODE_TYPES19.Identifier && MODULE_LEVEL_RESHAPERS.has(node.property.name)) {
|
|
5095
|
+
reshapedSchemaNames.add(node.object.name);
|
|
5096
|
+
}
|
|
5097
|
+
},
|
|
5098
|
+
/** Guard (c): `z.ZodType<T>` and every other type argument it carries. */
|
|
5099
|
+
TSTypeReference(node) {
|
|
5100
|
+
const { typeName } = node;
|
|
5101
|
+
const referenced = typeName.type === AST_NODE_TYPES19.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES19.TSQualifiedName && typeName.right.type === AST_NODE_TYPES19.Identifier ? typeName.right.name : null;
|
|
5102
|
+
if (referenced === null || !ZOD_TYPE_CONSTRAINTS.has(referenced)) {
|
|
5103
|
+
return;
|
|
5104
|
+
}
|
|
5105
|
+
for (const argument of node.typeArguments?.params ?? []) {
|
|
5106
|
+
collectConstrainedNames(argument);
|
|
5107
|
+
}
|
|
5108
|
+
},
|
|
5109
|
+
TSInterfaceDeclaration(node) {
|
|
5110
|
+
if (node.typeParameters !== void 0 || (node.extends?.length ?? 0) > 0) {
|
|
5111
|
+
return;
|
|
5112
|
+
}
|
|
5113
|
+
const members = typeMembers(node.body.body);
|
|
5114
|
+
if (members !== null) {
|
|
5115
|
+
typeDeclarations.push({ name: node.id.name, node: node.id, members });
|
|
5116
|
+
}
|
|
5117
|
+
},
|
|
5118
|
+
TSTypeAliasDeclaration(node) {
|
|
5119
|
+
if (node.typeParameters !== void 0 || node.typeAnnotation.type !== AST_NODE_TYPES19.TSTypeLiteral) {
|
|
5120
|
+
return;
|
|
5121
|
+
}
|
|
5122
|
+
const members = typeMembers(node.typeAnnotation.members);
|
|
5123
|
+
if (members !== null) {
|
|
5124
|
+
typeDeclarations.push({ name: node.id.name, node: node.id, members });
|
|
5125
|
+
}
|
|
5126
|
+
},
|
|
5127
|
+
"Program:exit"() {
|
|
5128
|
+
if (schemas.length === 0 || typeDeclarations.length === 0) {
|
|
5129
|
+
return;
|
|
5130
|
+
}
|
|
5131
|
+
const byName = /* @__PURE__ */ new Map();
|
|
5132
|
+
for (const schema of schemas) {
|
|
5133
|
+
const key = normalizeSchemaName(schema.name);
|
|
5134
|
+
if (key !== "" && !byName.has(key)) {
|
|
5135
|
+
byName.set(key, schema);
|
|
5136
|
+
}
|
|
5137
|
+
}
|
|
5138
|
+
for (const declaration of typeDeclarations) {
|
|
5139
|
+
if (constrainedTypeNames.has(declaration.name)) {
|
|
5140
|
+
continue;
|
|
5141
|
+
}
|
|
5142
|
+
if (ignorePatterns.some((pattern) => pattern.test(declaration.name))) {
|
|
5143
|
+
continue;
|
|
5144
|
+
}
|
|
5145
|
+
const schema = byName.get(normalizeTypeName(declaration.name));
|
|
5146
|
+
if (schema === void 0 || reshapedSchemaNames.has(schema.name)) {
|
|
5147
|
+
continue;
|
|
5148
|
+
}
|
|
5149
|
+
if (!isTwin(schema.fields, declaration.members)) {
|
|
5150
|
+
continue;
|
|
5151
|
+
}
|
|
5152
|
+
context.report({
|
|
5153
|
+
node: declaration.node,
|
|
5154
|
+
messageId: "handWrittenTwin",
|
|
5155
|
+
data: { typeName: declaration.name, schemaName: schema.name }
|
|
5156
|
+
});
|
|
5157
|
+
}
|
|
5158
|
+
}
|
|
5159
|
+
};
|
|
5160
|
+
}
|
|
5161
|
+
});
|
|
5162
|
+
|
|
4757
5163
|
// src/rules/no-offset-pagination.ts
|
|
4758
|
-
import { ESLintUtils as
|
|
5164
|
+
import { ESLintUtils as ESLintUtils29 } from "@typescript-eslint/utils";
|
|
4759
5165
|
|
|
4760
5166
|
// src/rules/_sql.ts
|
|
4761
|
-
import { AST_NODE_TYPES as
|
|
5167
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES20 } from "@typescript-eslint/utils";
|
|
4762
5168
|
function stripSqlNoise(text) {
|
|
4763
5169
|
const out = [...text];
|
|
4764
5170
|
const n = text.length;
|
|
@@ -4819,13 +5225,13 @@ function stripSqlNoise(text) {
|
|
|
4819
5225
|
var SUBSTITUTION_MARKER = "?";
|
|
4820
5226
|
function sqlTextOf(node) {
|
|
4821
5227
|
switch (node.type) {
|
|
4822
|
-
case
|
|
5228
|
+
case AST_NODE_TYPES20.Literal:
|
|
4823
5229
|
return typeof node.value === "string" ? node.value : null;
|
|
4824
|
-
case
|
|
5230
|
+
case AST_NODE_TYPES20.TemplateLiteral:
|
|
4825
5231
|
return node.quasis.map((q) => q.value.cooked ?? q.value.raw).join(SUBSTITUTION_MARKER);
|
|
4826
|
-
case
|
|
5232
|
+
case AST_NODE_TYPES20.TaggedTemplateExpression:
|
|
4827
5233
|
return sqlTextOf(node.quasi);
|
|
4828
|
-
case
|
|
5234
|
+
case AST_NODE_TYPES20.BinaryExpression: {
|
|
4829
5235
|
if (node.operator !== "+") {
|
|
4830
5236
|
return null;
|
|
4831
5237
|
}
|
|
@@ -4833,7 +5239,7 @@ function sqlTextOf(node) {
|
|
|
4833
5239
|
const right = sqlTextOf(node.right);
|
|
4834
5240
|
return left !== null && right !== null ? left + right : null;
|
|
4835
5241
|
}
|
|
4836
|
-
case
|
|
5242
|
+
case AST_NODE_TYPES20.ArrayExpression: {
|
|
4837
5243
|
const parts = [];
|
|
4838
5244
|
for (const element of node.elements) {
|
|
4839
5245
|
if (element === null) {
|
|
@@ -4853,7 +5259,7 @@ function sqlTextOf(node) {
|
|
|
4853
5259
|
}
|
|
4854
5260
|
function isJoinedFragmentArray(node) {
|
|
4855
5261
|
const parent = node.parent;
|
|
4856
|
-
return parent?.type ===
|
|
5262
|
+
return parent?.type === AST_NODE_TYPES20.MemberExpression && parent.object === node && !parent.computed && parent.property.type === AST_NODE_TYPES20.Identifier && parent.property.name === "join" && parent.parent?.type === AST_NODE_TYPES20.CallExpression;
|
|
4857
5263
|
}
|
|
4858
5264
|
function markConsumed(node, consumed) {
|
|
4859
5265
|
consumed.add(node);
|
|
@@ -4903,7 +5309,7 @@ function createSqlListener(handler) {
|
|
|
4903
5309
|
// src/rules/no-offset-pagination.ts
|
|
4904
5310
|
var OFFSET_PAGINATION = /\bOFFSET\s+(?:%s|%\(\w+\)s|\?\d*|:\w+|@\w+|\$\d+|\d+)/i;
|
|
4905
5311
|
var OFFSET_GATE = /offset/i;
|
|
4906
|
-
var no_offset_pagination_default =
|
|
5312
|
+
var no_offset_pagination_default = ESLintUtils29.RuleCreator(
|
|
4907
5313
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
4908
5314
|
)({
|
|
4909
5315
|
name: "no-offset-pagination",
|
|
@@ -4932,15 +5338,15 @@ var no_offset_pagination_default = ESLintUtils28.RuleCreator(
|
|
|
4932
5338
|
});
|
|
4933
5339
|
|
|
4934
5340
|
// src/rules/no-positional-tuple-return.ts
|
|
4935
|
-
import { AST_NODE_TYPES as
|
|
5341
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES21, ESLintUtils as ESLintUtils30 } from "@typescript-eslint/utils";
|
|
4936
5342
|
var MIN_ELEMENTS = 2;
|
|
4937
5343
|
var ACCESSOR_PAIR_LENGTH = 2;
|
|
4938
5344
|
var AWAITABLE_TYPES = /* @__PURE__ */ new Set(["Promise", "PromiseLike", "Awaited"]);
|
|
4939
5345
|
function tupleReturnType(node) {
|
|
4940
|
-
if (node.type ===
|
|
5346
|
+
if (node.type === AST_NODE_TYPES21.TSTupleType) {
|
|
4941
5347
|
return node;
|
|
4942
5348
|
}
|
|
4943
|
-
if (node.type ===
|
|
5349
|
+
if (node.type === AST_NODE_TYPES21.TSTypeReference && node.typeName.type === AST_NODE_TYPES21.Identifier && AWAITABLE_TYPES.has(node.typeName.name)) {
|
|
4944
5350
|
const argument = node.typeArguments?.params[0];
|
|
4945
5351
|
return argument === void 0 ? null : tupleReturnType(argument);
|
|
4946
5352
|
}
|
|
@@ -4954,30 +5360,30 @@ function isPermittedTuple(tuple, sourceCode) {
|
|
|
4954
5360
|
if (elements.length < MIN_ELEMENTS) {
|
|
4955
5361
|
return true;
|
|
4956
5362
|
}
|
|
4957
|
-
if (elements.some((element) => element.type ===
|
|
5363
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES21.TSRestType)) {
|
|
4958
5364
|
return true;
|
|
4959
5365
|
}
|
|
4960
|
-
if (elements.some((element) => element.type ===
|
|
5366
|
+
if (elements.some((element) => element.type === AST_NODE_TYPES21.TSNamedTupleMember)) {
|
|
4961
5367
|
return true;
|
|
4962
5368
|
}
|
|
4963
|
-
if (elements[0]?.type ===
|
|
5369
|
+
if (elements[0]?.type === AST_NODE_TYPES21.TSLiteralType) {
|
|
4964
5370
|
return true;
|
|
4965
5371
|
}
|
|
4966
|
-
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type ===
|
|
5372
|
+
if (elements.length === ACCESSOR_PAIR_LENGTH && elements.some((element) => element.type === AST_NODE_TYPES21.TSFunctionType)) {
|
|
4967
5373
|
return true;
|
|
4968
5374
|
}
|
|
4969
5375
|
const texts = new Set(elements.map((element) => normalizedText(sourceCode, element)));
|
|
4970
5376
|
return texts.size === 1;
|
|
4971
5377
|
}
|
|
4972
5378
|
function functionName(node) {
|
|
4973
|
-
if (node.type ===
|
|
5379
|
+
if (node.type === AST_NODE_TYPES21.FunctionDeclaration) {
|
|
4974
5380
|
return node.id?.name ?? null;
|
|
4975
5381
|
}
|
|
4976
5382
|
const parent = node.parent;
|
|
4977
|
-
if (parent?.type ===
|
|
5383
|
+
if (parent?.type === AST_NODE_TYPES21.VariableDeclarator && parent.id.type === AST_NODE_TYPES21.Identifier) {
|
|
4978
5384
|
return parent.id.name;
|
|
4979
5385
|
}
|
|
4980
|
-
if ((parent?.type ===
|
|
5386
|
+
if ((parent?.type === AST_NODE_TYPES21.MethodDefinition || parent?.type === AST_NODE_TYPES21.PropertyDefinition || parent?.type === AST_NODE_TYPES21.Property) && parent.key.type === AST_NODE_TYPES21.Identifier) {
|
|
4981
5387
|
return parent.key.name;
|
|
4982
5388
|
}
|
|
4983
5389
|
return null;
|
|
@@ -4985,7 +5391,7 @@ function functionName(node) {
|
|
|
4985
5391
|
function isInlineExported(node) {
|
|
4986
5392
|
for (let current = node; current != null; current = current.parent) {
|
|
4987
5393
|
const parent = current.parent;
|
|
4988
|
-
if (parent?.type ===
|
|
5394
|
+
if (parent?.type === AST_NODE_TYPES21.ExportNamedDeclaration || parent?.type === AST_NODE_TYPES21.ExportDefaultDeclaration) {
|
|
4989
5395
|
return true;
|
|
4990
5396
|
}
|
|
4991
5397
|
}
|
|
@@ -4994,18 +5400,18 @@ function isInlineExported(node) {
|
|
|
4994
5400
|
function moduleScopeBindingName(node) {
|
|
4995
5401
|
let current = node;
|
|
4996
5402
|
let child = node;
|
|
4997
|
-
while (current.parent != null && current.parent.type !==
|
|
5403
|
+
while (current.parent != null && current.parent.type !== AST_NODE_TYPES21.Program) {
|
|
4998
5404
|
child = current;
|
|
4999
5405
|
current = current.parent;
|
|
5000
5406
|
}
|
|
5001
|
-
if (current.parent?.type !==
|
|
5407
|
+
if (current.parent?.type !== AST_NODE_TYPES21.Program) {
|
|
5002
5408
|
return null;
|
|
5003
5409
|
}
|
|
5004
|
-
if (current.type ===
|
|
5410
|
+
if (current.type === AST_NODE_TYPES21.FunctionDeclaration || current.type === AST_NODE_TYPES21.ClassDeclaration) {
|
|
5005
5411
|
return current.id?.name ?? null;
|
|
5006
5412
|
}
|
|
5007
|
-
if (current.type ===
|
|
5008
|
-
if (child.type !==
|
|
5413
|
+
if (current.type === AST_NODE_TYPES21.VariableDeclaration) {
|
|
5414
|
+
if (child.type !== AST_NODE_TYPES21.VariableDeclarator || child.id.type !== AST_NODE_TYPES21.Identifier) {
|
|
5009
5415
|
return null;
|
|
5010
5416
|
}
|
|
5011
5417
|
return child.id.name;
|
|
@@ -5015,19 +5421,19 @@ function moduleScopeBindingName(node) {
|
|
|
5015
5421
|
function specifierExportedNames(program) {
|
|
5016
5422
|
const names = /* @__PURE__ */ new Set();
|
|
5017
5423
|
for (const statement of program.body) {
|
|
5018
|
-
if (statement.type ===
|
|
5424
|
+
if (statement.type === AST_NODE_TYPES21.ExportNamedDeclaration && statement.declaration == null && statement.source == null && statement.exportKind !== "type") {
|
|
5019
5425
|
for (const specifier of statement.specifiers) {
|
|
5020
|
-
if (specifier.exportKind !== "type" && specifier.local.type ===
|
|
5426
|
+
if (specifier.exportKind !== "type" && specifier.local.type === AST_NODE_TYPES21.Identifier) {
|
|
5021
5427
|
names.add(specifier.local.name);
|
|
5022
5428
|
}
|
|
5023
5429
|
}
|
|
5024
5430
|
continue;
|
|
5025
5431
|
}
|
|
5026
|
-
if (statement.type ===
|
|
5432
|
+
if (statement.type === AST_NODE_TYPES21.ExportDefaultDeclaration && statement.declaration.type === AST_NODE_TYPES21.Identifier) {
|
|
5027
5433
|
names.add(statement.declaration.name);
|
|
5028
5434
|
continue;
|
|
5029
5435
|
}
|
|
5030
|
-
if (statement.type ===
|
|
5436
|
+
if (statement.type === AST_NODE_TYPES21.TSExportAssignment && statement.expression.type === AST_NODE_TYPES21.Identifier) {
|
|
5031
5437
|
names.add(statement.expression.name);
|
|
5032
5438
|
}
|
|
5033
5439
|
}
|
|
@@ -5043,7 +5449,7 @@ function isExported(node, specifierExports) {
|
|
|
5043
5449
|
const binding = moduleScopeBindingName(node);
|
|
5044
5450
|
return binding !== null && specifierExports.has(binding);
|
|
5045
5451
|
}
|
|
5046
|
-
var no_positional_tuple_return_default =
|
|
5452
|
+
var no_positional_tuple_return_default = ESLintUtils30.RuleCreator(
|
|
5047
5453
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5048
5454
|
)({
|
|
5049
5455
|
name: "no-positional-tuple-return",
|
|
@@ -5091,16 +5497,16 @@ var no_positional_tuple_return_default = ESLintUtils29.RuleCreator(
|
|
|
5091
5497
|
});
|
|
5092
5498
|
|
|
5093
5499
|
// src/rules/no-repeated-string-literal.ts
|
|
5094
|
-
import { AST_NODE_TYPES as
|
|
5500
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES22, ESLintUtils as ESLintUtils31 } from "@typescript-eslint/utils";
|
|
5095
5501
|
var MIN_LENGTH = 40;
|
|
5096
5502
|
var MIN_DISTINCT_SCOPES = 2;
|
|
5097
5503
|
var PREVIEW_LENGTH = 40;
|
|
5098
5504
|
var SQL_KEYWORD_RE = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|JOIN|VALUES|ON CONFLICT|RETURNING|GROUP BY|ORDER BY)\b/;
|
|
5099
5505
|
var IDENTIFIER_RE = /^[a-z_][a-z0-9_.]*$/;
|
|
5100
5506
|
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5507
|
+
AST_NODE_TYPES22.FunctionDeclaration,
|
|
5508
|
+
AST_NODE_TYPES22.FunctionExpression,
|
|
5509
|
+
AST_NODE_TYPES22.ArrowFunctionExpression
|
|
5104
5510
|
]);
|
|
5105
5511
|
function isStructured(value) {
|
|
5106
5512
|
return value.includes("\n") || SQL_KEYWORD_RE.test(value) || IDENTIFIER_RE.test(value);
|
|
@@ -5122,9 +5528,9 @@ function isScaffolding(node) {
|
|
|
5122
5528
|
if (parent === void 0) {
|
|
5123
5529
|
return true;
|
|
5124
5530
|
}
|
|
5125
|
-
return parent.type ===
|
|
5531
|
+
return parent.type === AST_NODE_TYPES22.ImportDeclaration || parent.type === AST_NODE_TYPES22.ExportNamedDeclaration || parent.type === AST_NODE_TYPES22.ExportAllDeclaration || parent.type === AST_NODE_TYPES22.TSImportType || parent.type === AST_NODE_TYPES22.JSXAttribute || parent.type === AST_NODE_TYPES22.TSLiteralType;
|
|
5126
5532
|
}
|
|
5127
|
-
var no_repeated_string_literal_default =
|
|
5533
|
+
var no_repeated_string_literal_default = ESLintUtils31.RuleCreator(
|
|
5128
5534
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5129
5535
|
)({
|
|
5130
5536
|
name: "no-repeated-string-literal",
|
|
@@ -5164,7 +5570,7 @@ var no_repeated_string_literal_default = ESLintUtils30.RuleCreator(
|
|
|
5164
5570
|
}
|
|
5165
5571
|
},
|
|
5166
5572
|
TemplateLiteral(node) {
|
|
5167
|
-
if (node.parent.type ===
|
|
5573
|
+
if (node.parent.type === AST_NODE_TYPES22.TaggedTemplateExpression) {
|
|
5168
5574
|
return;
|
|
5169
5575
|
}
|
|
5170
5576
|
const [only] = node.quasis;
|
|
@@ -5198,7 +5604,7 @@ var no_repeated_string_literal_default = ESLintUtils30.RuleCreator(
|
|
|
5198
5604
|
});
|
|
5199
5605
|
|
|
5200
5606
|
// src/rules/no-select-star.ts
|
|
5201
|
-
import { ESLintUtils as
|
|
5607
|
+
import { ESLintUtils as ESLintUtils32 } from "@typescript-eslint/utils";
|
|
5202
5608
|
var QUERY_SHAPE = /\bSELECT\b[\s\S]*?\bFROM\b/i;
|
|
5203
5609
|
var SELECT_KEYWORD = /\bSELECT\b/gi;
|
|
5204
5610
|
var FROM_KEYWORD = /^FROM\b/i;
|
|
@@ -5238,7 +5644,7 @@ function hasRealSelectStar(sql) {
|
|
|
5238
5644
|
}
|
|
5239
5645
|
return false;
|
|
5240
5646
|
}
|
|
5241
|
-
var no_select_star_default =
|
|
5647
|
+
var no_select_star_default = ESLintUtils32.RuleCreator(
|
|
5242
5648
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5243
5649
|
)({
|
|
5244
5650
|
name: "no-select-star",
|
|
@@ -5267,7 +5673,7 @@ var no_select_star_default = ESLintUtils31.RuleCreator(
|
|
|
5267
5673
|
});
|
|
5268
5674
|
|
|
5269
5675
|
// src/rules/no-sleep-in-test-body.ts
|
|
5270
|
-
import { AST_NODE_TYPES as
|
|
5676
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES23, ESLintUtils as ESLintUtils33 } from "@typescript-eslint/utils";
|
|
5271
5677
|
var SLEEP_HELPERS = /* @__PURE__ */ new Set(["sleep", "delay", "wait", "pause"]);
|
|
5272
5678
|
var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
5273
5679
|
"it",
|
|
@@ -5276,34 +5682,34 @@ var TEST_CALLERS = /* @__PURE__ */ new Set([
|
|
|
5276
5682
|
"afterEach"
|
|
5277
5683
|
]);
|
|
5278
5684
|
var FUNCTION_TYPES2 = /* @__PURE__ */ new Set([
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5685
|
+
AST_NODE_TYPES23.FunctionDeclaration,
|
|
5686
|
+
AST_NODE_TYPES23.FunctionExpression,
|
|
5687
|
+
AST_NODE_TYPES23.ArrowFunctionExpression
|
|
5282
5688
|
]);
|
|
5283
5689
|
function isNonzeroNumericLiteral(node) {
|
|
5284
|
-
return node?.type ===
|
|
5690
|
+
return node?.type === AST_NODE_TYPES23.Literal && typeof node.value === "number" && node.value !== 0;
|
|
5285
5691
|
}
|
|
5286
5692
|
function isTimedSetTimeout(node) {
|
|
5287
|
-
return node.type ===
|
|
5693
|
+
return node.type === AST_NODE_TYPES23.CallExpression && node.callee.type === AST_NODE_TYPES23.Identifier && node.callee.name === "setTimeout" && node.arguments.length >= 2 && isNonzeroNumericLiteral(node.arguments[1]);
|
|
5288
5694
|
}
|
|
5289
5695
|
function isPromiseSleep(node) {
|
|
5290
|
-
if (node.callee.type !==
|
|
5696
|
+
if (node.callee.type !== AST_NODE_TYPES23.Identifier || node.callee.name !== "Promise") {
|
|
5291
5697
|
return false;
|
|
5292
5698
|
}
|
|
5293
5699
|
const executor = node.arguments[0];
|
|
5294
|
-
if (executor?.type !==
|
|
5700
|
+
if (executor?.type !== AST_NODE_TYPES23.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES23.FunctionExpression) {
|
|
5295
5701
|
return false;
|
|
5296
5702
|
}
|
|
5297
5703
|
const body = executor.body;
|
|
5298
|
-
if (body.type !==
|
|
5704
|
+
if (body.type !== AST_NODE_TYPES23.BlockStatement) {
|
|
5299
5705
|
return isTimedSetTimeout(body);
|
|
5300
5706
|
}
|
|
5301
5707
|
return body.body.some(
|
|
5302
|
-
(stmt) => stmt.type ===
|
|
5708
|
+
(stmt) => stmt.type === AST_NODE_TYPES23.ExpressionStatement && isTimedSetTimeout(stmt.expression)
|
|
5303
5709
|
);
|
|
5304
5710
|
}
|
|
5305
5711
|
function isHelperSleep(node) {
|
|
5306
|
-
return node.callee.type ===
|
|
5712
|
+
return node.callee.type === AST_NODE_TYPES23.Identifier && SLEEP_HELPERS.has(node.callee.name) && node.arguments.length >= 1 && isNonzeroNumericLiteral(node.arguments[0]);
|
|
5307
5713
|
}
|
|
5308
5714
|
function nearestEnclosingFunction(node) {
|
|
5309
5715
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5311,7 +5717,7 @@ function nearestEnclosingFunction(node) {
|
|
|
5311
5717
|
continue;
|
|
5312
5718
|
}
|
|
5313
5719
|
const grandparent = current.parent;
|
|
5314
|
-
const isPromiseExecutor = grandparent?.type ===
|
|
5720
|
+
const isPromiseExecutor = grandparent?.type === AST_NODE_TYPES23.NewExpression && isPromiseSleep(grandparent);
|
|
5315
5721
|
if (!isPromiseExecutor) {
|
|
5316
5722
|
return current;
|
|
5317
5723
|
}
|
|
@@ -5319,29 +5725,29 @@ function nearestEnclosingFunction(node) {
|
|
|
5319
5725
|
return null;
|
|
5320
5726
|
}
|
|
5321
5727
|
function testCallerName(callee) {
|
|
5322
|
-
if (callee.type ===
|
|
5728
|
+
if (callee.type === AST_NODE_TYPES23.Identifier) {
|
|
5323
5729
|
return callee.name;
|
|
5324
5730
|
}
|
|
5325
|
-
if (callee.type ===
|
|
5731
|
+
if (callee.type === AST_NODE_TYPES23.MemberExpression) {
|
|
5326
5732
|
return testCallerName(callee.object);
|
|
5327
5733
|
}
|
|
5328
|
-
if (callee.type ===
|
|
5734
|
+
if (callee.type === AST_NODE_TYPES23.CallExpression) {
|
|
5329
5735
|
return testCallerName(callee.callee);
|
|
5330
5736
|
}
|
|
5331
|
-
if (callee.type ===
|
|
5737
|
+
if (callee.type === AST_NODE_TYPES23.TaggedTemplateExpression) {
|
|
5332
5738
|
return testCallerName(callee.tag);
|
|
5333
5739
|
}
|
|
5334
5740
|
return null;
|
|
5335
5741
|
}
|
|
5336
5742
|
function isTestBody(fn) {
|
|
5337
5743
|
const call = fn.parent;
|
|
5338
|
-
if (call?.type !==
|
|
5744
|
+
if (call?.type !== AST_NODE_TYPES23.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5339
5745
|
return false;
|
|
5340
5746
|
}
|
|
5341
5747
|
const name = testCallerName(call.callee);
|
|
5342
5748
|
return name !== null && TEST_CALLERS.has(name);
|
|
5343
5749
|
}
|
|
5344
|
-
var no_sleep_in_test_body_default =
|
|
5750
|
+
var no_sleep_in_test_body_default = ESLintUtils33.RuleCreator(
|
|
5345
5751
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5346
5752
|
)({
|
|
5347
5753
|
name: "no-sleep-in-test-body",
|
|
@@ -5383,12 +5789,12 @@ var no_sleep_in_test_body_default = ESLintUtils32.RuleCreator(
|
|
|
5383
5789
|
});
|
|
5384
5790
|
|
|
5385
5791
|
// src/rules/no-conditional-in-test.ts
|
|
5386
|
-
import { AST_NODE_TYPES as
|
|
5792
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES24, ESLintUtils as ESLintUtils34 } from "@typescript-eslint/utils";
|
|
5387
5793
|
var TEST_CALLERS2 = /* @__PURE__ */ new Set(["it", "test"]);
|
|
5388
5794
|
var FUNCTION_TYPES3 = /* @__PURE__ */ new Set([
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5795
|
+
AST_NODE_TYPES24.FunctionDeclaration,
|
|
5796
|
+
AST_NODE_TYPES24.FunctionExpression,
|
|
5797
|
+
AST_NODE_TYPES24.ArrowFunctionExpression
|
|
5392
5798
|
]);
|
|
5393
5799
|
function nearestEnclosingFunction2(node) {
|
|
5394
5800
|
for (let current = node.parent; current != null; current = current.parent) {
|
|
@@ -5399,29 +5805,29 @@ function nearestEnclosingFunction2(node) {
|
|
|
5399
5805
|
return null;
|
|
5400
5806
|
}
|
|
5401
5807
|
function testCallerName2(callee) {
|
|
5402
|
-
if (callee.type ===
|
|
5808
|
+
if (callee.type === AST_NODE_TYPES24.Identifier) {
|
|
5403
5809
|
return callee.name;
|
|
5404
5810
|
}
|
|
5405
|
-
if (callee.type ===
|
|
5811
|
+
if (callee.type === AST_NODE_TYPES24.MemberExpression) {
|
|
5406
5812
|
return testCallerName2(callee.object);
|
|
5407
5813
|
}
|
|
5408
|
-
if (callee.type ===
|
|
5814
|
+
if (callee.type === AST_NODE_TYPES24.CallExpression) {
|
|
5409
5815
|
return testCallerName2(callee.callee);
|
|
5410
5816
|
}
|
|
5411
|
-
if (callee.type ===
|
|
5817
|
+
if (callee.type === AST_NODE_TYPES24.TaggedTemplateExpression) {
|
|
5412
5818
|
return testCallerName2(callee.tag);
|
|
5413
5819
|
}
|
|
5414
5820
|
return null;
|
|
5415
5821
|
}
|
|
5416
5822
|
function isTestBody2(fn) {
|
|
5417
5823
|
const call = fn.parent;
|
|
5418
|
-
if (call?.type !==
|
|
5824
|
+
if (call?.type !== AST_NODE_TYPES24.CallExpression || !call.arguments.some((argument) => argument === fn)) {
|
|
5419
5825
|
return false;
|
|
5420
5826
|
}
|
|
5421
5827
|
const name = testCallerName2(call.callee);
|
|
5422
5828
|
return name !== null && TEST_CALLERS2.has(name);
|
|
5423
5829
|
}
|
|
5424
|
-
var no_conditional_in_test_default =
|
|
5830
|
+
var no_conditional_in_test_default = ESLintUtils34.RuleCreator(
|
|
5425
5831
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5426
5832
|
)({
|
|
5427
5833
|
name: "no-conditional-in-test",
|
|
@@ -5465,7 +5871,7 @@ var no_conditional_in_test_default = ESLintUtils33.RuleCreator(
|
|
|
5465
5871
|
});
|
|
5466
5872
|
|
|
5467
5873
|
// src/rules/prefer-constant-time-secret-compare.ts
|
|
5468
|
-
import { AST_NODE_TYPES as
|
|
5874
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES25, ESLintUtils as ESLintUtils35 } from "@typescript-eslint/utils";
|
|
5469
5875
|
var EQUALITY_OPERATORS = /* @__PURE__ */ new Set(["===", "!==", "==", "!="]);
|
|
5470
5876
|
var SENTINEL_IDENTIFIERS = /* @__PURE__ */ new Set(["undefined", "NaN"]);
|
|
5471
5877
|
var SENTINEL_WORDS = /(^|_)(SENTINEL|EMPTY|NONE|NULL|UNSET|MISSING|PLACEHOLDER|DUMMY|FAKE|EXAMPLE)(_|$)/;
|
|
@@ -5478,36 +5884,36 @@ function isConstantReference(identifier) {
|
|
|
5478
5884
|
}
|
|
5479
5885
|
function isExcludedOperand(node) {
|
|
5480
5886
|
switch (node.type) {
|
|
5481
|
-
case
|
|
5887
|
+
case AST_NODE_TYPES25.Literal:
|
|
5482
5888
|
return true;
|
|
5483
|
-
case
|
|
5889
|
+
case AST_NODE_TYPES25.TemplateLiteral:
|
|
5484
5890
|
return node.expressions.length === 0;
|
|
5485
|
-
case
|
|
5891
|
+
case AST_NODE_TYPES25.Identifier:
|
|
5486
5892
|
return SENTINEL_IDENTIFIERS.has(node.name) || SENTINEL_PREFIX_RE.test(node.name) || isConstantReference(node.name);
|
|
5487
|
-
case
|
|
5488
|
-
return !node.computed && node.property.type ===
|
|
5893
|
+
case AST_NODE_TYPES25.MemberExpression:
|
|
5894
|
+
return !node.computed && node.property.type === AST_NODE_TYPES25.Identifier && (SENTINEL_PREFIX_RE.test(node.property.name) || isConstantReference(node.property.name));
|
|
5489
5895
|
default:
|
|
5490
5896
|
return false;
|
|
5491
5897
|
}
|
|
5492
5898
|
}
|
|
5493
5899
|
function operandName(node) {
|
|
5494
|
-
if (node.type ===
|
|
5900
|
+
if (node.type === AST_NODE_TYPES25.Identifier) {
|
|
5495
5901
|
return node.name;
|
|
5496
5902
|
}
|
|
5497
|
-
if (node.type ===
|
|
5903
|
+
if (node.type === AST_NODE_TYPES25.MemberExpression && !node.computed && node.property.type === AST_NODE_TYPES25.Identifier) {
|
|
5498
5904
|
return node.property.name;
|
|
5499
5905
|
}
|
|
5500
5906
|
return null;
|
|
5501
5907
|
}
|
|
5502
5908
|
function isSecretOperand(node) {
|
|
5503
|
-
if (node.type ===
|
|
5909
|
+
if (node.type === AST_NODE_TYPES25.TemplateLiteral) {
|
|
5504
5910
|
return node.expressions.some((expression) => isSecretOperand(expression));
|
|
5505
5911
|
}
|
|
5506
5912
|
const name = operandName(node);
|
|
5507
5913
|
return name !== null && isAuthSecretName(name);
|
|
5508
5914
|
}
|
|
5509
5915
|
function secretNameOf(node) {
|
|
5510
|
-
if (node.type ===
|
|
5916
|
+
if (node.type === AST_NODE_TYPES25.TemplateLiteral) {
|
|
5511
5917
|
for (const expression of node.expressions) {
|
|
5512
5918
|
const nested = secretNameOf(expression);
|
|
5513
5919
|
if (nested !== null) {
|
|
@@ -5518,7 +5924,7 @@ function secretNameOf(node) {
|
|
|
5518
5924
|
}
|
|
5519
5925
|
return operandName(node);
|
|
5520
5926
|
}
|
|
5521
|
-
var prefer_constant_time_secret_compare_default =
|
|
5927
|
+
var prefer_constant_time_secret_compare_default = ESLintUtils35.RuleCreator(
|
|
5522
5928
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5523
5929
|
)({
|
|
5524
5930
|
name: "prefer-constant-time-secret-compare",
|
|
@@ -5561,11 +5967,11 @@ var prefer_constant_time_secret_compare_default = ESLintUtils34.RuleCreator(
|
|
|
5561
5967
|
});
|
|
5562
5968
|
|
|
5563
5969
|
// src/rules/store-insert-requires-on-conflict.ts
|
|
5564
|
-
import { ESLintUtils as
|
|
5970
|
+
import { ESLintUtils as ESLintUtils36 } from "@typescript-eslint/utils";
|
|
5565
5971
|
var INSERT_WRITE = /\bINSERT\s+(?:OR\s+\w+\s+)?INTO\s+[\w."'`?$:@-]+\s*(?:\([^)]*\)\s*)?(?:VALUES|SELECT|DEFAULT\s+VALUES)\b/i;
|
|
5566
5972
|
var CONFLICT_HANDLED = /\bON\s+CONFLICT\b|\bON\s+DUPLICATE\s+KEY\b|\bINSERT\s+OR\s+(?:IGNORE|REPLACE)\b/i;
|
|
5567
5973
|
var INSERT_GATE = /insert/i;
|
|
5568
|
-
var store_insert_requires_on_conflict_default =
|
|
5974
|
+
var store_insert_requires_on_conflict_default = ESLintUtils36.RuleCreator(
|
|
5569
5975
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5570
5976
|
)({
|
|
5571
5977
|
name: "store-insert-requires-on-conflict",
|
|
@@ -5594,17 +6000,17 @@ var store_insert_requires_on_conflict_default = ESLintUtils35.RuleCreator(
|
|
|
5594
6000
|
});
|
|
5595
6001
|
|
|
5596
6002
|
// src/rules/no-dynamic-sql.ts
|
|
5597
|
-
import { AST_NODE_TYPES as
|
|
6003
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES26, ESLintUtils as ESLintUtils37 } from "@typescript-eslint/utils";
|
|
5598
6004
|
var DEFAULT_METHODS = ["prepare", "exec", "query"];
|
|
5599
6005
|
var CONSTANT_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
5600
6006
|
function isStaticFragment(expression) {
|
|
5601
|
-
if (expression.type ===
|
|
6007
|
+
if (expression.type === AST_NODE_TYPES26.Identifier) {
|
|
5602
6008
|
return CONSTANT_CASE_RE.test(expression.name);
|
|
5603
6009
|
}
|
|
5604
|
-
if (expression.type ===
|
|
6010
|
+
if (expression.type === AST_NODE_TYPES26.MemberExpression && !expression.computed && expression.property.type === AST_NODE_TYPES26.Identifier) {
|
|
5605
6011
|
return CONSTANT_CASE_RE.test(expression.property.name);
|
|
5606
6012
|
}
|
|
5607
|
-
if (expression.type ===
|
|
6013
|
+
if (expression.type === AST_NODE_TYPES26.Literal) {
|
|
5608
6014
|
return typeof expression.value === "string";
|
|
5609
6015
|
}
|
|
5610
6016
|
return false;
|
|
@@ -5615,36 +6021,36 @@ function runtimeInterpolations(template) {
|
|
|
5615
6021
|
);
|
|
5616
6022
|
}
|
|
5617
6023
|
function concatOperands(node) {
|
|
5618
|
-
if (node.type ===
|
|
6024
|
+
if (node.type === AST_NODE_TYPES26.BinaryExpression && node.operator === "+") {
|
|
5619
6025
|
return [...concatOperands(node.left), ...concatOperands(node.right)];
|
|
5620
6026
|
}
|
|
5621
6027
|
return [node];
|
|
5622
6028
|
}
|
|
5623
6029
|
function runtimeConcatOperands(node) {
|
|
5624
|
-
if (node.type !==
|
|
6030
|
+
if (node.type !== AST_NODE_TYPES26.BinaryExpression || node.operator !== "+") {
|
|
5625
6031
|
return [];
|
|
5626
6032
|
}
|
|
5627
6033
|
const operands = concatOperands(node);
|
|
5628
6034
|
const hasStringLiteral = operands.some(
|
|
5629
|
-
(operand) => operand.type ===
|
|
6035
|
+
(operand) => operand.type === AST_NODE_TYPES26.Literal && typeof operand.value === "string"
|
|
5630
6036
|
);
|
|
5631
6037
|
if (!hasStringLiteral) {
|
|
5632
6038
|
return [];
|
|
5633
6039
|
}
|
|
5634
6040
|
return operands.filter(
|
|
5635
|
-
(operand) => operand.type !==
|
|
6041
|
+
(operand) => operand.type !== AST_NODE_TYPES26.Literal && !isStaticFragment(operand)
|
|
5636
6042
|
);
|
|
5637
6043
|
}
|
|
5638
6044
|
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;
|
|
5639
6045
|
var RUNTIME_MARKER = " ? ";
|
|
5640
6046
|
function staticStatementText(node) {
|
|
5641
|
-
if (node.type ===
|
|
6047
|
+
if (node.type === AST_NODE_TYPES26.TemplateLiteral) {
|
|
5642
6048
|
return node.quasis.map((quasi) => quasi.value.cooked ?? quasi.value.raw).join(RUNTIME_MARKER);
|
|
5643
6049
|
}
|
|
5644
|
-
if (node.type ===
|
|
6050
|
+
if (node.type === AST_NODE_TYPES26.Literal) {
|
|
5645
6051
|
return typeof node.value === "string" ? node.value : RUNTIME_MARKER;
|
|
5646
6052
|
}
|
|
5647
|
-
if (node.type ===
|
|
6053
|
+
if (node.type === AST_NODE_TYPES26.BinaryExpression && node.operator === "+") {
|
|
5648
6054
|
return staticStatementText(node.left) + staticStatementText(node.right);
|
|
5649
6055
|
}
|
|
5650
6056
|
return RUNTIME_MARKER;
|
|
@@ -5654,13 +6060,13 @@ function looksLikeSql(node) {
|
|
|
5654
6060
|
}
|
|
5655
6061
|
function statementMethodName(node, methods) {
|
|
5656
6062
|
const callee = node.callee;
|
|
5657
|
-
if (callee.type !==
|
|
6063
|
+
if (callee.type !== AST_NODE_TYPES26.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES26.Identifier) {
|
|
5658
6064
|
return null;
|
|
5659
6065
|
}
|
|
5660
6066
|
const name = callee.property.name;
|
|
5661
6067
|
return methods.has(name) ? name : null;
|
|
5662
6068
|
}
|
|
5663
|
-
var no_dynamic_sql_default =
|
|
6069
|
+
var no_dynamic_sql_default = ESLintUtils37.RuleCreator(
|
|
5664
6070
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5665
6071
|
)({
|
|
5666
6072
|
name: "no-dynamic-sql",
|
|
@@ -5699,7 +6105,7 @@ var no_dynamic_sql_default = ESLintUtils36.RuleCreator(
|
|
|
5699
6105
|
if (statement === void 0 || !looksLikeSql(statement)) {
|
|
5700
6106
|
return;
|
|
5701
6107
|
}
|
|
5702
|
-
const offenders = statement.type ===
|
|
6108
|
+
const offenders = statement.type === AST_NODE_TYPES26.TemplateLiteral ? runtimeInterpolations(statement) : runtimeConcatOperands(statement);
|
|
5703
6109
|
for (const offender of offenders) {
|
|
5704
6110
|
context.report({
|
|
5705
6111
|
node: offender,
|
|
@@ -5713,7 +6119,7 @@ var no_dynamic_sql_default = ESLintUtils36.RuleCreator(
|
|
|
5713
6119
|
});
|
|
5714
6120
|
|
|
5715
6121
|
// src/rules/no-raw-fetch-outside-clients.ts
|
|
5716
|
-
import { ESLintUtils as
|
|
6122
|
+
import { ESLintUtils as ESLintUtils38 } from "@typescript-eslint/utils";
|
|
5717
6123
|
var DEFAULT_ALLOW = [
|
|
5718
6124
|
"[\\\\/]clients?[\\\\/]",
|
|
5719
6125
|
"-client\\.[cm]?[jt]sx?$",
|
|
@@ -5777,7 +6183,7 @@ function compile(patterns) {
|
|
|
5777
6183
|
}
|
|
5778
6184
|
return compiled;
|
|
5779
6185
|
}
|
|
5780
|
-
var no_raw_fetch_outside_clients_default =
|
|
6186
|
+
var no_raw_fetch_outside_clients_default = ESLintUtils38.RuleCreator(
|
|
5781
6187
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5782
6188
|
)({
|
|
5783
6189
|
name: "no-raw-fetch-outside-clients",
|
|
@@ -5825,7 +6231,7 @@ var no_raw_fetch_outside_clients_default = ESLintUtils37.RuleCreator(
|
|
|
5825
6231
|
});
|
|
5826
6232
|
|
|
5827
6233
|
// src/rules/no-storage-in-stateless-modules.ts
|
|
5828
|
-
import { AST_NODE_TYPES as
|
|
6234
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES27, ESLintUtils as ESLintUtils39 } from "@typescript-eslint/utils";
|
|
5829
6235
|
var DEFAULT_METHODS2 = [
|
|
5830
6236
|
"prepare",
|
|
5831
6237
|
"put",
|
|
@@ -5844,7 +6250,7 @@ function compile2(patterns) {
|
|
|
5844
6250
|
}
|
|
5845
6251
|
function storageMethodName(node, methods) {
|
|
5846
6252
|
const callee = node.callee;
|
|
5847
|
-
if (callee.type !==
|
|
6253
|
+
if (callee.type !== AST_NODE_TYPES27.MemberExpression || callee.computed || callee.property.type !== AST_NODE_TYPES27.Identifier) {
|
|
5848
6254
|
return null;
|
|
5849
6255
|
}
|
|
5850
6256
|
const name = callee.property.name;
|
|
@@ -5856,7 +6262,7 @@ function storageMethodName(node, methods) {
|
|
|
5856
6262
|
}
|
|
5857
6263
|
return name;
|
|
5858
6264
|
}
|
|
5859
|
-
var no_storage_in_stateless_modules_default =
|
|
6265
|
+
var no_storage_in_stateless_modules_default = ESLintUtils39.RuleCreator(
|
|
5860
6266
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5861
6267
|
)({
|
|
5862
6268
|
name: "no-storage-in-stateless-modules",
|
|
@@ -5915,8 +6321,8 @@ var no_storage_in_stateless_modules_default = ESLintUtils38.RuleCreator(
|
|
|
5915
6321
|
|
|
5916
6322
|
// src/rules/no-zod-native-enum.ts
|
|
5917
6323
|
import {
|
|
5918
|
-
ESLintUtils as
|
|
5919
|
-
AST_NODE_TYPES as
|
|
6324
|
+
ESLintUtils as ESLintUtils40,
|
|
6325
|
+
AST_NODE_TYPES as AST_NODE_TYPES28
|
|
5920
6326
|
} from "@typescript-eslint/utils";
|
|
5921
6327
|
import * as ts2 from "typescript";
|
|
5922
6328
|
var IGNORE_PATTERNS2 = [
|
|
@@ -5935,7 +6341,7 @@ function isZodModule2(source) {
|
|
|
5935
6341
|
return /(^|[/@-])zod([/-]|$)/.test(source);
|
|
5936
6342
|
}
|
|
5937
6343
|
function unwrap3(node) {
|
|
5938
|
-
if (node.type ===
|
|
6344
|
+
if (node.type === AST_NODE_TYPES28.TSAsExpression || node.type === AST_NODE_TYPES28.TSSatisfiesExpression) {
|
|
5939
6345
|
return unwrap3(node.expression);
|
|
5940
6346
|
}
|
|
5941
6347
|
return node;
|
|
@@ -5943,14 +6349,14 @@ function unwrap3(node) {
|
|
|
5943
6349
|
function stringValueTexts(node, sourceCode) {
|
|
5944
6350
|
const texts = [];
|
|
5945
6351
|
for (const prop of node.properties) {
|
|
5946
|
-
if (prop.type !==
|
|
6352
|
+
if (prop.type !== AST_NODE_TYPES28.Property) {
|
|
5947
6353
|
return null;
|
|
5948
6354
|
}
|
|
5949
6355
|
if (prop.computed || prop.shorthand || prop.method || prop.kind !== "init") {
|
|
5950
6356
|
return null;
|
|
5951
6357
|
}
|
|
5952
6358
|
const value = prop.value;
|
|
5953
|
-
if (value.type !==
|
|
6359
|
+
if (value.type !== AST_NODE_TYPES28.Literal || typeof value.value !== "string") {
|
|
5954
6360
|
return null;
|
|
5955
6361
|
}
|
|
5956
6362
|
const text = sourceCode.getText(value);
|
|
@@ -5966,7 +6372,7 @@ function resolvesToLocalEnum(node, scope) {
|
|
|
5966
6372
|
const variable = current.variables.find((v) => v.name === node.name);
|
|
5967
6373
|
if (variable !== void 0) {
|
|
5968
6374
|
return variable.defs.some(
|
|
5969
|
-
(def) => def.node.type ===
|
|
6375
|
+
(def) => def.node.type === AST_NODE_TYPES28.TSEnumDeclaration
|
|
5970
6376
|
);
|
|
5971
6377
|
}
|
|
5972
6378
|
current = current.upper;
|
|
@@ -5986,7 +6392,7 @@ function resolvesToImportedEnum(node, services) {
|
|
|
5986
6392
|
}
|
|
5987
6393
|
return (symbol.flags & ENUM_SYMBOL_FLAGS) !== 0;
|
|
5988
6394
|
}
|
|
5989
|
-
var no_zod_native_enum_default =
|
|
6395
|
+
var no_zod_native_enum_default = ESLintUtils40.RuleCreator(
|
|
5990
6396
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
5991
6397
|
)({
|
|
5992
6398
|
name: "no-zod-native-enum",
|
|
@@ -6013,32 +6419,32 @@ var no_zod_native_enum_default = ESLintUtils39.RuleCreator(
|
|
|
6013
6419
|
}
|
|
6014
6420
|
let services;
|
|
6015
6421
|
try {
|
|
6016
|
-
services =
|
|
6422
|
+
services = ESLintUtils40.getParserServices(context);
|
|
6017
6423
|
} catch {
|
|
6018
6424
|
services = null;
|
|
6019
6425
|
}
|
|
6020
6426
|
const zodImportedNames = /* @__PURE__ */ new Map();
|
|
6021
6427
|
function isZodMemberCall(node, api) {
|
|
6022
6428
|
const callee = node.callee;
|
|
6023
|
-
if (callee.type ===
|
|
6429
|
+
if (callee.type === AST_NODE_TYPES28.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES28.Identifier) {
|
|
6024
6430
|
return callee.property.name === api;
|
|
6025
6431
|
}
|
|
6026
|
-
if (callee.type ===
|
|
6432
|
+
if (callee.type === AST_NODE_TYPES28.Identifier) {
|
|
6027
6433
|
return zodImportedNames.get(callee.name) === api;
|
|
6028
6434
|
}
|
|
6029
6435
|
return false;
|
|
6030
6436
|
}
|
|
6031
6437
|
function buildFix(node) {
|
|
6032
6438
|
const callee = node.callee;
|
|
6033
|
-
if (callee.type !==
|
|
6439
|
+
if (callee.type !== AST_NODE_TYPES28.MemberExpression || callee.property.type !== AST_NODE_TYPES28.Identifier) {
|
|
6034
6440
|
return null;
|
|
6035
6441
|
}
|
|
6036
6442
|
const arg = node.arguments[0];
|
|
6037
|
-
if (arg === void 0 || node.arguments.length !== 1 || arg.type ===
|
|
6443
|
+
if (arg === void 0 || node.arguments.length !== 1 || arg.type === AST_NODE_TYPES28.SpreadElement) {
|
|
6038
6444
|
return null;
|
|
6039
6445
|
}
|
|
6040
6446
|
const inner = unwrap3(arg);
|
|
6041
|
-
if (inner.type !==
|
|
6447
|
+
if (inner.type !== AST_NODE_TYPES28.ObjectExpression) {
|
|
6042
6448
|
return null;
|
|
6043
6449
|
}
|
|
6044
6450
|
const values = stringValueTexts(inner, sourceCode);
|
|
@@ -6058,7 +6464,7 @@ var no_zod_native_enum_default = ESLintUtils39.RuleCreator(
|
|
|
6058
6464
|
return;
|
|
6059
6465
|
}
|
|
6060
6466
|
for (const spec of node.specifiers) {
|
|
6061
|
-
if (spec.type ===
|
|
6467
|
+
if (spec.type === AST_NODE_TYPES28.ImportSpecifier && spec.imported.type === AST_NODE_TYPES28.Identifier) {
|
|
6062
6468
|
zodImportedNames.set(spec.local.name, spec.imported.name);
|
|
6063
6469
|
}
|
|
6064
6470
|
}
|
|
@@ -6077,7 +6483,7 @@ var no_zod_native_enum_default = ESLintUtils39.RuleCreator(
|
|
|
6077
6483
|
return;
|
|
6078
6484
|
}
|
|
6079
6485
|
const arg = node.arguments[0];
|
|
6080
|
-
if (arg === void 0 || arg.type !==
|
|
6486
|
+
if (arg === void 0 || arg.type !== AST_NODE_TYPES28.Identifier) {
|
|
6081
6487
|
return;
|
|
6082
6488
|
}
|
|
6083
6489
|
const isEnum = resolvesToLocalEnum(arg, sourceCode.getScope(arg)) || services !== null && resolvesToImportedEnum(arg, services);
|
|
@@ -6095,8 +6501,8 @@ var no_zod_native_enum_default = ESLintUtils39.RuleCreator(
|
|
|
6095
6501
|
|
|
6096
6502
|
// src/rules/prefer-module-level-constant.ts
|
|
6097
6503
|
import {
|
|
6098
|
-
ESLintUtils as
|
|
6099
|
-
AST_NODE_TYPES as
|
|
6504
|
+
ESLintUtils as ESLintUtils41,
|
|
6505
|
+
AST_NODE_TYPES as AST_NODE_TYPES29
|
|
6100
6506
|
} from "@typescript-eslint/utils";
|
|
6101
6507
|
var DEFAULT_MIN_ELEMENTS = 3;
|
|
6102
6508
|
var MAX_LITERAL_DEPTH = 4;
|
|
@@ -6133,9 +6539,9 @@ var MUTATING_METHODS = /* @__PURE__ */ new Set([
|
|
|
6133
6539
|
"assign"
|
|
6134
6540
|
]);
|
|
6135
6541
|
var FUNCTION_TYPES4 = /* @__PURE__ */ new Set([
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6542
|
+
AST_NODE_TYPES29.FunctionDeclaration,
|
|
6543
|
+
AST_NODE_TYPES29.FunctionExpression,
|
|
6544
|
+
AST_NODE_TYPES29.ArrowFunctionExpression
|
|
6139
6545
|
]);
|
|
6140
6546
|
var COLLECTION_CONSTRUCTORS = /* @__PURE__ */ new Set(["Set", "Map"]);
|
|
6141
6547
|
function isIgnoredFile3(filename, sourceText) {
|
|
@@ -6148,13 +6554,13 @@ function isTestFile2(filename) {
|
|
|
6148
6554
|
return TEST_FILE_PATTERNS.some((re) => re.test(filename));
|
|
6149
6555
|
}
|
|
6150
6556
|
function unwrap4(node) {
|
|
6151
|
-
if (node.type ===
|
|
6557
|
+
if (node.type === AST_NODE_TYPES29.TSAsExpression || node.type === AST_NODE_TYPES29.TSSatisfiesExpression || node.type === AST_NODE_TYPES29.TSNonNullExpression) {
|
|
6152
6558
|
return unwrap4(node.expression);
|
|
6153
6559
|
}
|
|
6154
6560
|
return node;
|
|
6155
6561
|
}
|
|
6156
6562
|
function isRegexLiteral(node) {
|
|
6157
|
-
return node.type ===
|
|
6563
|
+
return node.type === AST_NODE_TYPES29.Literal && "regex" in node && node.regex !== void 0;
|
|
6158
6564
|
}
|
|
6159
6565
|
function isLiteralOnly(node, depth) {
|
|
6160
6566
|
if (depth > MAX_LITERAL_DEPTH) {
|
|
@@ -6162,29 +6568,29 @@ function isLiteralOnly(node, depth) {
|
|
|
6162
6568
|
}
|
|
6163
6569
|
const inner = unwrap4(node);
|
|
6164
6570
|
switch (inner.type) {
|
|
6165
|
-
case
|
|
6571
|
+
case AST_NODE_TYPES29.Literal: {
|
|
6166
6572
|
return true;
|
|
6167
6573
|
}
|
|
6168
|
-
case
|
|
6574
|
+
case AST_NODE_TYPES29.TemplateLiteral: {
|
|
6169
6575
|
return inner.expressions.length === 0;
|
|
6170
6576
|
}
|
|
6171
|
-
case
|
|
6172
|
-
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type ===
|
|
6577
|
+
case AST_NODE_TYPES29.UnaryExpression: {
|
|
6578
|
+
return (inner.operator === "-" || inner.operator === "+") && inner.argument.type === AST_NODE_TYPES29.Literal && typeof inner.argument.value === "number";
|
|
6173
6579
|
}
|
|
6174
|
-
case
|
|
6580
|
+
case AST_NODE_TYPES29.ArrayExpression: {
|
|
6175
6581
|
return inner.elements.every(
|
|
6176
|
-
(el) => el !== null && el.type !==
|
|
6582
|
+
(el) => el !== null && el.type !== AST_NODE_TYPES29.SpreadElement && isLiteralOnly(el, depth + 1)
|
|
6177
6583
|
);
|
|
6178
6584
|
}
|
|
6179
|
-
case
|
|
6585
|
+
case AST_NODE_TYPES29.ObjectExpression: {
|
|
6180
6586
|
return inner.properties.every((prop) => {
|
|
6181
|
-
if (prop.type !==
|
|
6587
|
+
if (prop.type !== AST_NODE_TYPES29.Property) {
|
|
6182
6588
|
return false;
|
|
6183
6589
|
}
|
|
6184
6590
|
if (prop.shorthand || prop.method || prop.kind !== "init") {
|
|
6185
6591
|
return false;
|
|
6186
6592
|
}
|
|
6187
|
-
if (prop.computed && prop.key.type !==
|
|
6593
|
+
if (prop.computed && prop.key.type !== AST_NODE_TYPES29.Literal) {
|
|
6188
6594
|
return false;
|
|
6189
6595
|
}
|
|
6190
6596
|
return isLiteralOnly(prop.value, depth + 1);
|
|
@@ -6197,7 +6603,7 @@ function isLiteralOnly(node, depth) {
|
|
|
6197
6603
|
}
|
|
6198
6604
|
function unwrapObjectFreeze(node) {
|
|
6199
6605
|
const inner = unwrap4(node);
|
|
6200
|
-
if (inner.type ===
|
|
6606
|
+
if (inner.type === AST_NODE_TYPES29.CallExpression && inner.callee.type === AST_NODE_TYPES29.MemberExpression && !inner.callee.computed && inner.callee.object.type === AST_NODE_TYPES29.Identifier && inner.callee.object.name === "Object" && inner.callee.property.type === AST_NODE_TYPES29.Identifier && inner.callee.property.name === "freeze" && inner.arguments.length === 1 && inner.arguments[0] !== void 0 && inner.arguments[0].type !== AST_NODE_TYPES29.SpreadElement) {
|
|
6201
6607
|
return unwrap4(inner.arguments[0]);
|
|
6202
6608
|
}
|
|
6203
6609
|
return inner;
|
|
@@ -6213,19 +6619,19 @@ function classify(init, checkRegex) {
|
|
|
6213
6619
|
}
|
|
6214
6620
|
return { kind: "regex", size: 1 };
|
|
6215
6621
|
}
|
|
6216
|
-
if (node.type ===
|
|
6622
|
+
if (node.type === AST_NODE_TYPES29.ArrayExpression) {
|
|
6217
6623
|
return isLiteralOnly(node, 0) ? { kind: "array", size: node.elements.length } : null;
|
|
6218
6624
|
}
|
|
6219
|
-
if (node.type ===
|
|
6625
|
+
if (node.type === AST_NODE_TYPES29.ObjectExpression) {
|
|
6220
6626
|
return isLiteralOnly(node, 0) ? { kind: "object", size: node.properties.length } : null;
|
|
6221
6627
|
}
|
|
6222
|
-
if (node.type ===
|
|
6628
|
+
if (node.type === AST_NODE_TYPES29.NewExpression && node.callee.type === AST_NODE_TYPES29.Identifier && COLLECTION_CONSTRUCTORS.has(node.callee.name)) {
|
|
6223
6629
|
const arg = node.arguments[0];
|
|
6224
|
-
if (node.arguments.length !== 1 || arg === void 0 || arg.type ===
|
|
6630
|
+
if (node.arguments.length !== 1 || arg === void 0 || arg.type === AST_NODE_TYPES29.SpreadElement) {
|
|
6225
6631
|
return null;
|
|
6226
6632
|
}
|
|
6227
6633
|
const entries = unwrap4(arg);
|
|
6228
|
-
if (entries.type !==
|
|
6634
|
+
if (entries.type !== AST_NODE_TYPES29.ArrayExpression) {
|
|
6229
6635
|
return null;
|
|
6230
6636
|
}
|
|
6231
6637
|
return isLiteralOnly(entries, 0) ? { kind: node.callee.name === "Set" ? "Set" : "Map", size: entries.elements.length } : null;
|
|
@@ -6254,10 +6660,10 @@ var NON_RETAINING_BUILTINS = /* @__PURE__ */ new Map(
|
|
|
6254
6660
|
);
|
|
6255
6661
|
function isNonRetainingBuiltinCall(node, argument) {
|
|
6256
6662
|
const callee = node.callee;
|
|
6257
|
-
if (callee.type ===
|
|
6663
|
+
if (callee.type === AST_NODE_TYPES29.Identifier && callee.name === "structuredClone") {
|
|
6258
6664
|
return true;
|
|
6259
6665
|
}
|
|
6260
|
-
if (callee.type !==
|
|
6666
|
+
if (callee.type !== AST_NODE_TYPES29.MemberExpression || callee.computed || callee.object.type !== AST_NODE_TYPES29.Identifier || callee.property.type !== AST_NODE_TYPES29.Identifier) {
|
|
6261
6667
|
return false;
|
|
6262
6668
|
}
|
|
6263
6669
|
const members = NON_RETAINING_BUILTINS.get(callee.object.name);
|
|
@@ -6271,43 +6677,43 @@ function isNonRetainingBuiltinCall(node, argument) {
|
|
|
6271
6677
|
}
|
|
6272
6678
|
function isSafeRead(identifier) {
|
|
6273
6679
|
const parent = identifier.parent;
|
|
6274
|
-
if (parent.type ===
|
|
6680
|
+
if (parent.type === AST_NODE_TYPES29.MemberExpression) {
|
|
6275
6681
|
if (parent.object !== identifier) {
|
|
6276
6682
|
return true;
|
|
6277
6683
|
}
|
|
6278
6684
|
const grandparent = parent.parent;
|
|
6279
|
-
if (grandparent.type ===
|
|
6685
|
+
if (grandparent.type === AST_NODE_TYPES29.AssignmentExpression && grandparent.left === parent) {
|
|
6280
6686
|
return false;
|
|
6281
6687
|
}
|
|
6282
|
-
if (grandparent.type ===
|
|
6688
|
+
if (grandparent.type === AST_NODE_TYPES29.UpdateExpression) {
|
|
6283
6689
|
return false;
|
|
6284
6690
|
}
|
|
6285
|
-
if (grandparent.type ===
|
|
6691
|
+
if (grandparent.type === AST_NODE_TYPES29.UnaryExpression && grandparent.operator === "delete") {
|
|
6286
6692
|
return false;
|
|
6287
6693
|
}
|
|
6288
|
-
if (!parent.computed && parent.property.type ===
|
|
6694
|
+
if (!parent.computed && parent.property.type === AST_NODE_TYPES29.Identifier && MUTATING_METHODS.has(parent.property.name) && grandparent.type === AST_NODE_TYPES29.CallExpression && grandparent.callee === parent) {
|
|
6289
6695
|
return false;
|
|
6290
6696
|
}
|
|
6291
6697
|
return true;
|
|
6292
6698
|
}
|
|
6293
|
-
if (parent.type ===
|
|
6699
|
+
if (parent.type === AST_NODE_TYPES29.ForOfStatement && parent.right === identifier) {
|
|
6294
6700
|
return true;
|
|
6295
6701
|
}
|
|
6296
|
-
if (parent.type ===
|
|
6702
|
+
if (parent.type === AST_NODE_TYPES29.SpreadElement) {
|
|
6297
6703
|
return true;
|
|
6298
6704
|
}
|
|
6299
|
-
if (parent.type ===
|
|
6705
|
+
if (parent.type === AST_NODE_TYPES29.BinaryExpression) {
|
|
6300
6706
|
return true;
|
|
6301
6707
|
}
|
|
6302
|
-
if (parent.type ===
|
|
6708
|
+
if (parent.type === AST_NODE_TYPES29.CallExpression && parent.arguments.includes(identifier) && isNonRetainingBuiltinCall(parent, identifier)) {
|
|
6303
6709
|
return true;
|
|
6304
6710
|
}
|
|
6305
|
-
if (parent.type ===
|
|
6711
|
+
if (parent.type === AST_NODE_TYPES29.UnaryExpression && parent.operator !== "delete") {
|
|
6306
6712
|
return true;
|
|
6307
6713
|
}
|
|
6308
6714
|
return false;
|
|
6309
6715
|
}
|
|
6310
|
-
var prefer_module_level_constant_default =
|
|
6716
|
+
var prefer_module_level_constant_default = ESLintUtils41.RuleCreator(
|
|
6311
6717
|
(name) => `https://github.com/sarj-ai/linting/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6312
6718
|
)({
|
|
6313
6719
|
name: "prefer-module-level-constant",
|
|
@@ -6359,7 +6765,7 @@ var prefer_module_level_constant_default = ESLintUtils40.RuleCreator(
|
|
|
6359
6765
|
if (reference.isWrite()) {
|
|
6360
6766
|
return false;
|
|
6361
6767
|
}
|
|
6362
|
-
if (reference.identifier.type !==
|
|
6768
|
+
if (reference.identifier.type !== AST_NODE_TYPES29.Identifier) {
|
|
6363
6769
|
return false;
|
|
6364
6770
|
}
|
|
6365
6771
|
if (!isSafeRead(reference.identifier)) {
|
|
@@ -6371,10 +6777,10 @@ var prefer_module_level_constant_default = ESLintUtils40.RuleCreator(
|
|
|
6371
6777
|
return {
|
|
6372
6778
|
VariableDeclarator(node) {
|
|
6373
6779
|
const declaration = node.parent;
|
|
6374
|
-
if (declaration.type !==
|
|
6780
|
+
if (declaration.type !== AST_NODE_TYPES29.VariableDeclaration || declaration.kind !== "const" || declaration.declare === true) {
|
|
6375
6781
|
return;
|
|
6376
6782
|
}
|
|
6377
|
-
if (node.id.type !==
|
|
6783
|
+
if (node.id.type !== AST_NODE_TYPES29.Identifier || node.init === null) {
|
|
6378
6784
|
return;
|
|
6379
6785
|
}
|
|
6380
6786
|
if (enclosingFunction2(node) === null) {
|
|
@@ -6401,7 +6807,7 @@ var prefer_module_level_constant_default = ESLintUtils40.RuleCreator(
|
|
|
6401
6807
|
});
|
|
6402
6808
|
|
|
6403
6809
|
// src/rules/jsdoc-restates-signature.ts
|
|
6404
|
-
import { AST_NODE_TYPES as
|
|
6810
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES30, ESLintUtils as ESLintUtils42 } from "@typescript-eslint/utils";
|
|
6405
6811
|
var VALUE_TAGS = /* @__PURE__ */ new Set([
|
|
6406
6812
|
"alpha",
|
|
6407
6813
|
"author",
|
|
@@ -6484,30 +6890,30 @@ function declarationNames(node) {
|
|
|
6484
6890
|
switch (node.type) {
|
|
6485
6891
|
// `export function f()` — the JSDoc sits above the `export`, so the token
|
|
6486
6892
|
// after it resolves to the wrapper, not to the thing being documented.
|
|
6487
|
-
case
|
|
6488
|
-
case
|
|
6893
|
+
case AST_NODE_TYPES30.ExportNamedDeclaration:
|
|
6894
|
+
case AST_NODE_TYPES30.ExportDefaultDeclaration:
|
|
6489
6895
|
return node.declaration == null ? null : declarationNames(node.declaration);
|
|
6490
|
-
case
|
|
6491
|
-
case
|
|
6896
|
+
case AST_NODE_TYPES30.FunctionDeclaration:
|
|
6897
|
+
case AST_NODE_TYPES30.TSDeclareFunction:
|
|
6492
6898
|
return node.id === null ? null : { name: node.id.name, params: paramNames(node.params) };
|
|
6493
|
-
case
|
|
6494
|
-
case
|
|
6495
|
-
case
|
|
6496
|
-
case
|
|
6899
|
+
case AST_NODE_TYPES30.ClassDeclaration:
|
|
6900
|
+
case AST_NODE_TYPES30.TSInterfaceDeclaration:
|
|
6901
|
+
case AST_NODE_TYPES30.TSTypeAliasDeclaration:
|
|
6902
|
+
case AST_NODE_TYPES30.TSEnumDeclaration:
|
|
6497
6903
|
return node.id === null ? null : { name: node.id.name, params: [] };
|
|
6498
|
-
case
|
|
6904
|
+
case AST_NODE_TYPES30.VariableDeclaration: {
|
|
6499
6905
|
const declarator = node.declarations[0];
|
|
6500
|
-
if (declarator === void 0 || declarator.id.type !==
|
|
6906
|
+
if (declarator === void 0 || declarator.id.type !== AST_NODE_TYPES30.Identifier) return null;
|
|
6501
6907
|
const init = declarator.init;
|
|
6502
|
-
const params = init != null && (init.type ===
|
|
6908
|
+
const params = init != null && (init.type === AST_NODE_TYPES30.ArrowFunctionExpression || init.type === AST_NODE_TYPES30.FunctionExpression) ? paramNames(init.params) : [];
|
|
6503
6909
|
return { name: declarator.id.name, params };
|
|
6504
6910
|
}
|
|
6505
|
-
case
|
|
6506
|
-
case
|
|
6507
|
-
case
|
|
6508
|
-
case
|
|
6509
|
-
if (node.key.type !==
|
|
6510
|
-
const params = node.type ===
|
|
6911
|
+
case AST_NODE_TYPES30.MethodDefinition:
|
|
6912
|
+
case AST_NODE_TYPES30.PropertyDefinition:
|
|
6913
|
+
case AST_NODE_TYPES30.TSMethodSignature:
|
|
6914
|
+
case AST_NODE_TYPES30.TSPropertySignature: {
|
|
6915
|
+
if (node.key.type !== AST_NODE_TYPES30.Identifier) return null;
|
|
6916
|
+
const params = node.type === AST_NODE_TYPES30.MethodDefinition ? paramNames(node.value.params) : node.type === AST_NODE_TYPES30.TSMethodSignature ? paramNames(node.params) : [];
|
|
6511
6917
|
return { name: node.key.name, params };
|
|
6512
6918
|
}
|
|
6513
6919
|
default:
|
|
@@ -6517,9 +6923,9 @@ function declarationNames(node) {
|
|
|
6517
6923
|
function paramNames(params) {
|
|
6518
6924
|
const names = [];
|
|
6519
6925
|
for (const param of params) {
|
|
6520
|
-
const target = param.type ===
|
|
6521
|
-
if (target.type ===
|
|
6522
|
-
else if (target.type ===
|
|
6926
|
+
const target = param.type === AST_NODE_TYPES30.AssignmentPattern ? param.left : param;
|
|
6927
|
+
if (target.type === AST_NODE_TYPES30.Identifier) names.push(target.name);
|
|
6928
|
+
else if (target.type === AST_NODE_TYPES30.TSParameterProperty) continue;
|
|
6523
6929
|
}
|
|
6524
6930
|
return names;
|
|
6525
6931
|
}
|
|
@@ -6528,7 +6934,7 @@ function tokensOf(names) {
|
|
|
6528
6934
|
for (const name of names) for (const part of splitIdentifier(name)) tokens.add(part);
|
|
6529
6935
|
return tokens;
|
|
6530
6936
|
}
|
|
6531
|
-
var jsdoc_restates_signature_default =
|
|
6937
|
+
var jsdoc_restates_signature_default = ESLintUtils42.RuleCreator(
|
|
6532
6938
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6533
6939
|
)({
|
|
6534
6940
|
name: "jsdoc-restates-signature",
|
|
@@ -6564,7 +6970,7 @@ var jsdoc_restates_signature_default = ESLintUtils41.RuleCreator(
|
|
|
6564
6970
|
if (token === null || token.loc.start.line !== comment.loc.end.line + 1) continue;
|
|
6565
6971
|
let node = sourceCode.getNodeByRangeIndex(token.range[0]);
|
|
6566
6972
|
let declaration = null;
|
|
6567
|
-
while (node != null && node.type !==
|
|
6973
|
+
while (node != null && node.type !== AST_NODE_TYPES30.Program) {
|
|
6568
6974
|
declaration = declarationNames(node);
|
|
6569
6975
|
if (declaration !== null) break;
|
|
6570
6976
|
node = node.parent ?? null;
|
|
@@ -6619,7 +7025,7 @@ var jsdoc_restates_signature_default = ESLintUtils41.RuleCreator(
|
|
|
6619
7025
|
});
|
|
6620
7026
|
|
|
6621
7027
|
// src/rules/no-restated-comment.ts
|
|
6622
|
-
import { AST_NODE_TYPES as
|
|
7028
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES31, ESLintUtils as ESLintUtils43 } from "@typescript-eslint/utils";
|
|
6623
7029
|
var MAX_WORDS = 8;
|
|
6624
7030
|
var MIN_CONTENT_TOKENS = 2;
|
|
6625
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;
|
|
@@ -6643,7 +7049,7 @@ function headsSiblingRun(node) {
|
|
|
6643
7049
|
const next = index >= 0 ? body[index + 1] : void 0;
|
|
6644
7050
|
return next !== void 0 && next.type === node.type;
|
|
6645
7051
|
}
|
|
6646
|
-
var no_restated_comment_default =
|
|
7052
|
+
var no_restated_comment_default = ESLintUtils43.RuleCreator(
|
|
6647
7053
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6648
7054
|
)({
|
|
6649
7055
|
name: "no-restated-comment",
|
|
@@ -6671,7 +7077,7 @@ var no_restated_comment_default = ESLintUtils42.RuleCreator(
|
|
|
6671
7077
|
function labelsASiblingRun(comment) {
|
|
6672
7078
|
const token = sourceCode.getTokenAfter(comment, { includeComments: false });
|
|
6673
7079
|
if (token === null) return false;
|
|
6674
|
-
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 !== AST_NODE_TYPES31.Program; node = node.parent) {
|
|
6675
7081
|
if (headsSiblingRun(node)) return true;
|
|
6676
7082
|
}
|
|
6677
7083
|
return false;
|
|
@@ -6711,7 +7117,7 @@ var no_restated_comment_default = ESLintUtils42.RuleCreator(
|
|
|
6711
7117
|
});
|
|
6712
7118
|
|
|
6713
7119
|
// src/rules/trailing-value-narration.ts
|
|
6714
|
-
import { ESLintUtils as
|
|
7120
|
+
import { ESLintUtils as ESLintUtils44 } from "@typescript-eslint/utils";
|
|
6715
7121
|
var NUMBER_RE = /(?<![\w.])(\d+(?:\.\d+)?)(?![\w.])/g;
|
|
6716
7122
|
var WORD_RE3 = /[A-Za-z]+(?:'[a-z]+)?|\d+(?:\.\d+)?/g;
|
|
6717
7123
|
var UNIT_WORDS = /* @__PURE__ */ new Set([
|
|
@@ -6795,7 +7201,7 @@ function narratesValue(body, code) {
|
|
|
6795
7201
|
(word) => STOPWORDS3.has(word) || UNIT_WORDS.has(word) || commentNumbers.has(word) || identifiers.has(word) || stems.has(stem(word))
|
|
6796
7202
|
);
|
|
6797
7203
|
}
|
|
6798
|
-
var trailing_value_narration_default =
|
|
7204
|
+
var trailing_value_narration_default = ESLintUtils44.RuleCreator(
|
|
6799
7205
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6800
7206
|
)({
|
|
6801
7207
|
name: "trailing-value-narration",
|
|
@@ -6836,7 +7242,7 @@ var trailing_value_narration_default = ESLintUtils43.RuleCreator(
|
|
|
6836
7242
|
});
|
|
6837
7243
|
|
|
6838
7244
|
// src/rules/no-tautological-expect.ts
|
|
6839
|
-
import { AST_NODE_TYPES as
|
|
7245
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES32, ESLintUtils as ESLintUtils45 } from "@typescript-eslint/utils";
|
|
6840
7246
|
var EQUALITY_MATCHERS = /* @__PURE__ */ new Set(["toBe", "toEqual", "toStrictEqual"]);
|
|
6841
7247
|
var ZERO_ARG_MATCHERS = /* @__PURE__ */ new Set([
|
|
6842
7248
|
"toBeDefined",
|
|
@@ -6850,17 +7256,17 @@ var OPERAND_PREVIEW_CHARS = 40;
|
|
|
6850
7256
|
var NUMERIC_SIGNS = /* @__PURE__ */ new Set(["-", "+"]);
|
|
6851
7257
|
function isLiteral(node) {
|
|
6852
7258
|
switch (node.type) {
|
|
6853
|
-
case
|
|
7259
|
+
case AST_NODE_TYPES32.Literal:
|
|
6854
7260
|
return true;
|
|
6855
|
-
case
|
|
7261
|
+
case AST_NODE_TYPES32.TemplateLiteral:
|
|
6856
7262
|
return node.expressions.length === 0;
|
|
6857
|
-
case
|
|
7263
|
+
case AST_NODE_TYPES32.UnaryExpression:
|
|
6858
7264
|
return NUMERIC_SIGNS.has(node.operator) && isLiteral(node.argument);
|
|
6859
|
-
case
|
|
7265
|
+
case AST_NODE_TYPES32.ArrayExpression:
|
|
6860
7266
|
return node.elements.every((element) => element !== null && isLiteral(element));
|
|
6861
|
-
case
|
|
7267
|
+
case AST_NODE_TYPES32.ObjectExpression:
|
|
6862
7268
|
return node.properties.every(
|
|
6863
|
-
(property) => property.type ===
|
|
7269
|
+
(property) => property.type === AST_NODE_TYPES32.Property && !property.computed && isLiteral(property.value)
|
|
6864
7270
|
);
|
|
6865
7271
|
default:
|
|
6866
7272
|
return false;
|
|
@@ -6868,12 +7274,12 @@ function isLiteral(node) {
|
|
|
6868
7274
|
}
|
|
6869
7275
|
function expectOperand(callee) {
|
|
6870
7276
|
const receiver = callee.object;
|
|
6871
|
-
if (receiver.type !==
|
|
7277
|
+
if (receiver.type !== AST_NODE_TYPES32.CallExpression || receiver.callee.type !== AST_NODE_TYPES32.Identifier || receiver.callee.name !== "expect" || receiver.arguments.length !== 1) {
|
|
6872
7278
|
return null;
|
|
6873
7279
|
}
|
|
6874
7280
|
return receiver.arguments[0] ?? null;
|
|
6875
7281
|
}
|
|
6876
|
-
var no_tautological_expect_default =
|
|
7282
|
+
var no_tautological_expect_default = ESLintUtils45.RuleCreator(
|
|
6877
7283
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
6878
7284
|
)({
|
|
6879
7285
|
name: "no-tautological-expect",
|
|
@@ -6900,10 +7306,10 @@ var no_tautological_expect_default = ESLintUtils44.RuleCreator(
|
|
|
6900
7306
|
return {
|
|
6901
7307
|
CallExpression(node) {
|
|
6902
7308
|
const callee = node.callee;
|
|
6903
|
-
if (callee.type !==
|
|
7309
|
+
if (callee.type !== AST_NODE_TYPES32.MemberExpression || callee.computed) {
|
|
6904
7310
|
return;
|
|
6905
7311
|
}
|
|
6906
|
-
if (callee.property.type !==
|
|
7312
|
+
if (callee.property.type !== AST_NODE_TYPES32.Identifier) {
|
|
6907
7313
|
return;
|
|
6908
7314
|
}
|
|
6909
7315
|
const matcher = callee.property.name;
|
|
@@ -6937,26 +7343,26 @@ var no_tautological_expect_default = ESLintUtils44.RuleCreator(
|
|
|
6937
7343
|
});
|
|
6938
7344
|
|
|
6939
7345
|
// src/rules/require-interface-for-injected-service.ts
|
|
6940
|
-
import { AST_NODE_TYPES as
|
|
7346
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES33, ESLintUtils as ESLintUtils46 } from "@typescript-eslint/utils";
|
|
6941
7347
|
var CONFIGISH_TYPE_RE = /(?:Options|Opts|Config|Configuration|Settings|Params|Props|Args|Env|Environment|Callbacks|Flags)$/;
|
|
6942
7348
|
var CONFIGISH_NAME_RE = /^(?:options|opts|config|configuration|settings|params|props|args|env|environment|callbacks|flags|logger|log|clock)$/i;
|
|
6943
7349
|
var HTTP_TRANSPORT_TYPE_RE = /^(?:KyInstance|AxiosInstance|Session)$/;
|
|
6944
7350
|
var TRANSPORT_WRAPPER_NAME_RE = /Client$/;
|
|
6945
7351
|
var ROUTER_FACTORY_NAME = "Router";
|
|
6946
7352
|
var FRAMEWORK_HTTP_TYPES = /* @__PURE__ */ new Set(["Request", "Response", "NextFunction"]);
|
|
6947
|
-
var isExportedClass = (node) => node.parent.type ===
|
|
6948
|
-
var qualifiedName = (name) => name.type ===
|
|
7353
|
+
var isExportedClass = (node) => node.parent.type === AST_NODE_TYPES33.ExportNamedDeclaration || node.parent.type === AST_NODE_TYPES33.ExportDefaultDeclaration;
|
|
7354
|
+
var qualifiedName = (name) => name.type === AST_NODE_TYPES33.Identifier ? name.name : name.type === AST_NODE_TYPES33.TSQualifiedName ? `${qualifiedName(name.left)}.${name.right.name}` : "";
|
|
6949
7355
|
var typeReferenceName = (annotated) => {
|
|
6950
7356
|
let target = annotated;
|
|
6951
|
-
if (target.type ===
|
|
6952
|
-
if (target.type ===
|
|
6953
|
-
if (target.type !==
|
|
7357
|
+
if (target.type === AST_NODE_TYPES33.TSParameterProperty) target = target.parameter;
|
|
7358
|
+
if (target.type === AST_NODE_TYPES33.AssignmentPattern) target = target.left;
|
|
7359
|
+
if (target.type !== AST_NODE_TYPES33.Identifier) return null;
|
|
6954
7360
|
const annotation = target.typeAnnotation?.typeAnnotation;
|
|
6955
|
-
if (annotation === void 0 || annotation.type !==
|
|
7361
|
+
if (annotation === void 0 || annotation.type !== AST_NODE_TYPES33.TSTypeReference) {
|
|
6956
7362
|
return null;
|
|
6957
7363
|
}
|
|
6958
7364
|
const { typeName } = annotation;
|
|
6959
|
-
const rightmost = typeName.type ===
|
|
7365
|
+
const rightmost = typeName.type === AST_NODE_TYPES33.Identifier ? typeName.name : typeName.type === AST_NODE_TYPES33.TSQualifiedName ? typeName.right.name : null;
|
|
6960
7366
|
if (rightmost === null) return null;
|
|
6961
7367
|
return { name: target.name, typeName: rightmost, display: qualifiedName(typeName) };
|
|
6962
7368
|
};
|
|
@@ -6966,17 +7372,17 @@ var readConstructor = (ctor) => {
|
|
|
6966
7372
|
let constructedFields = 0;
|
|
6967
7373
|
if (body !== null && body !== void 0) {
|
|
6968
7374
|
for (const statement of body.body) {
|
|
6969
|
-
if (statement.type !==
|
|
7375
|
+
if (statement.type !== AST_NODE_TYPES33.ExpressionStatement) continue;
|
|
6970
7376
|
const expression = statement.expression;
|
|
6971
|
-
if (expression.type !==
|
|
7377
|
+
if (expression.type !== AST_NODE_TYPES33.AssignmentExpression || expression.operator !== "=" || expression.left.type !== AST_NODE_TYPES33.MemberExpression || expression.left.object.type !== AST_NODE_TYPES33.ThisExpression) {
|
|
6972
7378
|
continue;
|
|
6973
7379
|
}
|
|
6974
7380
|
const source = expression.right;
|
|
6975
|
-
if (source.type ===
|
|
7381
|
+
if (source.type === AST_NODE_TYPES33.NewExpression) {
|
|
6976
7382
|
constructedFields += 1;
|
|
6977
|
-
} else if (source.type ===
|
|
7383
|
+
} else if (source.type === AST_NODE_TYPES33.Identifier) {
|
|
6978
7384
|
storedFrom.add(source.name);
|
|
6979
|
-
} else if (source.type ===
|
|
7385
|
+
} else if (source.type === AST_NODE_TYPES33.MemberExpression && source.object.type === AST_NODE_TYPES33.Identifier) {
|
|
6980
7386
|
storedFrom.add(source.object.name);
|
|
6981
7387
|
}
|
|
6982
7388
|
}
|
|
@@ -6985,7 +7391,7 @@ var readConstructor = (ctor) => {
|
|
|
6985
7391
|
for (const parameter of ctor.value.params) {
|
|
6986
7392
|
const reference = typeReferenceName(parameter);
|
|
6987
7393
|
if (reference === null) continue;
|
|
6988
|
-
const stored = parameter.type ===
|
|
7394
|
+
const stored = parameter.type === AST_NODE_TYPES33.TSParameterProperty || storedFrom.has(reference.name);
|
|
6989
7395
|
if (!stored) continue;
|
|
6990
7396
|
if (CONFIGISH_TYPE_RE.test(reference.typeName)) continue;
|
|
6991
7397
|
if (CONFIGISH_NAME_RE.test(reference.name)) continue;
|
|
@@ -7015,19 +7421,19 @@ var subtreeHas = (root, found) => {
|
|
|
7015
7421
|
return hit;
|
|
7016
7422
|
};
|
|
7017
7423
|
var isFrameworkWiring = (body) => subtreeHas(body, (node) => {
|
|
7018
|
-
if (node.type ===
|
|
7424
|
+
if (node.type === AST_NODE_TYPES33.CallExpression) {
|
|
7019
7425
|
const { callee } = node;
|
|
7020
|
-
if (callee.type ===
|
|
7021
|
-
return callee.type ===
|
|
7426
|
+
if (callee.type === AST_NODE_TYPES33.Identifier) return callee.name === ROUTER_FACTORY_NAME;
|
|
7427
|
+
return callee.type === AST_NODE_TYPES33.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES33.Identifier && callee.property.name === ROUTER_FACTORY_NAME;
|
|
7022
7428
|
}
|
|
7023
|
-
return node.type ===
|
|
7429
|
+
return node.type === AST_NODE_TYPES33.TSTypeReference && node.typeName.type === AST_NODE_TYPES33.TSQualifiedName && FRAMEWORK_HTTP_TYPES.has(node.typeName.right.name);
|
|
7024
7430
|
});
|
|
7025
7431
|
var stem2 = (name) => name.replace(/^I(?=[A-Z])/, "").replace(/Impl$/, "");
|
|
7026
7432
|
var fileInterfaceNames = (program) => {
|
|
7027
7433
|
const names = [];
|
|
7028
7434
|
for (const statement of program.body) {
|
|
7029
|
-
const declaration = statement.type ===
|
|
7030
|
-
if (declaration?.type ===
|
|
7435
|
+
const declaration = statement.type === AST_NODE_TYPES33.ExportNamedDeclaration ? statement.declaration : statement;
|
|
7436
|
+
if (declaration?.type === AST_NODE_TYPES33.TSInterfaceDeclaration) names.push(declaration.id.name);
|
|
7031
7437
|
}
|
|
7032
7438
|
return names;
|
|
7033
7439
|
};
|
|
@@ -7045,16 +7451,16 @@ var isTransportWrapper = (className, collaborators, program) => {
|
|
|
7045
7451
|
var publicMethodNames = (body) => {
|
|
7046
7452
|
const names = [];
|
|
7047
7453
|
for (const member of body.body) {
|
|
7048
|
-
if (member.type !==
|
|
7454
|
+
if (member.type !== AST_NODE_TYPES33.MethodDefinition) continue;
|
|
7049
7455
|
if (member.kind !== "method" || member.static) continue;
|
|
7050
7456
|
if (member.accessibility === "private" || member.accessibility === "protected") continue;
|
|
7051
|
-
if (member.key.type ===
|
|
7052
|
-
if (member.key.type ===
|
|
7457
|
+
if (member.key.type === AST_NODE_TYPES33.PrivateIdentifier) continue;
|
|
7458
|
+
if (member.key.type === AST_NODE_TYPES33.Identifier) names.push(member.key.name);
|
|
7053
7459
|
else names.push("\u2026");
|
|
7054
7460
|
}
|
|
7055
7461
|
return names;
|
|
7056
7462
|
};
|
|
7057
|
-
var require_interface_for_injected_service_default =
|
|
7463
|
+
var require_interface_for_injected_service_default = ESLintUtils46.RuleCreator(
|
|
7058
7464
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7059
7465
|
)({
|
|
7060
7466
|
name: "require-interface-for-injected-service",
|
|
@@ -7082,7 +7488,7 @@ var require_interface_for_injected_service_default = ESLintUtils45.RuleCreator(
|
|
|
7082
7488
|
if (node.implements.length > 0) return;
|
|
7083
7489
|
if (node.decorators.length > 0) return;
|
|
7084
7490
|
const ctor = node.body.body.find(
|
|
7085
|
-
(member) => member.type ===
|
|
7491
|
+
(member) => member.type === AST_NODE_TYPES33.MethodDefinition && member.kind === "constructor"
|
|
7086
7492
|
);
|
|
7087
7493
|
if (ctor === void 0) return;
|
|
7088
7494
|
const { collaborators, constructedFields } = readConstructor(ctor);
|
|
@@ -7107,26 +7513,26 @@ var require_interface_for_injected_service_default = ESLintUtils45.RuleCreator(
|
|
|
7107
7513
|
});
|
|
7108
7514
|
|
|
7109
7515
|
// src/rules/prefer-non-nullable-collection.ts
|
|
7110
|
-
import { AST_NODE_TYPES as
|
|
7516
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES34, ESLintUtils as ESLintUtils47 } from "@typescript-eslint/utils";
|
|
7111
7517
|
var ARRAY_TYPE_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
7112
7518
|
function propertyName(node) {
|
|
7113
7519
|
const key = node.key;
|
|
7114
|
-
if (key.type ===
|
|
7115
|
-
if (key.type ===
|
|
7520
|
+
if (key.type === AST_NODE_TYPES34.Identifier) return key.name;
|
|
7521
|
+
if (key.type === AST_NODE_TYPES34.Literal) return String(key.value);
|
|
7116
7522
|
return "collection";
|
|
7117
7523
|
}
|
|
7118
7524
|
function isArrayType(node) {
|
|
7119
|
-
if (node.type ===
|
|
7120
|
-
return node.type ===
|
|
7525
|
+
if (node.type === AST_NODE_TYPES34.TSArrayType) return true;
|
|
7526
|
+
return node.type === AST_NODE_TYPES34.TSTypeReference && node.typeName.type === AST_NODE_TYPES34.Identifier && ARRAY_TYPE_NAMES.has(node.typeName.name);
|
|
7121
7527
|
}
|
|
7122
7528
|
function isNullishType(node) {
|
|
7123
|
-
return node.type ===
|
|
7529
|
+
return node.type === AST_NODE_TYPES34.TSNullKeyword || node.type === AST_NODE_TYPES34.TSUndefinedKeyword;
|
|
7124
7530
|
}
|
|
7125
7531
|
function isNullableArrayOnly(node) {
|
|
7126
7532
|
const values = node.types.filter((member) => !isNullishType(member));
|
|
7127
7533
|
return values.length > 0 && values.length < node.types.length && values.every(isArrayType);
|
|
7128
7534
|
}
|
|
7129
|
-
var prefer_non_nullable_collection_default =
|
|
7535
|
+
var prefer_non_nullable_collection_default = ESLintUtils47.RuleCreator(
|
|
7130
7536
|
(name) => `https://github.com/sarj-ai/standards/tree/main/packages/typescript#${name}`
|
|
7131
7537
|
)({
|
|
7132
7538
|
name: "prefer-non-nullable-collection",
|
|
@@ -7149,7 +7555,7 @@ var prefer_non_nullable_collection_default = ESLintUtils46.RuleCreator(
|
|
|
7149
7555
|
function checkOptionalProperty(node) {
|
|
7150
7556
|
const annotation = node.typeAnnotation?.typeAnnotation;
|
|
7151
7557
|
if (annotation === void 0) return;
|
|
7152
|
-
if (annotation.type !==
|
|
7558
|
+
if (annotation.type !== AST_NODE_TYPES34.TSUnionType || !isNullableArrayOnly(annotation)) {
|
|
7153
7559
|
return;
|
|
7154
7560
|
}
|
|
7155
7561
|
context.report({
|
|
@@ -7162,7 +7568,7 @@ var prefer_non_nullable_collection_default = ESLintUtils46.RuleCreator(
|
|
|
7162
7568
|
TSPropertySignature: checkOptionalProperty,
|
|
7163
7569
|
PropertyDefinition: checkOptionalProperty,
|
|
7164
7570
|
TSTypeAliasDeclaration(node) {
|
|
7165
|
-
if (node.typeAnnotation.type !==
|
|
7571
|
+
if (node.typeAnnotation.type !== AST_NODE_TYPES34.TSUnionType) return;
|
|
7166
7572
|
if (!isNullableArrayOnly(node.typeAnnotation)) return;
|
|
7167
7573
|
context.report({
|
|
7168
7574
|
node,
|
|
@@ -7175,7 +7581,7 @@ var prefer_non_nullable_collection_default = ESLintUtils46.RuleCreator(
|
|
|
7175
7581
|
});
|
|
7176
7582
|
|
|
7177
7583
|
// src/rules/no-implicit-attribute-access.ts
|
|
7178
|
-
import { AST_NODE_TYPES as
|
|
7584
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES35, ESLintUtils as ESLintUtils48 } from "@typescript-eslint/utils";
|
|
7179
7585
|
var EXCLUDED_BASES = /* @__PURE__ */ new Set([
|
|
7180
7586
|
"environ",
|
|
7181
7587
|
"headers",
|
|
@@ -7191,15 +7597,15 @@ var EXCLUDED_BASES = /* @__PURE__ */ new Set([
|
|
|
7191
7597
|
"sessionStorage"
|
|
7192
7598
|
]);
|
|
7193
7599
|
function getBaseName(node) {
|
|
7194
|
-
if (node.type ===
|
|
7600
|
+
if (node.type === AST_NODE_TYPES35.Identifier) {
|
|
7195
7601
|
return node.name;
|
|
7196
7602
|
}
|
|
7197
|
-
if (node.type ===
|
|
7603
|
+
if (node.type === AST_NODE_TYPES35.MemberExpression && node.property.type === AST_NODE_TYPES35.Identifier) {
|
|
7198
7604
|
return node.property.name;
|
|
7199
7605
|
}
|
|
7200
7606
|
return null;
|
|
7201
7607
|
}
|
|
7202
|
-
var no_implicit_attribute_access_default =
|
|
7608
|
+
var no_implicit_attribute_access_default = ESLintUtils48.RuleCreator(
|
|
7203
7609
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7204
7610
|
)({
|
|
7205
7611
|
name: "no-implicit-attribute-access",
|
|
@@ -7220,7 +7626,7 @@ var no_implicit_attribute_access_default = ESLintUtils47.RuleCreator(
|
|
|
7220
7626
|
if (!node.computed) {
|
|
7221
7627
|
return;
|
|
7222
7628
|
}
|
|
7223
|
-
if (node.property.type ===
|
|
7629
|
+
if (node.property.type === AST_NODE_TYPES35.Literal && typeof node.property.value === "string") {
|
|
7224
7630
|
const baseName = getBaseName(node.object);
|
|
7225
7631
|
if (!baseName || !EXCLUDED_BASES.has(baseName)) {
|
|
7226
7632
|
context.report({
|
|
@@ -7233,11 +7639,11 @@ var no_implicit_attribute_access_default = ESLintUtils47.RuleCreator(
|
|
|
7233
7639
|
},
|
|
7234
7640
|
CallExpression(node) {
|
|
7235
7641
|
const callee = node.callee;
|
|
7236
|
-
if (callee.type ===
|
|
7237
|
-
const method = callee.property.type ===
|
|
7642
|
+
if (callee.type === AST_NODE_TYPES35.MemberExpression) {
|
|
7643
|
+
const method = callee.property.type === AST_NODE_TYPES35.Identifier ? callee.property.name : null;
|
|
7238
7644
|
if (method === "get") {
|
|
7239
7645
|
const arg = node.arguments[0];
|
|
7240
|
-
if (arg && arg.type ===
|
|
7646
|
+
if (arg && arg.type === AST_NODE_TYPES35.Literal && typeof arg.value === "string") {
|
|
7241
7647
|
const baseName = getBaseName(callee.object);
|
|
7242
7648
|
if (!baseName || !EXCLUDED_BASES.has(baseName)) {
|
|
7243
7649
|
context.report({
|
|
@@ -7255,8 +7661,8 @@ var no_implicit_attribute_access_default = ESLintUtils47.RuleCreator(
|
|
|
7255
7661
|
});
|
|
7256
7662
|
|
|
7257
7663
|
// src/rules/strict-test-assertions.ts
|
|
7258
|
-
import { AST_NODE_TYPES as
|
|
7259
|
-
var strict_test_assertions_default =
|
|
7664
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES36, ESLintUtils as ESLintUtils49 } from "@typescript-eslint/utils";
|
|
7665
|
+
var strict_test_assertions_default = ESLintUtils49.RuleCreator.withoutDocs({
|
|
7260
7666
|
meta: {
|
|
7261
7667
|
type: "suggestion",
|
|
7262
7668
|
docs: {
|
|
@@ -7274,9 +7680,9 @@ var strict_test_assertions_default = ESLintUtils48.RuleCreator.withoutDocs({
|
|
|
7274
7680
|
let currentObject = null;
|
|
7275
7681
|
let sequence = [];
|
|
7276
7682
|
function getExpectObject(expr) {
|
|
7277
|
-
if (expr.type ===
|
|
7683
|
+
if (expr.type === AST_NODE_TYPES36.CallExpression && expr.callee.type === AST_NODE_TYPES36.MemberExpression && expr.callee.object.type === AST_NODE_TYPES36.CallExpression && expr.callee.object.callee.type === AST_NODE_TYPES36.Identifier && expr.callee.object.callee.name === "expect" && expr.callee.object.arguments.length === 1) {
|
|
7278
7684
|
const arg = expr.callee.object.arguments.at(0);
|
|
7279
|
-
if (arg?.type ===
|
|
7685
|
+
if (arg?.type === AST_NODE_TYPES36.MemberExpression) {
|
|
7280
7686
|
return arg.object;
|
|
7281
7687
|
}
|
|
7282
7688
|
}
|
|
@@ -7292,12 +7698,12 @@ var strict_test_assertions_default = ESLintUtils48.RuleCreator.withoutDocs({
|
|
|
7292
7698
|
if (!currentObject) return null;
|
|
7293
7699
|
const objectText = context.sourceCode.getText(currentObject);
|
|
7294
7700
|
const props = sequence.map((stmt) => {
|
|
7295
|
-
if (stmt.expression.type !==
|
|
7701
|
+
if (stmt.expression.type !== AST_NODE_TYPES36.CallExpression || stmt.expression.callee.type !== AST_NODE_TYPES36.MemberExpression || stmt.expression.callee.object.type !== AST_NODE_TYPES36.CallExpression) {
|
|
7296
7702
|
return null;
|
|
7297
7703
|
}
|
|
7298
7704
|
const actual = stmt.expression.callee.object.arguments.at(0);
|
|
7299
7705
|
const expected = stmt.expression.arguments.at(0);
|
|
7300
|
-
if (actual?.type ===
|
|
7706
|
+
if (actual?.type === AST_NODE_TYPES36.MemberExpression && actual.property.type === AST_NODE_TYPES36.Identifier && expected) {
|
|
7301
7707
|
const propName2 = actual.property.name;
|
|
7302
7708
|
const valText = context.sourceCode.getText(expected);
|
|
7303
7709
|
return `${propName2}: ${valText}`;
|
|
@@ -7315,7 +7721,7 @@ var strict_test_assertions_default = ESLintUtils48.RuleCreator.withoutDocs({
|
|
|
7315
7721
|
}
|
|
7316
7722
|
}
|
|
7317
7723
|
for (const statement of body) {
|
|
7318
|
-
if (statement.type ===
|
|
7724
|
+
if (statement.type === AST_NODE_TYPES36.ExpressionStatement) {
|
|
7319
7725
|
const obj = getExpectObject(statement.expression);
|
|
7320
7726
|
if (obj && currentObject && context.sourceCode.getText(obj) === context.sourceCode.getText(currentObject)) {
|
|
7321
7727
|
sequence.push(statement);
|
|
@@ -7349,8 +7755,8 @@ var strict_test_assertions_default = ESLintUtils48.RuleCreator.withoutDocs({
|
|
|
7349
7755
|
});
|
|
7350
7756
|
|
|
7351
7757
|
// src/rules/no-async-callback-in-waitfor.ts
|
|
7352
|
-
import { AST_NODE_TYPES as
|
|
7353
|
-
var no_async_callback_in_waitfor_default =
|
|
7758
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES37, ESLintUtils as ESLintUtils50 } from "@typescript-eslint/utils";
|
|
7759
|
+
var no_async_callback_in_waitfor_default = ESLintUtils50.RuleCreator(
|
|
7354
7760
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7355
7761
|
)({
|
|
7356
7762
|
name: "no-async-callback-in-waitfor",
|
|
@@ -7371,9 +7777,9 @@ var no_async_callback_in_waitfor_default = ESLintUtils49.RuleCreator(
|
|
|
7371
7777
|
}
|
|
7372
7778
|
return {
|
|
7373
7779
|
CallExpression(node) {
|
|
7374
|
-
if (node.callee.type ===
|
|
7780
|
+
if (node.callee.type === AST_NODE_TYPES37.Identifier && node.callee.name === "waitFor") {
|
|
7375
7781
|
const callback = node.arguments[0];
|
|
7376
|
-
if (callback && (callback.type ===
|
|
7782
|
+
if (callback && (callback.type === AST_NODE_TYPES37.ArrowFunctionExpression || callback.type === AST_NODE_TYPES37.FunctionExpression) && callback.async) {
|
|
7377
7783
|
context.report({
|
|
7378
7784
|
node: callback,
|
|
7379
7785
|
messageId: "noAsyncCallbackInWaitFor"
|
|
@@ -7386,7 +7792,7 @@ var no_async_callback_in_waitfor_default = ESLintUtils49.RuleCreator(
|
|
|
7386
7792
|
});
|
|
7387
7793
|
|
|
7388
7794
|
// src/rules/no-hand-rolled-sleep.ts
|
|
7389
|
-
import { AST_NODE_TYPES as
|
|
7795
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES38, ESLintUtils as ESLintUtils51 } from "@typescript-eslint/utils";
|
|
7390
7796
|
var GLOBAL_OBJECTS2 = /* @__PURE__ */ new Set([
|
|
7391
7797
|
"globalThis",
|
|
7392
7798
|
"window",
|
|
@@ -7405,66 +7811,66 @@ function matchesAnyPattern3(filename, patterns) {
|
|
|
7405
7811
|
return false;
|
|
7406
7812
|
}
|
|
7407
7813
|
function isSetTimeoutCallee(callee) {
|
|
7408
|
-
if (callee.type ===
|
|
7814
|
+
if (callee.type === AST_NODE_TYPES38.Identifier) {
|
|
7409
7815
|
return callee.name === "setTimeout";
|
|
7410
7816
|
}
|
|
7411
|
-
return callee.type ===
|
|
7817
|
+
return callee.type === AST_NODE_TYPES38.MemberExpression && !callee.computed && callee.property.type === AST_NODE_TYPES38.Identifier && callee.property.name === "setTimeout" && callee.object.type === AST_NODE_TYPES38.Identifier && GLOBAL_OBJECTS2.has(callee.object.name);
|
|
7412
7818
|
}
|
|
7413
7819
|
function soleCall(fn) {
|
|
7414
|
-
if (fn.body.type !==
|
|
7415
|
-
return fn.body.type ===
|
|
7820
|
+
if (fn.body.type !== AST_NODE_TYPES38.BlockStatement) {
|
|
7821
|
+
return fn.body.type === AST_NODE_TYPES38.CallExpression ? fn.body : null;
|
|
7416
7822
|
}
|
|
7417
7823
|
if (fn.body.body.length !== 1) {
|
|
7418
7824
|
return null;
|
|
7419
7825
|
}
|
|
7420
7826
|
const [only] = fn.body.body;
|
|
7421
|
-
if (only?.type !==
|
|
7827
|
+
if (only?.type !== AST_NODE_TYPES38.ExpressionStatement) {
|
|
7422
7828
|
return null;
|
|
7423
7829
|
}
|
|
7424
|
-
return only.expression.type ===
|
|
7830
|
+
return only.expression.type === AST_NODE_TYPES38.CallExpression ? only.expression : null;
|
|
7425
7831
|
}
|
|
7426
7832
|
function isTimedDelay(delay) {
|
|
7427
7833
|
if (delay === void 0) {
|
|
7428
7834
|
return false;
|
|
7429
7835
|
}
|
|
7430
|
-
if (delay.type ===
|
|
7836
|
+
if (delay.type === AST_NODE_TYPES38.Literal && typeof delay.value === "number") {
|
|
7431
7837
|
return delay.value !== 0;
|
|
7432
7838
|
}
|
|
7433
7839
|
return true;
|
|
7434
7840
|
}
|
|
7435
7841
|
function settlesWithoutValue(callback, name) {
|
|
7436
|
-
if (callback.type ===
|
|
7842
|
+
if (callback.type === AST_NODE_TYPES38.Identifier) {
|
|
7437
7843
|
return callback.name === name;
|
|
7438
7844
|
}
|
|
7439
|
-
if (callback.type !==
|
|
7845
|
+
if (callback.type !== AST_NODE_TYPES38.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES38.FunctionExpression) {
|
|
7440
7846
|
return false;
|
|
7441
7847
|
}
|
|
7442
7848
|
const call = soleCall(callback);
|
|
7443
|
-
return call !== null && call.arguments.length === 0 && call.callee.type ===
|
|
7849
|
+
return call !== null && call.arguments.length === 0 && call.callee.type === AST_NODE_TYPES38.Identifier && call.callee.name === name;
|
|
7444
7850
|
}
|
|
7445
7851
|
function rejectsInCallback(callback, name) {
|
|
7446
|
-
if (callback.type ===
|
|
7852
|
+
if (callback.type === AST_NODE_TYPES38.Identifier) {
|
|
7447
7853
|
return callback.name === name;
|
|
7448
7854
|
}
|
|
7449
|
-
if (callback.type !==
|
|
7855
|
+
if (callback.type !== AST_NODE_TYPES38.ArrowFunctionExpression && callback.type !== AST_NODE_TYPES38.FunctionExpression) {
|
|
7450
7856
|
return false;
|
|
7451
7857
|
}
|
|
7452
7858
|
const call = soleCall(callback);
|
|
7453
|
-
return call !== null && call.callee.type ===
|
|
7859
|
+
return call !== null && call.callee.type === AST_NODE_TYPES38.Identifier && call.callee.name === name;
|
|
7454
7860
|
}
|
|
7455
7861
|
function parameterName(fn, index) {
|
|
7456
7862
|
const parameter = fn.params[index];
|
|
7457
|
-
return parameter?.type ===
|
|
7863
|
+
return parameter?.type === AST_NODE_TYPES38.Identifier ? parameter.name : null;
|
|
7458
7864
|
}
|
|
7459
7865
|
function isRaceArm(node) {
|
|
7460
7866
|
const array = node.parent;
|
|
7461
|
-
if (array?.type !==
|
|
7867
|
+
if (array?.type !== AST_NODE_TYPES38.ArrayExpression) {
|
|
7462
7868
|
return false;
|
|
7463
7869
|
}
|
|
7464
7870
|
const call = array.parent;
|
|
7465
|
-
return call?.type ===
|
|
7871
|
+
return call?.type === AST_NODE_TYPES38.CallExpression && call.arguments[0] === array && call.callee.type === AST_NODE_TYPES38.MemberExpression && !call.callee.computed && call.callee.object.type === AST_NODE_TYPES38.Identifier && call.callee.object.name === "Promise" && call.callee.property.type === AST_NODE_TYPES38.Identifier && RACE_METHODS.has(call.callee.property.name);
|
|
7466
7872
|
}
|
|
7467
|
-
var no_hand_rolled_sleep_default =
|
|
7873
|
+
var no_hand_rolled_sleep_default = ESLintUtils51.RuleCreator(
|
|
7468
7874
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7469
7875
|
)({
|
|
7470
7876
|
name: "no-hand-rolled-sleep",
|
|
@@ -7512,10 +7918,10 @@ var no_hand_rolled_sleep_default = ESLintUtils50.RuleCreator(
|
|
|
7512
7918
|
}
|
|
7513
7919
|
const program = sourceCode.ast;
|
|
7514
7920
|
for (const statement of program.body) {
|
|
7515
|
-
if (statement.type ===
|
|
7921
|
+
if (statement.type === AST_NODE_TYPES38.ExpressionStatement && statement.expression.type === AST_NODE_TYPES38.Literal && statement.expression.value === "use client") {
|
|
7516
7922
|
return true;
|
|
7517
7923
|
}
|
|
7518
|
-
if (statement.type ===
|
|
7924
|
+
if (statement.type === AST_NODE_TYPES38.ImportDeclaration && typeof statement.source.value === "string" && CLIENT_ONLY_MODULES.test(statement.source.value)) {
|
|
7519
7925
|
return true;
|
|
7520
7926
|
}
|
|
7521
7927
|
}
|
|
@@ -7531,11 +7937,11 @@ var no_hand_rolled_sleep_default = ESLintUtils50.RuleCreator(
|
|
|
7531
7937
|
};
|
|
7532
7938
|
return {
|
|
7533
7939
|
NewExpression(node) {
|
|
7534
|
-
if (node.callee.type !==
|
|
7940
|
+
if (node.callee.type !== AST_NODE_TYPES38.Identifier || node.callee.name !== "Promise") {
|
|
7535
7941
|
return;
|
|
7536
7942
|
}
|
|
7537
7943
|
const executor = node.arguments[0];
|
|
7538
|
-
if (executor?.type !==
|
|
7944
|
+
if (executor?.type !== AST_NODE_TYPES38.ArrowFunctionExpression && executor?.type !== AST_NODE_TYPES38.FunctionExpression) {
|
|
7539
7945
|
return;
|
|
7540
7946
|
}
|
|
7541
7947
|
const call = soleCall(executor);
|
|
@@ -7563,8 +7969,8 @@ var no_hand_rolled_sleep_default = ESLintUtils50.RuleCreator(
|
|
|
7563
7969
|
});
|
|
7564
7970
|
|
|
7565
7971
|
// src/rules/prefer-setup-file-mocks.ts
|
|
7566
|
-
import { AST_NODE_TYPES as
|
|
7567
|
-
var prefer_setup_file_mocks_default =
|
|
7972
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES39, ESLintUtils as ESLintUtils52 } from "@typescript-eslint/utils";
|
|
7973
|
+
var prefer_setup_file_mocks_default = ESLintUtils52.RuleCreator(
|
|
7568
7974
|
(name) => `https://github.com/sarj-ai/standards/blob/main/packages/typescript/src/rules/${name}.ts`
|
|
7569
7975
|
)({
|
|
7570
7976
|
name: "prefer-setup-file-mocks",
|
|
@@ -7585,7 +7991,7 @@ var prefer_setup_file_mocks_default = ESLintUtils51.RuleCreator(
|
|
|
7585
7991
|
}
|
|
7586
7992
|
return {
|
|
7587
7993
|
CallExpression(node) {
|
|
7588
|
-
if (node.callee.type ===
|
|
7994
|
+
if (node.callee.type === AST_NODE_TYPES39.MemberExpression && node.callee.object.type === AST_NODE_TYPES39.Identifier && (node.callee.object.name === "vi" || node.callee.object.name === "jest") && node.callee.property.type === AST_NODE_TYPES39.Identifier && node.callee.property.name === "mock") {
|
|
7589
7995
|
context.report({
|
|
7590
7996
|
node,
|
|
7591
7997
|
messageId: "preferSetupFileMocks"
|
|
@@ -7623,6 +8029,7 @@ var rules = {
|
|
|
7623
8029
|
"no-unsafe-mock-casting": no_unsafe_mock_casting_default,
|
|
7624
8030
|
"prefer-string-literal-union": prefer_string_literal_union_default,
|
|
7625
8031
|
"prefer-zod-enum": prefer_zod_enum_default,
|
|
8032
|
+
"prefer-zod-infer": prefer_zod_infer_default,
|
|
7626
8033
|
"no-silent-promise-catch": no_silent_promise_catch_default,
|
|
7627
8034
|
"require-fetch-timeout": require_fetch_timeout_default,
|
|
7628
8035
|
"no-offset-pagination": no_offset_pagination_default,
|
|
@@ -7653,7 +8060,7 @@ var rules = {
|
|
|
7653
8060
|
var plugin = {
|
|
7654
8061
|
meta: {
|
|
7655
8062
|
name: "@sarj/eslint-plugin",
|
|
7656
|
-
version: "4.
|
|
8063
|
+
version: "4.2.0"
|
|
7657
8064
|
},
|
|
7658
8065
|
rules,
|
|
7659
8066
|
configs: {
|
|
@@ -7689,6 +8096,11 @@ var plugin = {
|
|
|
7689
8096
|
"@sarj/no-unsafe-mock-casting": "warn",
|
|
7690
8097
|
"@sarj/prefer-string-literal-union": "warn",
|
|
7691
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",
|
|
7692
8104
|
// Mined from 2y of PR review feedback + 5-repo code-smell audit (2026-07).
|
|
7693
8105
|
"@sarj/require-fetch-timeout": "warn",
|
|
7694
8106
|
"@sarj/no-silent-promise-catch": "warn",
|
|
@@ -7784,6 +8196,8 @@ var plugin = {
|
|
|
7784
8196
|
// Promoted to error 2026-07-25 — strict means strict (user directive).
|
|
7785
8197
|
"@sarj/prefer-string-literal-union": "error",
|
|
7786
8198
|
"@sarj/prefer-zod-enum": "error",
|
|
8199
|
+
// See the `recommended` block for the measured counts.
|
|
8200
|
+
"@sarj/prefer-zod-infer": "error",
|
|
7787
8201
|
// Mined from 2y of PR review feedback + 5-repo code-smell audit (2026-07).
|
|
7788
8202
|
"@sarj/require-fetch-timeout": "error",
|
|
7789
8203
|
"@sarj/no-silent-promise-catch": "error",
|