@clipboard-health/eslint-plugin 0.2.0 → 0.4.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,11 +1,14 @@
1
1
  {
2
2
  "name": "@clipboard-health/eslint-plugin",
3
3
  "description": "Clipboard's ESLint Plugin",
4
- "version": "0.2.0",
4
+ "version": "0.4.0",
5
5
  "dependencies": {
6
6
  "@typescript-eslint/utils": "8.33.0",
7
7
  "tslib": "2.8.1"
8
8
  },
9
+ "devDependencies": {
10
+ "@typescript-eslint/parser": "7.18.0"
11
+ },
9
12
  "keywords": [
10
13
  "eslint",
11
14
  "plugin"
package/src/index.d.ts CHANGED
@@ -1,3 +1,4 @@
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
+ "require-http-module-factory": import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"requireFactory" | "wrongPackage" | "noImport", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
3
4
  };
package/src/index.js CHANGED
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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
+ const require_http_module_factory_1 = tslib_1.__importDefault(require("./lib/rules/require-http-module-factory"));
6
7
  exports.rules = {
7
8
  "enforce-ts-rest-in-controllers": enforce_ts_rest_in_controllers_1.default,
9
+ "require-http-module-factory": require_http_module_factory_1.default,
8
10
  };
9
11
  //# 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;AAEvE,QAAA,KAAK,GAAG;IACnB,gCAAgC,EAAE,wCAA0B;CAC7D,CAAC"}
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"}
@@ -0,0 +1,2 @@
1
+ declare const rule: import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<"requireFactory" | "wrongPackage" | "noImport", [], unknown, import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>;
2
+ export default rule;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /**
5
+ * @fileoverview Rule to require HttpModule to use registerAsync factory to avoid shared axios client issues
6
+ */
7
+ const utils_1 = require("@typescript-eslint/utils");
8
+ const createRule_1 = tslib_1.__importDefault(require("../../createRule"));
9
+ const isHttpModuleImport = (spec) => spec.type === utils_1.AST_NODE_TYPES.ImportSpecifier &&
10
+ spec.imported.type === utils_1.AST_NODE_TYPES.Identifier &&
11
+ spec.imported.name === "HttpModule";
12
+ const isImportsArray = (node) => {
13
+ const { parent } = node;
14
+ return (parent?.type === utils_1.AST_NODE_TYPES.Property &&
15
+ parent.key?.type === utils_1.AST_NODE_TYPES.Identifier &&
16
+ parent.key.name === "imports" &&
17
+ parent.value === node);
18
+ };
19
+ const rule = (0, createRule_1.default)({
20
+ name: "require-http-module-factory",
21
+ defaultOptions: [],
22
+ meta: {
23
+ type: "problem",
24
+ docs: {
25
+ description: "Require HttpModule to use registerAsync factory to avoid shared axios client issues",
26
+ },
27
+ schema: [],
28
+ messages: {
29
+ requireFactory: "HttpModule must use .registerAsync() with a custom factory to create a new axios client instance. Direct HttpModule imports share the global axios client and can cause interceptor conflicts.",
30
+ wrongPackage: "HttpModule must be imported from '@nestjs/axios' package. Using HttpModule from other packages may not provide the expected factory methods.",
31
+ noImport: "HttpModule is used but not imported from '@nestjs/axios'. Import HttpModule and use .registerAsync() with a custom factory.",
32
+ },
33
+ },
34
+ create(context) {
35
+ let httpModuleImportedCorrectly = false;
36
+ let httpModuleImportName;
37
+ const checkHttpModuleUsage = (element) => {
38
+ if (!element || element.type !== utils_1.AST_NODE_TYPES.Identifier) {
39
+ return;
40
+ }
41
+ const isDirectHttpModule = element.name === "HttpModule";
42
+ const isAliasedHttpModule = httpModuleImportedCorrectly && element.name === httpModuleImportName;
43
+ if (isDirectHttpModule) {
44
+ const messageId = httpModuleImportedCorrectly ? "requireFactory" : "noImport";
45
+ context.report({ node: element, messageId });
46
+ }
47
+ else if (isAliasedHttpModule) {
48
+ context.report({ node: element, messageId: "requireFactory" });
49
+ }
50
+ };
51
+ return {
52
+ ImportDeclaration(node) {
53
+ if (node.source.value !== "@nestjs/axios") {
54
+ return;
55
+ }
56
+ for (const spec of node.specifiers) {
57
+ if (isHttpModuleImport(spec)) {
58
+ httpModuleImportedCorrectly = true;
59
+ httpModuleImportName = spec.local.name;
60
+ }
61
+ }
62
+ },
63
+ ArrayExpression(node) {
64
+ if (!isImportsArray(node)) {
65
+ return;
66
+ }
67
+ for (const element of node.elements) {
68
+ checkHttpModuleUsage(element);
69
+ }
70
+ },
71
+ };
72
+ },
73
+ });
74
+ exports.default = rule;
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/eslint-plugin/src/lib/rules/require-http-module-factory/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,oDAAyE;AAEzE,0EAA0C;AAE1C,MAAM,kBAAkB,GAAG,CAAC,IAA2B,EAAW,EAAE,CAClE,IAAI,CAAC,IAAI,KAAK,sBAAc,CAAC,eAAe;IAC5C,IAAI,CAAC,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