@clipboard-health/eslint-plugin 1.4.3 → 1.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipboard-health/eslint-plugin",
3
3
  "description": "Clipboard's ESLint Plugin",
4
- "version": "1.4.3",
4
+ "version": "1.5.0",
5
5
  "dependencies": {
6
6
  "@typescript-eslint/utils": "8.33.0",
7
7
  "tslib": "2.8.1"
package/src/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare const rules: {
2
2
  "enforce-ts-rest-in-controllers": import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingDecorator" | "missingReturn" | "decoratorNotFromPackage" | "callNotFromPackage", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
3
3
  "require-http-module-factory": import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"requireFactory" | "wrongPackage" | "noImport", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
4
+ "require-run-validators-with-upsert": import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingRunValidators" | "runValidatorsFalse", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
4
5
  };
package/src/index.js CHANGED
@@ -4,8 +4,10 @@ exports.rules = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const enforce_ts_rest_in_controllers_1 = tslib_1.__importDefault(require("./lib/rules/enforce-ts-rest-in-controllers"));
6
6
  const require_http_module_factory_1 = tslib_1.__importDefault(require("./lib/rules/require-http-module-factory"));
7
+ const require_run_validators_with_upsert_1 = tslib_1.__importDefault(require("./lib/rules/require-run-validators-with-upsert"));
7
8
  exports.rules = {
8
9
  "enforce-ts-rest-in-controllers": enforce_ts_rest_in_controllers_1.default,
9
10
  "require-http-module-factory": require_http_module_factory_1.default,
11
+ "require-run-validators-with-upsert": require_run_validators_with_upsert_1.default,
10
12
  };
11
13
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/eslint-plugin/src/index.ts"],"names":[],"mappings":";;;;AAAA,wHAAoF;AACpF,kHAA+E;AAElE,QAAA,KAAK,GAAG;IACnB,gCAAgC,EAAE,wCAA0B;IAC5D,6BAA6B,EAAE,qCAAwB;CACxD,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/eslint-plugin/src/index.ts"],"names":[],"mappings":";;;;AAAA,wHAAoF;AACpF,kHAA+E;AAC/E,gIAA4F;AAE/E,QAAA,KAAK,GAAG;IACnB,gCAAgC,EAAE,wCAA0B;IAC5D,6BAA6B,EAAE,qCAAwB;IACvD,oCAAoC,EAAE,4CAA8B;CACrE,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare const rule: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"missingRunValidators" | "runValidatorsFalse", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
2
+ export default rule;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /**
5
+ * @fileoverview Rule to require runValidators: true when upsert: true is used in Mongoose operations
6
+ */
7
+ const utils_1 = require("@typescript-eslint/utils");
8
+ const createRule_1 = tslib_1.__importDefault(require("../../createRule"));
9
+ const UPSERT_METHODS = new Set([
10
+ "updateOne",
11
+ "updateMany",
12
+ "findOneAndUpdate",
13
+ "findByIdAndUpdate",
14
+ "findOneAndReplace",
15
+ "replaceOne",
16
+ ]);
17
+ const hasPropertyWithValue = (property, name, value) => property.type === utils_1.AST_NODE_TYPES.Property &&
18
+ property.key.type === utils_1.AST_NODE_TYPES.Identifier &&
19
+ property.key.name === name &&
20
+ property.value.type === utils_1.AST_NODE_TYPES.Literal &&
21
+ property.value.value === value;
22
+ const findProperty = (objectExpression, name) => objectExpression.properties.find((property) => property.type === utils_1.AST_NODE_TYPES.Property &&
23
+ property.key.type === utils_1.AST_NODE_TYPES.Identifier &&
24
+ property.key.name === name);
25
+ const hasUpsertTrue = (objectExpression) => objectExpression.properties.some((property) => hasPropertyWithValue(property, "upsert", true));
26
+ const hasRunValidatorsTrue = (objectExpression) => objectExpression.properties.some((property) => hasPropertyWithValue(property, "runValidators", true));
27
+ const hasRunValidatorsFalse = (objectExpression) => objectExpression.properties.some((property) => hasPropertyWithValue(property, "runValidators", false));
28
+ const hasRunValidatorsProperty = (objectExpression) => objectExpression.properties.some((property) => property.type === utils_1.AST_NODE_TYPES.Property &&
29
+ property.key.type === utils_1.AST_NODE_TYPES.Identifier &&
30
+ property.key.name === "runValidators");
31
+ const rule = (0, createRule_1.default)({
32
+ name: "require-run-validators-with-upsert",
33
+ defaultOptions: [],
34
+ meta: {
35
+ type: "problem",
36
+ docs: {
37
+ description: "Require runValidators: true when upsert: true is used in Mongoose update operations",
38
+ },
39
+ schema: [],
40
+ messages: {
41
+ missingRunValidators: "Mongoose upsert operations must include 'runValidators: true' to ensure schema validation on inserted documents. Add 'runValidators: true' to the options object.",
42
+ runValidatorsFalse: "Mongoose upsert operations should not have 'runValidators: false'. Schema validation should be enabled for upserts to ensure data integrity.",
43
+ },
44
+ },
45
+ create(context) {
46
+ return {
47
+ CallExpression(node) {
48
+ if (node.callee.type !== utils_1.AST_NODE_TYPES.MemberExpression) {
49
+ return;
50
+ }
51
+ const { property } = node.callee;
52
+ if (property.type !== utils_1.AST_NODE_TYPES.Identifier) {
53
+ return;
54
+ }
55
+ const methodName = property.name;
56
+ if (!UPSERT_METHODS.has(methodName)) {
57
+ return;
58
+ }
59
+ for (const argument of node.arguments) {
60
+ if (argument.type !== utils_1.AST_NODE_TYPES.ObjectExpression) {
61
+ continue;
62
+ }
63
+ if (!hasUpsertTrue(argument)) {
64
+ continue;
65
+ }
66
+ if (hasRunValidatorsTrue(argument)) {
67
+ continue;
68
+ }
69
+ if (hasRunValidatorsFalse(argument)) {
70
+ const runValidatorsProperty = findProperty(argument, "runValidators");
71
+ if (runValidatorsProperty) {
72
+ context.report({
73
+ node: runValidatorsProperty,
74
+ messageId: "runValidatorsFalse",
75
+ });
76
+ }
77
+ continue;
78
+ }
79
+ // If runValidators is present with a non-literal value (e.g., a variable),
80
+ // we consider it valid since the developer is explicitly setting it
81
+ if (hasRunValidatorsProperty(argument)) {
82
+ continue;
83
+ }
84
+ // runValidators is missing
85
+ const upsertProperty = findProperty(argument, "upsert");
86
+ if (upsertProperty) {
87
+ context.report({
88
+ node: upsertProperty,
89
+ messageId: "missingRunValidators",
90
+ });
91
+ }
92
+ }
93
+ },
94
+ };
95
+ },
96
+ });
97
+ exports.default = rule;
98
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/eslint-plugin/src/lib/rules/require-run-validators-with-upsert/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,oDAAyE;AAEzE,0EAA0C;AAE1C,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,WAAW;IACX,YAAY;IACZ,kBAAkB;IAClB,mBAAmB;IACnB,mBAAmB;IACnB,YAAY;CACb,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,CAC3B,QAAuC,EACvC,IAAY,EACZ,KAAc,EACL,EAAE,CACX,QAAQ,CAAC,IAAI,KAAK,sBAAc,CAAC,QAAQ;IACzC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,sBAAc,CAAC,UAAU;IAC/C,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI;IAC1B,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,sBAAc,CAAC,OAAO;IAC9C,QAAQ,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC;AAEjC,MAAM,YAAY,GAAG,CACnB,gBAA2C,EAC3C,IAAY,EACmB,EAAE,CACjC,gBAAgB,CAAC,UA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