@harness-engineering/eslint-plugin 0.2.2 → 0.2.3

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.
Files changed (2) hide show
  1. package/dist/index.js +66 -55
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -23,34 +23,41 @@ function hasJSDocComment(node, sourceCode) {
23
23
  }
24
24
  return foundJSDoc;
25
25
  }
26
+ var SKIP_KEYS = /* @__PURE__ */ new Set(["parent", "loc", "range", "tokens", "comments"]);
27
+ var ZOD_PARSE_METHODS = /* @__PURE__ */ new Set(["parse", "safeParse"]);
28
+ function isZodParseCall(node) {
29
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
30
+ const callee = node.callee;
31
+ if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
32
+ const prop = callee.property;
33
+ if (prop.type !== AST_NODE_TYPES.Identifier) return false;
34
+ return ZOD_PARSE_METHODS.has(prop.name);
35
+ }
36
+ function visitChildren(node, visitor) {
37
+ for (const key of Object.keys(node)) {
38
+ if (SKIP_KEYS.has(key)) continue;
39
+ const value = node[key];
40
+ if (!value || typeof value !== "object") continue;
41
+ if (Array.isArray(value)) {
42
+ for (const item of value) {
43
+ if (item && typeof item === "object" && "type" in item) {
44
+ visitor(item);
45
+ }
46
+ }
47
+ } else if ("type" in value) {
48
+ visitor(value);
49
+ }
50
+ }
51
+ }
26
52
  function hasZodValidation(body) {
27
53
  let found = false;
28
- const skipKeys = /* @__PURE__ */ new Set(["parent", "loc", "range", "tokens", "comments"]);
29
54
  function visit(node) {
30
55
  if (found) return;
31
- if (node.type === AST_NODE_TYPES.CallExpression && node.callee.type === AST_NODE_TYPES.MemberExpression) {
32
- const prop = node.callee.property;
33
- const propType = prop.type;
34
- if (propType === AST_NODE_TYPES.Identifier && (prop.name === "parse" || prop.name === "safeParse")) {
35
- found = true;
36
- return;
37
- }
38
- }
39
- for (const key of Object.keys(node)) {
40
- if (skipKeys.has(key)) continue;
41
- const value = node[key];
42
- if (value && typeof value === "object") {
43
- if (Array.isArray(value)) {
44
- for (const item of value) {
45
- if (item && typeof item === "object" && "type" in item) {
46
- visit(item);
47
- }
48
- }
49
- } else if ("type" in value) {
50
- visit(value);
51
- }
52
- }
56
+ if (isZodParseCall(node)) {
57
+ found = true;
58
+ return;
53
59
  }
60
+ visitChildren(node, visit);
54
61
  }
55
62
  visit(body);
56
63
  return found;
@@ -106,30 +113,34 @@ var enforce_doc_exports_default = createRule({
106
113
  });
107
114
  }
108
115
  }
116
+ function getExportInfo(decl) {
117
+ const declType = decl.type;
118
+ if (declType === AST_NODE_TYPES2.FunctionDeclaration) {
119
+ const fn = decl;
120
+ return fn.id ? [{ kind: "function", name: fn.id.name }] : [];
121
+ }
122
+ if (declType === AST_NODE_TYPES2.ClassDeclaration) {
123
+ const cls = decl;
124
+ return cls.id ? [{ kind: "class", name: cls.id.name }] : [];
125
+ }
126
+ if (declType === AST_NODE_TYPES2.VariableDeclaration) {
127
+ const varDecl = decl;
128
+ return varDecl.declarations.filter((d) => d.id.type === AST_NODE_TYPES2.Identifier).map((d) => ({ kind: "variable", name: d.id.name }));
129
+ }
130
+ if (declType === AST_NODE_TYPES2.TSTypeAliasDeclaration && !options.ignoreTypes) {
131
+ return [{ kind: "type", name: decl.id.name }];
132
+ }
133
+ if (declType === AST_NODE_TYPES2.TSInterfaceDeclaration && !options.ignoreTypes) {
134
+ return [{ kind: "interface", name: decl.id.name }];
135
+ }
136
+ return [];
137
+ }
109
138
  return {
110
139
  ExportNamedDeclaration(node) {
111
140
  const decl = node.declaration;
112
141
  if (!decl) return;
113
- const declType = decl.type;
114
- if (declType === AST_NODE_TYPES2.FunctionDeclaration) {
115
- const fn = decl;
116
- if (fn.id) checkExport(node, "function", fn.id.name);
117
- } else if (declType === AST_NODE_TYPES2.ClassDeclaration) {
118
- const cls = decl;
119
- if (cls.id) checkExport(node, "class", cls.id.name);
120
- } else if (declType === AST_NODE_TYPES2.VariableDeclaration) {
121
- const varDecl = decl;
122
- for (const declarator of varDecl.declarations) {
123
- if (declarator.id.type === AST_NODE_TYPES2.Identifier) {
124
- checkExport(node, "variable", declarator.id.name);
125
- }
126
- }
127
- } else if (declType === AST_NODE_TYPES2.TSTypeAliasDeclaration && !options.ignoreTypes) {
128
- const typeAlias = decl;
129
- checkExport(node, "type", typeAlias.id.name);
130
- } else if (declType === AST_NODE_TYPES2.TSInterfaceDeclaration && !options.ignoreTypes) {
131
- const iface = decl;
132
- checkExport(node, "interface", iface.id.name);
142
+ for (const info of getExportInfo(decl)) {
143
+ checkExport(node, info.kind, info.name);
133
144
  }
134
145
  }
135
146
  };
@@ -819,21 +830,21 @@ function isImportOrRequire(node) {
819
830
  }
820
831
  return false;
821
832
  }
833
+ function isMemberCall(callee, objectNames, methods) {
834
+ return callee.object.type === "Identifier" && objectNames.has(callee.object.name) && callee.property.type === "Identifier" && methods.has(callee.property.name);
835
+ }
836
+ var PATH_OBJECTS = /* @__PURE__ */ new Set(["path"]);
837
+ var FS_OBJECTS = /* @__PURE__ */ new Set(["fs", "fsp"]);
822
838
  function isInFlaggedContext(node) {
823
839
  const parent = node.parent;
824
840
  if (!parent) return false;
825
- if (parent.type === "CallExpression") {
826
- const callee = parent.callee;
827
- if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && callee.object.name === "path" && callee.property.type === "Identifier" && PATH_METHODS.has(callee.property.name)) {
828
- return true;
829
- }
830
- if (callee.type === "MemberExpression" && callee.object.type === "Identifier" && (callee.object.name === "fs" || callee.object.name === "fsp") && callee.property.type === "Identifier" && FS_METHODS.has(callee.property.name)) {
831
- return true;
832
- }
833
- if (callee.type === "MemberExpression" && callee.property.type === "Identifier" && STRING_METHODS.has(callee.property.name)) {
834
- return true;
835
- }
836
- return false;
841
+ if (parent.type !== "CallExpression") return false;
842
+ const callee = parent.callee;
843
+ if (callee.type !== "MemberExpression") return false;
844
+ if (isMemberCall(callee, PATH_OBJECTS, PATH_METHODS)) return true;
845
+ if (isMemberCall(callee, FS_OBJECTS, FS_METHODS)) return true;
846
+ if (callee.property.type === "Identifier" && STRING_METHODS.has(callee.property.name)) {
847
+ return true;
837
848
  }
838
849
  return false;
839
850
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harness-engineering/eslint-plugin",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "ESLint plugin for harness engineering architectural constraints",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",