@ngrx/eslint-plugin 14.0.0-beta.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.
Files changed (130) hide show
  1. package/jest.config.js +22 -0
  2. package/jest.config.js.map +1 -0
  3. package/migrations/migration.json +3 -0
  4. package/package.json +51 -0
  5. package/schematics/collection.json +10 -0
  6. package/schematics/ng-add/index.js +51 -0
  7. package/schematics/ng-add/index.js.map +1 -0
  8. package/schematics/ng-add/schema.js +3 -0
  9. package/schematics/ng-add/schema.js.map +1 -0
  10. package/schematics/ng-add/schema.json +87 -0
  11. package/scripts/generate-config.js +85 -0
  12. package/scripts/generate-config.js.map +1 -0
  13. package/scripts/generate-docs.js +90 -0
  14. package/scripts/generate-docs.js.map +1 -0
  15. package/scripts/generate-overview.js +98 -0
  16. package/scripts/generate-overview.js.map +1 -0
  17. package/spec/utils/index.js +22 -0
  18. package/spec/utils/index.js.map +1 -0
  19. package/src/configs/all-requiring-type-checking.js +46 -0
  20. package/src/configs/all-requiring-type-checking.js.map +1 -0
  21. package/src/configs/all.js +39 -0
  22. package/src/configs/all.js.map +1 -0
  23. package/src/configs/component-store-strict.js +11 -0
  24. package/src/configs/component-store-strict.js.map +1 -0
  25. package/src/configs/component-store.js +11 -0
  26. package/src/configs/component-store.js.map +1 -0
  27. package/src/configs/effects-requiring-type-checking.js +27 -0
  28. package/src/configs/effects-requiring-type-checking.js.map +1 -0
  29. package/src/configs/effects-strict-requiring-type-checking.js +27 -0
  30. package/src/configs/effects-strict-requiring-type-checking.js.map +1 -0
  31. package/src/configs/effects-strict.js +20 -0
  32. package/src/configs/effects-strict.js.map +1 -0
  33. package/src/configs/effects.js +20 -0
  34. package/src/configs/effects.js.map +1 -0
  35. package/src/configs/index.js +33 -0
  36. package/src/configs/index.js.map +1 -0
  37. package/src/configs/recommended-requiring-type-checking.js +46 -0
  38. package/src/configs/recommended-requiring-type-checking.js.map +1 -0
  39. package/src/configs/recommended.js +39 -0
  40. package/src/configs/recommended.js.map +1 -0
  41. package/src/configs/store-strict.js +30 -0
  42. package/src/configs/store-strict.js.map +1 -0
  43. package/src/configs/store.js +30 -0
  44. package/src/configs/store.js.map +1 -0
  45. package/src/configs/strict-requiring-type-checking.js +46 -0
  46. package/src/configs/strict-requiring-type-checking.js.map +1 -0
  47. package/src/configs/strict.js +39 -0
  48. package/src/configs/strict.js.map +1 -0
  49. package/src/index.js +8 -0
  50. package/src/index.js.map +1 -0
  51. package/src/rule-creator.js +29 -0
  52. package/src/rule-creator.js.map +1 -0
  53. package/src/rules/component-store/updater-explicit-return-type.js +69 -0
  54. package/src/rules/component-store/updater-explicit-return-type.js.map +1 -0
  55. package/src/rules/effects/avoid-cyclic-effects.js +202 -0
  56. package/src/rules/effects/avoid-cyclic-effects.js.map +1 -0
  57. package/src/rules/effects/no-dispatch-in-effects.js +83 -0
  58. package/src/rules/effects/no-dispatch-in-effects.js.map +1 -0
  59. package/src/rules/effects/no-effect-decorator-and-creator.js +107 -0
  60. package/src/rules/effects/no-effect-decorator-and-creator.js.map +1 -0
  61. package/src/rules/effects/no-effect-decorator.js +124 -0
  62. package/src/rules/effects/no-effect-decorator.js.map +1 -0
  63. package/src/rules/effects/no-effects-in-providers.js +105 -0
  64. package/src/rules/effects/no-effects-in-providers.js.map +1 -0
  65. package/src/rules/effects/no-multiple-actions-in-effects.js +77 -0
  66. package/src/rules/effects/no-multiple-actions-in-effects.js.map +1 -0
  67. package/src/rules/effects/prefer-action-creator-in-of-type.js +58 -0
  68. package/src/rules/effects/prefer-action-creator-in-of-type.js.map +1 -0
  69. package/src/rules/effects/prefer-concat-latest-from.js +153 -0
  70. package/src/rules/effects/prefer-concat-latest-from.js.map +1 -0
  71. package/src/rules/effects/prefer-effect-callback-in-block-statement.js +99 -0
  72. package/src/rules/effects/prefer-effect-callback-in-block-statement.js.map +1 -0
  73. package/src/rules/effects/use-effects-lifecycle-interface.js +88 -0
  74. package/src/rules/effects/use-effects-lifecycle-interface.js.map +1 -0
  75. package/src/rules/index.js +59 -0
  76. package/src/rules/index.js.map +1 -0
  77. package/src/rules/store/avoid-combining-selectors.js +65 -0
  78. package/src/rules/store/avoid-combining-selectors.js.map +1 -0
  79. package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js +95 -0
  80. package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js.map +1 -0
  81. package/src/rules/store/avoid-duplicate-actions-in-reducer.js +150 -0
  82. package/src/rules/store/avoid-duplicate-actions-in-reducer.js.map +1 -0
  83. package/src/rules/store/avoid-mapping-selectors.js +82 -0
  84. package/src/rules/store/avoid-mapping-selectors.js.map +1 -0
  85. package/src/rules/store/good-action-hygiene.js +84 -0
  86. package/src/rules/store/good-action-hygiene.js.map +1 -0
  87. package/src/rules/store/no-multiple-global-stores.js +157 -0
  88. package/src/rules/store/no-multiple-global-stores.js.map +1 -0
  89. package/src/rules/store/no-reducer-in-key-names.js +76 -0
  90. package/src/rules/store/no-reducer-in-key-names.js.map +1 -0
  91. package/src/rules/store/no-store-subscription.js +64 -0
  92. package/src/rules/store/no-store-subscription.js.map +1 -0
  93. package/src/rules/store/no-typed-global-store.js +101 -0
  94. package/src/rules/store/no-typed-global-store.js.map +1 -0
  95. package/src/rules/store/on-function-explicit-return-type.js +106 -0
  96. package/src/rules/store/on-function-explicit-return-type.js.map +1 -0
  97. package/src/rules/store/prefer-action-creator-in-dispatch.js +70 -0
  98. package/src/rules/store/prefer-action-creator-in-dispatch.js.map +1 -0
  99. package/src/rules/store/prefer-action-creator.js +58 -0
  100. package/src/rules/store/prefer-action-creator.js.map +1 -0
  101. package/src/rules/store/prefer-inline-action-props.js +72 -0
  102. package/src/rules/store/prefer-inline-action-props.js.map +1 -0
  103. package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js +93 -0
  104. package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js.map +1 -0
  105. package/src/rules/store/prefer-selector-in-select.js +93 -0
  106. package/src/rules/store/prefer-selector-in-select.js.map +1 -0
  107. package/src/rules/store/prefix-selectors-with-select.js +107 -0
  108. package/src/rules/store/prefix-selectors-with-select.js.map +1 -0
  109. package/src/rules/store/select-style.js +196 -0
  110. package/src/rules/store/select-style.js.map +1 -0
  111. package/src/rules/store/use-consistent-global-store-name.js +139 -0
  112. package/src/rules/store/use-consistent-global-store-name.js.map +1 -0
  113. package/src/utils/helper-functions/docs.js +8 -0
  114. package/src/utils/helper-functions/docs.js.map +1 -0
  115. package/src/utils/helper-functions/folder.js +118 -0
  116. package/src/utils/helper-functions/folder.js.map +1 -0
  117. package/src/utils/helper-functions/guards.js +56 -0
  118. package/src/utils/helper-functions/guards.js.map +1 -0
  119. package/src/utils/helper-functions/index.js +23 -0
  120. package/src/utils/helper-functions/index.js.map +1 -0
  121. package/src/utils/helper-functions/ngrx-modules.js +10 -0
  122. package/src/utils/helper-functions/ngrx-modules.js.map +1 -0
  123. package/src/utils/helper-functions/utils.js +302 -0
  124. package/src/utils/helper-functions/utils.js.map +1 -0
  125. package/src/utils/helper-functions/versions.js +70 -0
  126. package/src/utils/helper-functions/versions.js.map +1 -0
  127. package/src/utils/index.js +19 -0
  128. package/src/utils/index.js.map +1 -0
  129. package/src/utils/selectors/index.js +58 -0
  130. package/src/utils/selectors/index.js.map +1 -0
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __read = (this && this.__read) || function (o, n) {
26
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
27
+ if (!m) return o;
28
+ var i = m.call(o), r, ar = [], e;
29
+ try {
30
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
31
+ }
32
+ catch (error) { e = { error: error }; }
33
+ finally {
34
+ try {
35
+ if (r && !r.done && (m = i["return"])) m.call(i);
36
+ }
37
+ finally { if (e) throw e.error; }
38
+ }
39
+ return ar;
40
+ };
41
+ var _a;
42
+ exports.__esModule = true;
43
+ exports.messageId = void 0;
44
+ var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
45
+ var path = __importStar(require("path"));
46
+ var rule_creator_1 = require("../../rule-creator");
47
+ var utils_1 = require("../../utils");
48
+ exports.messageId = 'preferEffectCallbackInBlockStatement';
49
+ exports["default"] = (0, rule_creator_1.createRule)({
50
+ name: path.parse(__filename).name,
51
+ meta: {
52
+ type: 'suggestion',
53
+ ngrxModule: 'effects',
54
+ docs: {
55
+ description: 'A block statement is easier to troubleshoot.',
56
+ recommended: 'warn'
57
+ },
58
+ schema: [],
59
+ messages: (_a = {},
60
+ _a[exports.messageId] = 'The callback of `Effect` should be wrapped in a block statement.',
61
+ _a),
62
+ fixable: 'code'
63
+ },
64
+ defaultOptions: [],
65
+ create: function (context) {
66
+ var _a;
67
+ var sourceCode = context.getSourceCode();
68
+ var nonParametrizedEffect = "".concat(utils_1.createEffectExpression, " > ArrowFunctionExpression > .body[type!=/^(ArrowFunctionExpression|BlockStatement)$/]");
69
+ var parametrizedEffect = "".concat(utils_1.createEffectExpression, " > ArrowFunctionExpression > ArrowFunctionExpression > .body[type!='BlockStatement']");
70
+ var parametrizedEffectWithinBlockStatement = "".concat(utils_1.createEffectExpression, " > ArrowFunctionExpression > BlockStatement > ReturnStatement > ArrowFunctionExpression > .body[type!='BlockStatement']");
71
+ return _a = {},
72
+ _a["".concat(nonParametrizedEffect, ", ").concat(parametrizedEffect, ", ").concat(parametrizedEffectWithinBlockStatement)] = function (node) {
73
+ context.report({
74
+ node: node,
75
+ messageId: exports.messageId,
76
+ fix: function (fixer) {
77
+ var _a = __read(getSafeNodesToApplyFix(sourceCode, node), 2), previousNode = _a[0], nextNode = _a[1];
78
+ return [
79
+ fixer.insertTextBefore(previousNode, "{ return "),
80
+ fixer.insertTextAfter(nextNode, " }"),
81
+ ];
82
+ }
83
+ });
84
+ },
85
+ _a;
86
+ }
87
+ });
88
+ function getSafeNodesToApplyFix(sourceCode, node) {
89
+ var previousToken = sourceCode.getTokenBefore(node);
90
+ var nextToken = sourceCode.getTokenAfter(node);
91
+ if (previousToken &&
92
+ experimental_utils_1.ASTUtils.isOpeningParenToken(previousToken) &&
93
+ nextToken &&
94
+ experimental_utils_1.ASTUtils.isClosingParenToken(nextToken)) {
95
+ return [previousToken, nextToken];
96
+ }
97
+ return [node, node];
98
+ }
99
+ //# sourceMappingURL=prefer-effect-callback-in-block-statement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-effect-callback-in-block-statement.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/effects/prefer-effect-callback-in-block-statement.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAiE;AACjE,yCAA6B;AAC7B,mDAAgD;AAChD,qCAAqD;AAExC,QAAA,SAAS,GAAG,sCAAsC,CAAC;AAKhE,qBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI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,CAAC,aAAa,CAAC;QAC3C,SAAS;QACT,6BAAQ,CAAC,mBAAmB,CAAC,SAAS,CAAC,EACvC;QACA,OAAO,CAAC,aAAa,EAAE,SAAS,CAAU,CAAC;KAC5C;IAED,OAAO,CAAC,IAAI,EAAE,IAAI,CAAU,CAAC;AAC/B,CAAC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ASTUtils } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { createEffectExpression } from '../../utils';\n\nexport const messageId = 'preferEffectCallbackInBlockStatement';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'effects',\n docs: {\n description: 'A block statement is easier to troubleshoot.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]:\n 'The callback of `Effect` should be wrapped in a block statement.',\n },\n fixable: 'code',\n },\n defaultOptions: [],\n create: (context) => {\n const sourceCode = context.getSourceCode();\n const nonParametrizedEffect =\n `${createEffectExpression} > ArrowFunctionExpression > .body[type!=/^(ArrowFunctionExpression|BlockStatement)$/]` as const;\n const parametrizedEffect =\n `${createEffectExpression} > ArrowFunctionExpression > ArrowFunctionExpression > .body[type!='BlockStatement']` as const;\n const parametrizedEffectWithinBlockStatement =\n `${createEffectExpression} > ArrowFunctionExpression > BlockStatement > ReturnStatement > ArrowFunctionExpression > .body[type!='BlockStatement']` as const;\n\n return {\n [`${nonParametrizedEffect}, ${parametrizedEffect}, ${parametrizedEffectWithinBlockStatement}`](\n node: TSESTree.ArrowFunctionExpression['body']\n ) {\n context.report({\n node,\n messageId,\n fix: (fixer) => {\n const [previousNode, nextNode] = getSafeNodesToApplyFix(\n sourceCode,\n node\n );\n return [\n fixer.insertTextBefore(previousNode, `{ return `),\n fixer.insertTextAfter(nextNode, ` }`),\n ];\n },\n });\n },\n };\n },\n});\n\nfunction getSafeNodesToApplyFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n node: TSESTree.Node\n) {\n const previousToken = sourceCode.getTokenBefore(node);\n const nextToken = sourceCode.getTokenAfter(node);\n\n if (\n previousToken &&\n ASTUtils.isOpeningParenToken(previousToken) &&\n nextToken &&\n ASTUtils.isClosingParenToken(nextToken)\n ) {\n return [previousToken, nextToken] as const;\n }\n\n return [node, node] as const;\n}\n"]}
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var _a;
26
+ exports.__esModule = true;
27
+ exports.messageId = void 0;
28
+ var path = __importStar(require("path"));
29
+ var rule_creator_1 = require("../../rule-creator");
30
+ var utils_1 = require("../../utils");
31
+ exports.messageId = 'useEffectsLifecycleInterface';
32
+ exports["default"] = (0, rule_creator_1.createRule)({
33
+ name: path.parse(__filename).name,
34
+ meta: {
35
+ type: 'suggestion',
36
+ ngrxModule: 'effects',
37
+ docs: {
38
+ description: 'Ensures classes implement lifecycle interfaces corresponding to the declared lifecycle methods.',
39
+ recommended: 'warn'
40
+ },
41
+ fixable: 'code',
42
+ schema: [],
43
+ messages: (_a = {},
44
+ _a[exports.messageId] = 'Lifecycle interface `{{ interfaceName }}` should be implemented for method `{{ methodName }}`.',
45
+ _a)
46
+ },
47
+ defaultOptions: [],
48
+ create: function (context) {
49
+ var _a;
50
+ var lifecycleMapper = {
51
+ ngrxOnIdentifyEffects: 'OnIdentifyEffects',
52
+ ngrxOnInitEffects: 'OnInitEffects',
53
+ ngrxOnRunEffects: 'OnRunEffects'
54
+ };
55
+ var lifecyclesPattern = Object.keys(lifecycleMapper).join('|');
56
+ return _a = {},
57
+ _a["ClassDeclaration > ClassBody > MethodDefinition > Identifier[name=/".concat(lifecyclesPattern, "/]")] = function (node) {
58
+ var classDeclaration = node.parent.parent.parent;
59
+ var methodName = node.name;
60
+ var interfaceName = lifecycleMapper[methodName];
61
+ if ((0, utils_1.getInterface)(classDeclaration, interfaceName)) {
62
+ return;
63
+ }
64
+ context.report({
65
+ fix: function (fixer) {
66
+ var _a = (0, utils_1.getImplementsSchemaFixer)(classDeclaration, interfaceName), implementsNodeReplace = _a.implementsNodeReplace, implementsTextReplace = _a.implementsTextReplace;
67
+ return [
68
+ fixer.insertTextAfter(implementsNodeReplace, implementsTextReplace),
69
+ ].concat((0, utils_1.getImportAddFix)({
70
+ compatibleWithTypeOnlyImport: true,
71
+ fixer: fixer,
72
+ importName: interfaceName,
73
+ moduleName: utils_1.NGRX_MODULE_PATHS.effects,
74
+ node: classDeclaration
75
+ }));
76
+ },
77
+ node: node,
78
+ messageId: exports.messageId,
79
+ data: {
80
+ interfaceName: interfaceName,
81
+ methodName: methodName
82
+ }
83
+ });
84
+ },
85
+ _a;
86
+ }
87
+ });
88
+ //# sourceMappingURL=use-effects-lifecycle-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-effects-lifecycle-interface.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/effects/use-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qBAAqB,2BACO,CAAC;wBAC5D,OAAO;4BACL,KAAK,CAAC,eAAe,CACnB,qBAAqB,EACrB,qBAAqB,CACtB;yBACF,CAAC,MAAM,CACN,IAAA,uBAAe,EAAC;4BACd,4BAA4B,EAAE,IAAI;4BAClC,KAAK,OAAA;4BACL,UAAU,EAAE,aAAa;4BACzB,UAAU,EAAE,yBAAiB,CAAC,OAAO;4BACrC,IAAI,EAAE,gBAAgB;yBACvB,CAAC,CACH,CAAC;oBACJ,CAAC;oBACD,IAAI,MAAA;oBACJ,SAAS,mBAAA;oBACT,IAAI,EAAE;wBACJ,aAAa,eAAA;wBACb,UAAU,YAAA;qBACX;iBACF,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n getImplementsSchemaFixer,\n getImportAddFix,\n getInterface,\n NGRX_MODULE_PATHS,\n} from '../../utils';\n\nexport const messageId = 'useEffectsLifecycleInterface';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'effects',\n docs: {\n description:\n 'Ensures classes implement lifecycle interfaces corresponding to the declared lifecycle methods.',\n recommended: 'warn',\n },\n fixable: 'code',\n schema: [],\n messages: {\n [messageId]:\n 'Lifecycle interface `{{ interfaceName }}` should be implemented for method `{{ methodName }}`.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const lifecycleMapper = {\n ngrxOnIdentifyEffects: 'OnIdentifyEffects',\n ngrxOnInitEffects: 'OnInitEffects',\n ngrxOnRunEffects: 'OnRunEffects',\n } as const;\n const lifecyclesPattern = Object.keys(lifecycleMapper).join('|');\n\n return {\n [`ClassDeclaration > ClassBody > MethodDefinition > Identifier[name=/${lifecyclesPattern}/]`](\n node: TSESTree.Identifier & {\n name: keyof typeof lifecycleMapper;\n parent: TSESTree.MethodDefinition & {\n parent: TSESTree.ClassBody & { parent: TSESTree.ClassDeclaration };\n };\n }\n ) {\n const classDeclaration = node.parent.parent.parent;\n const methodName = node.name;\n const interfaceName = lifecycleMapper[methodName];\n\n if (getInterface(classDeclaration, interfaceName)) {\n return;\n }\n\n context.report({\n fix: (fixer) => {\n const { implementsNodeReplace, implementsTextReplace } =\n getImplementsSchemaFixer(classDeclaration, interfaceName);\n return [\n fixer.insertTextAfter(\n implementsNodeReplace,\n implementsTextReplace\n ),\n ].concat(\n getImportAddFix({\n compatibleWithTypeOnlyImport: true,\n fixer,\n importName: interfaceName,\n moduleName: NGRX_MODULE_PATHS.effects,\n node: classDeclaration,\n })\n );\n },\n node,\n messageId,\n data: {\n interfaceName,\n methodName,\n },\n });\n },\n };\n },\n});\n"]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ exports.__esModule = true;
37
+ exports.rules = void 0;
38
+ var path = __importStar(require("path"));
39
+ var utils_1 = require("../utils");
40
+ // Copied from https://github.com/jest-community/eslint-plugin-jest/blob/main/src/index.ts
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ var interopRequireDefault = function (obj) {
43
+ return (obj === null || obj === void 0 ? void 0 : obj.__esModule) ? obj : { "default": obj };
44
+ };
45
+ var importDefault = function (moduleName) {
46
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
47
+ return interopRequireDefault(require(moduleName))["default"];
48
+ };
49
+ var rulesDir = __dirname;
50
+ var excludedFiles = ['index'];
51
+ exports.rules = Array.from((0, utils_1.traverseFolder)(rulesDir))
52
+ .filter(function (rule) { return !excludedFiles.includes(rule.file); })
53
+ .reduce(function (allRules, rule) {
54
+ var _a;
55
+ var ruleModule = importDefault(rule.path);
56
+ ruleModule.meta.ngrxModule = path.basename(path.dirname(rule.path));
57
+ return __assign(__assign({}, allRules), (_a = {}, _a[rule.file] = ruleModule, _a));
58
+ }, {});
59
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/eslint-plugin/src/rules/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA6B;AAG7B,kCAA0C;AAE1C,0FAA0F;AAE1F,8DAA8D;AAC9D,IAAM,qBAAqB,GAAG,UAAC,GAAQ;IACrC,OAAA,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,EAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,SAAO,EAAE,GAAG,EAAE;AAAxC,CAAwC,CAAC;AAE3C,IAAM,aAAa,GAAG,UAAC,UAAkB;IACvC,8DAA8D;IAC9D,OAAA,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAO,CAAA;AAAlD,CAAkD,CAAC;AAErD,IAAM,QAAQ,GAAG,SAAS,CAAC;AAC3B,IAAM,aAAa,GAAG,CAAC,OAAO,CAAC,CAAC;AAEnB,QAAA,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAA,sBAAc,EAAC,QAAQ,CAAC,CAAC;KACtD,MAAM,CAAC,UAAC,IAAI,IAAK,OAAA,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAlC,CAAkC,CAAC;KACpD,MAAM,CAA6C,UAAC,QAAQ,EAAE,IAAI;;IACjE,IAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAA+B,CAAC;IAC1E,UAAU,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CACxC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CACT,CAAC;IACjB,6BACK,QAAQ,gBACV,IAAI,CAAC,IAAI,IAAG,UAAU,OACvB;AACJ,CAAC,EAAE,EAAE,CAAC,CAAC","sourcesContent":["import * as path from 'path';\nimport type { NgRxRuleModule } from '../rule-creator';\nimport type { NGRX_MODULE } from '../utils';\nimport { traverseFolder } from '../utils';\n\n// Copied from https://github.com/jest-community/eslint-plugin-jest/blob/main/src/index.ts\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst interopRequireDefault = (obj: any): { default: unknown } =>\n obj?.__esModule ? obj : { default: obj };\n\nconst importDefault = (moduleName: string) =>\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n interopRequireDefault(require(moduleName)).default;\n\nconst rulesDir = __dirname;\nconst excludedFiles = ['index'];\n\nexport const rules = Array.from(traverseFolder(rulesDir))\n .filter((rule) => !excludedFiles.includes(rule.file))\n .reduce<Record<string, NgRxRuleModule<[], string>>>((allRules, rule) => {\n const ruleModule = importDefault(rule.path) as NgRxRuleModule<[], string>;\n ruleModule.meta.ngrxModule = path.basename(\n path.dirname(rule.path)\n ) as NGRX_MODULE;\n return {\n ...allRules,\n [rule.file]: ruleModule,\n };\n }, {});\n"]}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var _a;
26
+ exports.__esModule = true;
27
+ exports.messageId = void 0;
28
+ var path = __importStar(require("path"));
29
+ var rule_creator_1 = require("../../rule-creator");
30
+ var utils_1 = require("../../utils");
31
+ exports.messageId = 'avoidCombiningSelectors';
32
+ exports["default"] = (0, rule_creator_1.createRule)({
33
+ name: path.parse(__filename).name,
34
+ meta: {
35
+ type: 'suggestion',
36
+ ngrxModule: 'store',
37
+ docs: {
38
+ description: 'Prefer combining selectors at the selector level.',
39
+ recommended: 'warn'
40
+ },
41
+ schema: [],
42
+ messages: (_a = {},
43
+ _a[exports.messageId] = 'Combine selectors at the selector level.',
44
+ _a)
45
+ },
46
+ defaultOptions: [],
47
+ create: function (context) {
48
+ var _a;
49
+ var _b = (0, utils_1.getNgRxStores)(context).identifiers, identifiers = _b === void 0 ? [] : _b;
50
+ var storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
51
+ if (!storeNames) {
52
+ return {};
53
+ }
54
+ var pipeableOrStoreSelect = ":matches(".concat((0, utils_1.namedExpression)(storeNames), "[callee.property.name='pipe']:has(CallExpression[callee.name='select']), ").concat((0, utils_1.selectExpression)(storeNames), ")");
55
+ return _a = {},
56
+ _a["CallExpression[callee.name='combineLatest'][arguments.length>1] ".concat(pipeableOrStoreSelect, " ~ ").concat(pipeableOrStoreSelect)] = function (node) {
57
+ context.report({
58
+ node: node,
59
+ messageId: exports.messageId
60
+ });
61
+ },
62
+ _a;
63
+ }
64
+ });
65
+ //# sourceMappingURL=avoid-combining-selectors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avoid-combining-selectors.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-combining-selectors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAKqB;AAER,QAAA,SAAS,GAAG,yBAAyB,CAAC;AAKnD,qBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EAAE,mDAAmD;YAChE,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IAAG,0CAA0C;eACxD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACN,IAAA,KAAqB,IAAA,qBAAa,EAAC,OAAO,CAAC,YAA3B,EAAhB,WAAW,mBAAG,EAAE,KAAA,CAA4B;QACpD,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,EAAE,CAAC;SACX;QAED,IAAM,qBAAqB,GAAG,mBAAY,IAAA,uBAAe,EACvD,UAAU,CACX,sFAA4E,IAAA,wBAAgB,EAC3F,UAAU,CACX,MAAY,CAAC;QAEd;YACE,GAAC,0EAAmE,qBAAqB,gBAAM,qBAAqB,CAAE,IAAtH,UACE,IAA6B;gBAE7B,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,MAAA;oBACJ,SAAS,mBAAA;iBACV,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getNgRxStores,\n namedExpression,\n selectExpression,\n} from '../../utils';\n\nexport const messageId = 'avoidCombiningSelectors';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description: 'Prefer combining selectors at the selector level.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]: 'Combine selectors at the selector level.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n const pipeableOrStoreSelect = `:matches(${namedExpression(\n storeNames\n )}[callee.property.name='pipe']:has(CallExpression[callee.name='select']), ${selectExpression(\n storeNames\n )})` as const;\n\n return {\n [`CallExpression[callee.name='combineLatest'][arguments.length>1] ${pipeableOrStoreSelect} ~ ${pipeableOrStoreSelect}`](\n node: TSESTree.CallExpression\n ) {\n context.report({\n node,\n messageId,\n });\n },\n };\n },\n});\n"]}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __values = (this && this.__values) || function(o) {
26
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
27
+ if (m) return m.call(o);
28
+ if (o && typeof o.length === "number") return {
29
+ next: function () {
30
+ if (o && i >= o.length) o = void 0;
31
+ return { value: o && o[i++], done: !o };
32
+ }
33
+ };
34
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
35
+ };
36
+ var _a;
37
+ exports.__esModule = true;
38
+ exports.messageId = void 0;
39
+ var path = __importStar(require("path"));
40
+ var rule_creator_1 = require("../../rule-creator");
41
+ var utils_1 = require("../../utils");
42
+ exports.messageId = 'avoidDispatchingMultipleActionsSequentially';
43
+ exports["default"] = (0, rule_creator_1.createRule)({
44
+ name: path.parse(__filename).name,
45
+ meta: {
46
+ type: 'suggestion',
47
+ ngrxModule: 'store',
48
+ docs: {
49
+ description: 'It is recommended to only dispatch one `Action` at a time.',
50
+ recommended: 'warn'
51
+ },
52
+ schema: [],
53
+ messages: (_a = {},
54
+ _a[exports.messageId] = 'Avoid dispatching many actions in a row to accomplish a larger conceptual "transaction".',
55
+ _a)
56
+ },
57
+ defaultOptions: [],
58
+ create: function (context) {
59
+ var _a;
60
+ var _b = (0, utils_1.getNgRxStores)(context).identifiers, identifiers = _b === void 0 ? [] : _b;
61
+ var storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
62
+ if (!storeNames) {
63
+ return {};
64
+ }
65
+ var collectedDispatches = new Set();
66
+ return _a = {},
67
+ _a["BlockStatement > ExpressionStatement > ".concat((0, utils_1.dispatchExpression)(storeNames))] = function (node) {
68
+ collectedDispatches.add(node);
69
+ },
70
+ _a['BlockStatement:exit'] = function () {
71
+ var e_1, _a;
72
+ if (collectedDispatches.size > 1) {
73
+ try {
74
+ for (var collectedDispatches_1 = __values(collectedDispatches), collectedDispatches_1_1 = collectedDispatches_1.next(); !collectedDispatches_1_1.done; collectedDispatches_1_1 = collectedDispatches_1.next()) {
75
+ var node = collectedDispatches_1_1.value;
76
+ context.report({
77
+ node: node,
78
+ messageId: exports.messageId
79
+ });
80
+ }
81
+ }
82
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
83
+ finally {
84
+ try {
85
+ if (collectedDispatches_1_1 && !collectedDispatches_1_1.done && (_a = collectedDispatches_1["return"])) _a.call(collectedDispatches_1);
86
+ }
87
+ finally { if (e_1) throw e_1.error; }
88
+ }
89
+ }
90
+ collectedDispatches.clear();
91
+ },
92
+ _a;
93
+ }
94
+ });
95
+ //# sourceMappingURL=avoid-dispatching-multiple-actions-sequentially.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avoid-dispatching-multiple-actions-sequentially.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src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;gCACb,IAAI,MAAA;gCACJ,SAAS,mBAAA;6BACV,CAAC,CAAC;yBACJ;;;;;;;;;iBACF;gBAED,mBAAmB,CAAC,KAAK,EAAE,CAAC;YAC9B,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { asPattern, dispatchExpression, getNgRxStores } from '../../utils';\n\nexport const messageId = 'avoidDispatchingMultipleActionsSequentially';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description: 'It is recommended to only dispatch one `Action` at a time.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Avoid dispatching many actions in a row to accomplish a larger conceptual \"transaction\".',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n const collectedDispatches = new Set<TSESTree.CallExpression>();\n\n return {\n [`BlockStatement > ExpressionStatement > ${dispatchExpression(\n storeNames\n )}`](node: TSESTree.CallExpression) {\n collectedDispatches.add(node);\n },\n 'BlockStatement:exit'() {\n if (collectedDispatches.size > 1) {\n for (const node of collectedDispatches) {\n context.report({\n node,\n messageId,\n });\n }\n }\n\n collectedDispatches.clear();\n },\n };\n },\n});\n"]}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __read = (this && this.__read) || function (o, n) {
26
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
27
+ if (!m) return o;
28
+ var i = m.call(o), r, ar = [], e;
29
+ try {
30
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
31
+ }
32
+ catch (error) { e = { error: error }; }
33
+ finally {
34
+ try {
35
+ if (r && !r.done && (m = i["return"])) m.call(i);
36
+ }
37
+ finally { if (e) throw e.error; }
38
+ }
39
+ return ar;
40
+ };
41
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
42
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
43
+ if (ar || !(i in from)) {
44
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
45
+ ar[i] = from[i];
46
+ }
47
+ }
48
+ return to.concat(ar || Array.prototype.slice.call(from));
49
+ };
50
+ var __values = (this && this.__values) || function(o) {
51
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
52
+ if (m) return m.call(o);
53
+ if (o && typeof o.length === "number") return {
54
+ next: function () {
55
+ if (o && i >= o.length) o = void 0;
56
+ return { value: o && o[i++], done: !o };
57
+ }
58
+ };
59
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
60
+ };
61
+ var _a;
62
+ exports.__esModule = true;
63
+ exports.avoidDuplicateActionsInReducerSuggest = exports.avoidDuplicateActionsInReducer = void 0;
64
+ var path = __importStar(require("path"));
65
+ var rule_creator_1 = require("../../rule-creator");
66
+ var utils_1 = require("../../utils");
67
+ exports.avoidDuplicateActionsInReducer = 'avoidDuplicateActionsInReducer';
68
+ exports.avoidDuplicateActionsInReducerSuggest = 'avoidDuplicateActionsInReducerSuggest';
69
+ exports["default"] = (0, rule_creator_1.createRule)({
70
+ name: path.parse(__filename).name,
71
+ meta: {
72
+ type: 'suggestion',
73
+ hasSuggestions: true,
74
+ ngrxModule: 'store',
75
+ docs: {
76
+ description: 'A `Reducer` should handle an `Action` once.',
77
+ recommended: 'warn',
78
+ suggestion: true
79
+ },
80
+ schema: [],
81
+ messages: (_a = {},
82
+ _a[exports.avoidDuplicateActionsInReducer] = 'The `Reducer` handles a duplicate `Action` `{{ actionName }}`.',
83
+ _a[exports.avoidDuplicateActionsInReducerSuggest] = 'Remove this duplication.',
84
+ _a)
85
+ },
86
+ defaultOptions: [],
87
+ create: function (context) {
88
+ var _a;
89
+ var sourceCode = context.getSourceCode();
90
+ var collectedActions = new Map();
91
+ return _a = {},
92
+ _a["".concat(utils_1.createReducer, " > CallExpression[callee.name='on'][arguments.0.type='Identifier']")] = function (_a) {
93
+ var _b;
94
+ var _c = __read(_a.arguments, 1), action = _c[0];
95
+ var actions = (_b = collectedActions.get(action.name)) !== null && _b !== void 0 ? _b : [];
96
+ collectedActions.set(action.name, __spreadArray(__spreadArray([], __read(actions), false), [action], false));
97
+ },
98
+ _a["".concat(utils_1.createReducer, ":exit")] = function () {
99
+ var e_1, _a, e_2, _b;
100
+ try {
101
+ for (var collectedActions_1 = __values(collectedActions), collectedActions_1_1 = collectedActions_1.next(); !collectedActions_1_1.done; collectedActions_1_1 = collectedActions_1.next()) {
102
+ var _c = __read(collectedActions_1_1.value, 2), actionName = _c[0], identifiers = _c[1];
103
+ if (identifiers.length <= 1) {
104
+ break;
105
+ }
106
+ var _loop_1 = function (node) {
107
+ context.report({
108
+ node: node,
109
+ messageId: exports.avoidDuplicateActionsInReducer,
110
+ data: {
111
+ actionName: actionName
112
+ },
113
+ suggest: [
114
+ {
115
+ messageId: exports.avoidDuplicateActionsInReducerSuggest,
116
+ fix: function (fixer) {
117
+ return (0, utils_1.getNodeToCommaRemoveFix)(sourceCode, fixer, node.parent);
118
+ }
119
+ },
120
+ ]
121
+ });
122
+ };
123
+ try {
124
+ for (var identifiers_1 = (e_2 = void 0, __values(identifiers)), identifiers_1_1 = identifiers_1.next(); !identifiers_1_1.done; identifiers_1_1 = identifiers_1.next()) {
125
+ var node = identifiers_1_1.value;
126
+ _loop_1(node);
127
+ }
128
+ }
129
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
130
+ finally {
131
+ try {
132
+ if (identifiers_1_1 && !identifiers_1_1.done && (_b = identifiers_1["return"])) _b.call(identifiers_1);
133
+ }
134
+ finally { if (e_2) throw e_2.error; }
135
+ }
136
+ }
137
+ }
138
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
139
+ finally {
140
+ try {
141
+ if (collectedActions_1_1 && !collectedActions_1_1.done && (_a = collectedActions_1["return"])) _a.call(collectedActions_1);
142
+ }
143
+ finally { if (e_1) throw e_1.error; }
144
+ }
145
+ collectedActions.clear();
146
+ },
147
+ _a;
148
+ }
149
+ });
150
+ //# sourceMappingURL=avoid-duplicate-actions-in-reducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"avoid-duplicate-actions-in-reducer.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-duplicate-actions-in-reducer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAAqE;AAExD,QAAA,8BAA8B,GAAG,gCAAgC,CAAC;AAClE,QAAA,qCAAqC,GAChD,uCAAuC,CAAC;AAQ1C,qBAAe,IAAA,yBAAU,EAAs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;wCACE,SAAS,EAAE,6CAAqC;wCAChD,GAAG,EAAE,UAAC,KAAK;4CACT,OAAA,IAAA,+BAAuB,EAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;wCAAvD,CAAuD;qCAC1D;iCACF;6BACF,CAAC,CAAC;;;4BAdL,KAAmB,IAAA,+BAAA,SAAA,WAAW,CAAA,CAAA,wCAAA;gCAAzB,IAAM,IAAI,wBAAA;wCAAJ,IAAI;6BAed;;;;;;;;;qBACF;;;;;;;;;gBAED,gBAAgB,CAAC,KAAK,EAAE,CAAC;YAC3B,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { createReducer, getNodeToCommaRemoveFix } from '../../utils';\n\nexport const avoidDuplicateActionsInReducer = 'avoidDuplicateActionsInReducer';\nexport const avoidDuplicateActionsInReducerSuggest =\n 'avoidDuplicateActionsInReducerSuggest';\n\ntype MessageIds =\n | typeof avoidDuplicateActionsInReducer\n | typeof avoidDuplicateActionsInReducerSuggest;\ntype Options = readonly [];\ntype Action = TSESTree.Identifier & { parent: TSESTree.CallExpression };\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n hasSuggestions: true,\n ngrxModule: 'store',\n docs: {\n description: 'A `Reducer` should handle an `Action` once.',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [],\n messages: {\n [avoidDuplicateActionsInReducer]:\n 'The `Reducer` handles a duplicate `Action` `{{ actionName }}`.',\n [avoidDuplicateActionsInReducerSuggest]: 'Remove this duplication.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const sourceCode = context.getSourceCode();\n const collectedActions = new Map<string, Action[]>();\n\n return {\n [`${createReducer} > CallExpression[callee.name='on'][arguments.0.type='Identifier']`]({\n arguments: [action],\n }: TSESTree.CallExpression & {\n arguments: Action[];\n }) {\n const actions = collectedActions.get(action.name) ?? [];\n collectedActions.set(action.name, [...actions, action]);\n },\n [`${createReducer}:exit`]() {\n for (const [actionName, identifiers] of collectedActions) {\n if (identifiers.length <= 1) {\n break;\n }\n\n for (const node of identifiers) {\n context.report({\n node,\n messageId: avoidDuplicateActionsInReducer,\n data: {\n actionName,\n },\n suggest: [\n {\n messageId: avoidDuplicateActionsInReducerSuggest,\n fix: (fixer) =>\n getNodeToCommaRemoveFix(sourceCode, fixer, node.parent),\n },\n ],\n });\n }\n }\n\n collectedActions.clear();\n },\n };\n },\n});\n"]}