@ngrx/eslint-plugin 18.0.0-beta.0 → 18.0.0-rc.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 (205) hide show
  1. package/jest.config.d.ts +15 -0
  2. package/package.json +3 -5
  3. package/schematics/ng-add/index.d.ts +3 -0
  4. package/schematics/ng-add/index.js +32 -20
  5. package/schematics/ng-add/index.js.map +1 -1
  6. package/schematics/ng-add/schema.d.ts +3 -0
  7. package/schematics/ng-add/schema.js.map +1 -1
  8. package/schematics/ng-add/schema.json +16 -51
  9. package/scripts/generate-config.d.ts +1 -0
  10. package/scripts/generate-config.js +73 -73
  11. package/scripts/generate-config.js.map +1 -1
  12. package/scripts/generate-docs.d.ts +1 -0
  13. package/scripts/generate-docs.js +33 -65
  14. package/scripts/generate-docs.js.map +1 -1
  15. package/scripts/generate-overview.d.ts +1 -0
  16. package/scripts/generate-overview.js +43 -75
  17. package/scripts/generate-overview.js.map +1 -1
  18. package/spec/utils/from-fixture.d.ts +8 -0
  19. package/spec/utils/from-fixture.js +62 -0
  20. package/spec/utils/from-fixture.js.map +1 -0
  21. package/spec/utils/index.d.ts +2 -0
  22. package/spec/utils/index.js +16 -19
  23. package/spec/utils/index.js.map +1 -1
  24. package/spec/utils/rule-tester.d.ts +5 -0
  25. package/spec/utils/rule-tester.js +23 -0
  26. package/spec/utils/rule-tester.js.map +1 -0
  27. package/src/configs/all.d.ts +7 -0
  28. package/src/configs/all.js +56 -32
  29. package/src/configs/all.js.map +1 -1
  30. package/src/configs/all.json +42 -0
  31. package/src/configs/component-store.d.ts +7 -0
  32. package/src/configs/component-store.js +23 -8
  33. package/src/configs/component-store.js.map +1 -1
  34. package/src/configs/component-store.json +9 -0
  35. package/src/configs/effects.d.ts +7 -0
  36. package/src/configs/effects.js +32 -11
  37. package/src/configs/effects.js.map +1 -1
  38. package/src/configs/effects.json +13 -0
  39. package/src/configs/operators.d.ts +7 -0
  40. package/src/configs/operators.js +28 -0
  41. package/src/configs/operators.js.map +1 -0
  42. package/src/configs/operators.json +7 -0
  43. package/src/configs/signals.d.ts +7 -0
  44. package/src/configs/signals.js +34 -0
  45. package/src/configs/signals.js.map +1 -0
  46. package/src/configs/signals.json +8 -0
  47. package/src/configs/store.d.ts +7 -0
  48. package/src/configs/store.js +38 -23
  49. package/src/configs/store.js.map +1 -1
  50. package/src/configs/store.json +24 -0
  51. package/src/index.d.ts +141 -0
  52. package/src/index.js +18 -3
  53. package/src/index.js.map +1 -1
  54. package/src/rule-creator.d.ts +24 -0
  55. package/src/rule-creator.js +12 -58
  56. package/src/rule-creator.js.map +1 -1
  57. package/src/rules/component-store/avoid-combining-component-store-selectors.d.ts +3 -0
  58. package/src/rules/component-store/avoid-combining-component-store-selectors.js +22 -47
  59. package/src/rules/component-store/avoid-combining-component-store-selectors.js.map +1 -1
  60. package/src/rules/component-store/avoid-mapping-component-store-selectors.d.ts +3 -0
  61. package/src/rules/component-store/avoid-mapping-component-store-selectors.js +17 -20
  62. package/src/rules/component-store/avoid-mapping-component-store-selectors.js.map +1 -1
  63. package/src/rules/component-store/updater-explicit-return-type.d.ts +3 -0
  64. package/src/rules/component-store/updater-explicit-return-type.js +17 -20
  65. package/src/rules/component-store/updater-explicit-return-type.js.map +1 -1
  66. package/src/rules/effects/avoid-cyclic-effects.d.ts +4 -0
  67. package/src/rules/effects/avoid-cyclic-effects.js +47 -109
  68. package/src/rules/effects/avoid-cyclic-effects.js.map +1 -1
  69. package/src/rules/effects/no-dispatch-in-effects.d.ts +5 -0
  70. package/src/rules/effects/no-dispatch-in-effects.js +17 -21
  71. package/src/rules/effects/no-dispatch-in-effects.js.map +1 -1
  72. package/src/rules/effects/no-effects-in-providers.d.ts +3 -0
  73. package/src/rules/effects/no-effects-in-providers.js +18 -49
  74. package/src/rules/effects/no-effects-in-providers.js.map +1 -1
  75. package/src/rules/effects/no-multiple-actions-in-effects.d.ts +5 -0
  76. package/src/rules/effects/no-multiple-actions-in-effects.js +31 -24
  77. package/src/rules/effects/no-multiple-actions-in-effects.js.map +1 -1
  78. package/src/rules/effects/prefer-action-creator-in-of-type.d.ts +3 -0
  79. package/src/rules/effects/prefer-action-creator-in-of-type.js +10 -13
  80. package/src/rules/effects/prefer-action-creator-in-of-type.js.map +1 -1
  81. package/src/rules/effects/prefer-effect-callback-in-block-statement.d.ts +4 -0
  82. package/src/rules/effects/prefer-effect-callback-in-block-statement.js +24 -43
  83. package/src/rules/effects/prefer-effect-callback-in-block-statement.js.map +1 -1
  84. package/src/rules/effects/use-effects-lifecycle-interface.d.ts +3 -0
  85. package/src/rules/effects/use-effects-lifecycle-interface.js +21 -24
  86. package/src/rules/effects/use-effects-lifecycle-interface.js.map +1 -1
  87. package/src/rules/index.d.ts +33 -0
  88. package/src/rules/index.js +69 -53
  89. package/src/rules/index.js.map +1 -1
  90. package/src/rules/operators/prefer-concat-latest-from.d.ts +7 -0
  91. package/src/rules/operators/prefer-concat-latest-from.js +123 -0
  92. package/src/rules/operators/prefer-concat-latest-from.js.map +1 -0
  93. package/src/rules/signals/signal-state-no-arrays-at-root-level.d.ts +3 -0
  94. package/src/rules/signals/signal-state-no-arrays-at-root-level.js +59 -0
  95. package/src/rules/signals/signal-state-no-arrays-at-root-level.js.map +1 -0
  96. package/src/rules/signals/with-state-no-arrays-at-root-level.d.ts +4 -0
  97. package/src/rules/signals/with-state-no-arrays-at-root-level.js +72 -0
  98. package/src/rules/signals/with-state-no-arrays-at-root-level.js.map +1 -0
  99. package/src/rules/store/avoid-combining-selectors.d.ts +3 -0
  100. package/src/rules/store/avoid-combining-selectors.js +20 -45
  101. package/src/rules/store/avoid-combining-selectors.js.map +1 -1
  102. package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.d.ts +3 -0
  103. package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js +20 -47
  104. package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js.map +1 -1
  105. package/src/rules/store/avoid-duplicate-actions-in-reducer.d.ts +5 -0
  106. package/src/rules/store/avoid-duplicate-actions-in-reducer.js +33 -101
  107. package/src/rules/store/avoid-duplicate-actions-in-reducer.js.map +1 -1
  108. package/src/rules/store/avoid-mapping-selectors.d.ts +3 -0
  109. package/src/rules/store/avoid-mapping-selectors.js +24 -30
  110. package/src/rules/store/avoid-mapping-selectors.js.map +1 -1
  111. package/src/rules/store/good-action-hygiene.d.ts +3 -0
  112. package/src/rules/store/good-action-hygiene.js +14 -34
  113. package/src/rules/store/good-action-hygiene.js.map +1 -1
  114. package/src/rules/store/no-multiple-global-stores.d.ts +6 -0
  115. package/src/rules/store/no-multiple-global-stores.js +34 -96
  116. package/src/rules/store/no-multiple-global-stores.js.map +1 -1
  117. package/src/rules/store/no-reducer-in-key-names.d.ts +5 -0
  118. package/src/rules/store/no-reducer-in-key-names.js +16 -20
  119. package/src/rules/store/no-reducer-in-key-names.js.map +1 -1
  120. package/src/rules/store/no-store-subscription.d.ts +3 -0
  121. package/src/rules/store/no-store-subscription.js +13 -16
  122. package/src/rules/store/no-store-subscription.js.map +1 -1
  123. package/src/rules/store/no-typed-global-store.d.ts +5 -0
  124. package/src/rules/store/no-typed-global-store.js +29 -70
  125. package/src/rules/store/no-typed-global-store.js.map +1 -1
  126. package/src/rules/store/on-function-explicit-return-type.d.ts +6 -0
  127. package/src/rules/store/on-function-explicit-return-type.js +23 -43
  128. package/src/rules/store/on-function-explicit-return-type.js.map +1 -1
  129. package/src/rules/store/prefer-action-creator-in-dispatch.d.ts +3 -0
  130. package/src/rules/store/prefer-action-creator-in-dispatch.js +15 -18
  131. package/src/rules/store/prefer-action-creator-in-dispatch.js.map +1 -1
  132. package/src/rules/store/prefer-action-creator.d.ts +3 -0
  133. package/src/rules/store/prefer-action-creator.js +10 -13
  134. package/src/rules/store/prefer-action-creator.js.map +1 -1
  135. package/src/rules/store/prefer-inline-action-props.d.ts +5 -0
  136. package/src/rules/store/prefer-inline-action-props.js +14 -18
  137. package/src/rules/store/prefer-inline-action-props.js.map +1 -1
  138. package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.d.ts +5 -0
  139. package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js +16 -37
  140. package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js.map +1 -1
  141. package/src/rules/store/prefer-selector-in-select.d.ts +3 -0
  142. package/src/rules/store/prefer-selector-in-select.js +21 -46
  143. package/src/rules/store/prefer-selector-in-select.js.map +1 -1
  144. package/src/rules/store/prefix-selectors-with-select.d.ts +5 -0
  145. package/src/rules/store/prefix-selectors-with-select.js +26 -39
  146. package/src/rules/store/prefix-selectors-with-select.js.map +1 -1
  147. package/src/rules/store/select-style.d.ts +11 -0
  148. package/src/rules/store/select-style.js +53 -108
  149. package/src/rules/store/select-style.js.map +1 -1
  150. package/src/rules/store/use-consistent-global-store-name.d.ts +6 -0
  151. package/src/rules/store/use-consistent-global-store-name.js +24 -80
  152. package/src/rules/store/use-consistent-global-store-name.js.map +1 -1
  153. package/src/utils/helper-functions/docs.d.ts +1 -0
  154. package/src/utils/helper-functions/docs.js +1 -3
  155. package/src/utils/helper-functions/docs.js.map +1 -1
  156. package/src/utils/helper-functions/folder.d.ts +5 -0
  157. package/src/utils/helper-functions/folder.js +16 -88
  158. package/src/utils/helper-functions/folder.js.map +1 -1
  159. package/src/utils/helper-functions/guards.d.ts +97 -0
  160. package/src/utils/helper-functions/guards.js +27 -31
  161. package/src/utils/helper-functions/guards.js.map +1 -1
  162. package/src/utils/helper-functions/index.d.ts +6 -0
  163. package/src/utils/helper-functions/ngrx-modules.d.ts +8 -0
  164. package/src/utils/helper-functions/ngrx-modules.js +7 -6
  165. package/src/utils/helper-functions/ngrx-modules.js.map +1 -1
  166. package/src/utils/helper-functions/rules.d.ts +3 -0
  167. package/src/utils/helper-functions/rules.js +47 -0
  168. package/src/utils/helper-functions/rules.js.map +1 -0
  169. package/src/utils/helper-functions/utils.d.ts +48 -0
  170. package/src/utils/helper-functions/utils.js +68 -143
  171. package/src/utils/helper-functions/utils.js.map +1 -1
  172. package/src/utils/helper-functions/versions.d.ts +1 -0
  173. package/src/utils/helper-functions/versions.js +9 -10
  174. package/src/utils/helper-functions/versions.js.map +1 -1
  175. package/src/utils/index.d.ts +2 -0
  176. package/src/utils/selectors/index.d.ts +29 -0
  177. package/src/utils/selectors/index.js +30 -44
  178. package/src/utils/selectors/index.js.map +1 -1
  179. package/v9/index.d.ts +29 -0
  180. package/v9/index.js +38 -0
  181. package/v9/index.js.map +1 -0
  182. package/src/configs/all-requiring-type-checking.js +0 -46
  183. package/src/configs/all-requiring-type-checking.js.map +0 -1
  184. package/src/configs/component-store-strict.js +0 -15
  185. package/src/configs/component-store-strict.js.map +0 -1
  186. package/src/configs/effects-requiring-type-checking.js +0 -25
  187. package/src/configs/effects-requiring-type-checking.js.map +0 -1
  188. package/src/configs/effects-strict-requiring-type-checking.js +0 -25
  189. package/src/configs/effects-strict-requiring-type-checking.js.map +0 -1
  190. package/src/configs/effects-strict.js +0 -18
  191. package/src/configs/effects-strict.js.map +0 -1
  192. package/src/configs/index.js +0 -33
  193. package/src/configs/index.js.map +0 -1
  194. package/src/configs/recommended-requiring-type-checking.js +0 -46
  195. package/src/configs/recommended-requiring-type-checking.js.map +0 -1
  196. package/src/configs/recommended.js +0 -39
  197. package/src/configs/recommended.js.map +0 -1
  198. package/src/configs/store-strict.js +0 -30
  199. package/src/configs/store-strict.js.map +0 -1
  200. package/src/configs/strict-requiring-type-checking.js +0 -46
  201. package/src/configs/strict-requiring-type-checking.js.map +0 -1
  202. package/src/configs/strict.js +0 -39
  203. package/src/configs/strict.js.map +0 -1
  204. package/src/rules/effects/prefer-concat-latest-from.js +0 -153
  205. package/src/rules/effects/prefer-concat-latest-from.js.map +0 -1
@@ -22,23 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
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
25
  Object.defineProperty(exports, "__esModule", { value: true });
38
26
  exports.messageId = void 0;
39
- var path = __importStar(require("path"));
40
- var rule_creator_1 = require("../../rule-creator");
41
- var utils_1 = require("../../utils");
27
+ const path = __importStar(require("path"));
28
+ const rule_creator_1 = require("../../rule-creator");
29
+ const utils_1 = require("../../utils");
42
30
  exports.messageId = 'preferSelectorInSelect';
43
31
  exports.default = (0, rule_creator_1.createRule)({
44
32
  name: path.parse(__filename).name,
@@ -47,47 +35,34 @@ exports.default = (0, rule_creator_1.createRule)({
47
35
  ngrxModule: 'store',
48
36
  docs: {
49
37
  description: 'Using a selector in the `select` is preferred over `string` or `props drilling`.',
50
- recommended: 'warn',
51
38
  },
52
39
  schema: [],
53
- messages: (_a = {},
54
- _a[exports.messageId] = 'Using `string` or `props drilling` is forbidden. Use a selector instead.',
55
- _a),
40
+ messages: {
41
+ [exports.messageId]: 'Using `string` or `props drilling` is forbidden. Use a selector instead.',
42
+ },
56
43
  },
57
44
  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;
45
+ create: (context) => {
46
+ const { identifiers = [] } = (0, utils_1.getNgRxStores)(context);
47
+ const storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
62
48
  if (!storeNames) {
63
49
  return {};
64
50
  }
65
- return _a = {},
66
- _a["".concat((0, utils_1.pipeableSelect)(storeNames), ", ").concat((0, utils_1.selectExpression)(storeNames))] = function (node) {
67
- var e_1, _a;
68
- try {
69
- for (var _b = __values(node.arguments), _c = _b.next(); !_c.done; _c = _b.next()) {
70
- var argument = _c.value;
71
- if (!(0, utils_1.isLiteral)(argument) &&
72
- !(0, utils_1.isArrowFunctionExpression)(argument) &&
73
- !(0, utils_1.isFunctionExpression)(argument)) {
74
- break;
75
- }
76
- context.report({
77
- node: argument,
78
- messageId: exports.messageId,
79
- });
80
- }
81
- }
82
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
83
- finally {
84
- try {
85
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
51
+ return {
52
+ [`${(0, utils_1.pipeableSelect)(storeNames)}, ${(0, utils_1.selectExpression)(storeNames)}`](node) {
53
+ for (const argument of node.arguments) {
54
+ if (!(0, utils_1.isLiteral)(argument) &&
55
+ !(0, utils_1.isArrowFunctionExpression)(argument) &&
56
+ !(0, utils_1.isFunctionExpression)(argument)) {
57
+ break;
86
58
  }
87
- finally { if (e_1) throw e_1.error; }
59
+ context.report({
60
+ node: argument,
61
+ messageId: exports.messageId,
62
+ });
88
63
  }
89
64
  },
90
- _a;
65
+ };
91
66
  },
92
67
  });
93
68
  //# sourceMappingURL=prefer-selector-in-select.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prefer-selector-in-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-selector-in-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAQqB;AAER,QAAA,SAAS,GAAG,wBAAwB,CAAC;AAKlD,kBAAe,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,EACT,kFAAkF;YACpF,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IACR,0EAA0E;eAC7E;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,CAAC;YAChB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED;YACE,GAAC,UAAG,IAAA,sBAAc,EAAC,UAAU,CAAC,eAAK,IAAA,wBAAgB,EAAC,UAAU,CAAC,CAAE,IAAjE,UACE,IAA6B;;;oBAE7B,KAAuB,IAAA,KAAA,SAAA,IAAI,CAAC,SAAS,CAAA,gBAAA,4BAAE,CAAC;wBAAnC,IAAM,QAAQ,WAAA;wBACjB,IACE,CAAC,IAAA,iBAAS,EAAC,QAAQ,CAAC;4BACpB,CAAC,IAAA,iCAAyB,EAAC,QAAQ,CAAC;4BACpC,CAAC,IAAA,4BAAoB,EAAC,QAAQ,CAAC,EAC/B,CAAC;4BACD,MAAM;wBACR,CAAC;wBAED,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,QAAQ;4BACd,SAAS,mBAAA;yBACV,CAAC,CAAC;oBACL,CAAC;;;;;;;;;YACH,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 isArrowFunctionExpression,\n isFunctionExpression,\n isLiteral,\n pipeableSelect,\n selectExpression,\n} from '../../utils';\n\nexport const messageId = 'preferSelectorInSelect';\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:\n 'Using a selector in the `select` is preferred over `string` or `props drilling`.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Using `string` or `props drilling` is forbidden. Use a selector instead.',\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 return {\n [`${pipeableSelect(storeNames)}, ${selectExpression(storeNames)}`](\n node: TSESTree.CallExpression\n ) {\n for (const argument of node.arguments) {\n if (\n !isLiteral(argument) &&\n !isArrowFunctionExpression(argument) &&\n !isFunctionExpression(argument)\n ) {\n break;\n }\n\n context.report({\n node: argument,\n messageId,\n });\n }\n },\n };\n },\n});\n"]}
1
+ {"version":3,"file":"prefer-selector-in-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-selector-in-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAQqB;AAER,QAAA,SAAS,GAAG,wBAAwB,CAAC;AAKlD,kBAAe,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,EACT,kFAAkF;SACrF;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iBAAS,CAAC,EACT,0EAA0E;SAC7E;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,IAAA,qBAAa,EAAC,OAAO,CAAC,CAAC;QACpD,MAAM,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,CAAC;YAChB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO;YACL,CAAC,GAAG,IAAA,sBAAc,EAAC,UAAU,CAAC,KAAK,IAAA,wBAAgB,EAAC,UAAU,CAAC,EAAE,CAAC,CAChE,IAA6B;gBAE7B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;oBACtC,IACE,CAAC,IAAA,iBAAS,EAAC,QAAQ,CAAC;wBACpB,CAAC,IAAA,iCAAyB,EAAC,QAAQ,CAAC;wBACpC,CAAC,IAAA,4BAAoB,EAAC,QAAQ,CAAC,EAC/B,CAAC;wBACD,MAAM;oBACR,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,QAAQ;wBACd,SAAS,EAAT,iBAAS;qBACV,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getNgRxStores,\n isArrowFunctionExpression,\n isFunctionExpression,\n isLiteral,\n pipeableSelect,\n selectExpression,\n} from '../../utils';\n\nexport const messageId = 'preferSelectorInSelect';\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:\n 'Using a selector in the `select` is preferred over `string` or `props drilling`.',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Using `string` or `props drilling` is forbidden. Use a selector instead.',\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 return {\n [`${pipeableSelect(storeNames)}, ${selectExpression(storeNames)}`](\n node: TSESTree.CallExpression\n ) {\n for (const argument of node.arguments) {\n if (\n !isLiteral(argument) &&\n !isArrowFunctionExpression(argument) &&\n !isFunctionExpression(argument)\n ) {\n break;\n }\n\n context.report({\n node: argument,\n messageId,\n });\n }\n },\n };\n },\n});\n"]}
@@ -0,0 +1,5 @@
1
+ export declare const prefixSelectorsWithSelect = "prefixSelectorsWithSelect";
2
+ export declare const prefixSelectorsWithSelectSuggest = "prefixSelectorsWithSelectSuggest";
3
+ type MessageIds = typeof prefixSelectorsWithSelect | typeof prefixSelectorsWithSelectSuggest;
4
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, readonly [], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
5
+ export default _default;
@@ -1,15 +1,4 @@
1
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
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -33,12 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
33
22
  __setModuleDefault(result, mod);
34
23
  return result;
35
24
  };
36
- var _a;
37
25
  Object.defineProperty(exports, "__esModule", { value: true });
38
26
  exports.prefixSelectorsWithSelectSuggest = exports.prefixSelectorsWithSelect = void 0;
39
- var path = __importStar(require("path"));
40
- var rule_creator_1 = require("../../rule-creator");
41
- var utils_1 = require("../../utils");
27
+ const path = __importStar(require("path"));
28
+ const rule_creator_1 = require("../../rule-creator");
29
+ const utils_1 = require("../../utils");
42
30
  exports.prefixSelectorsWithSelect = 'prefixSelectorsWithSelect';
43
31
  exports.prefixSelectorsWithSelectSuggest = 'prefixSelectorsWithSelectSuggest';
44
32
  exports.default = (0, rule_creator_1.createRule)({
@@ -48,27 +36,29 @@ exports.default = (0, rule_creator_1.createRule)({
48
36
  hasSuggestions: true,
49
37
  ngrxModule: 'store',
50
38
  docs: {
51
- description: 'The selector should start with "select", for example "selectThing".',
52
- recommended: 'warn',
53
- suggestion: true,
39
+ description: 'The selector should start with "select", for example "selectEntity".',
54
40
  },
55
41
  schema: [],
56
- messages: (_a = {},
57
- _a[exports.prefixSelectorsWithSelect] = 'The selector should start with "select".',
58
- _a[exports.prefixSelectorsWithSelectSuggest] = 'Prefix the selector with "select": `{{ name }}`.',
59
- _a),
42
+ messages: {
43
+ [exports.prefixSelectorsWithSelect]: 'The selector should start with "select".',
44
+ [exports.prefixSelectorsWithSelectSuggest]: 'Prefix the selector with "select": `{{ name }}`.',
45
+ },
60
46
  },
61
47
  defaultOptions: [],
62
- create: function (context) {
48
+ create: (context) => {
63
49
  return {
64
- 'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name="createFeature"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))': function (_a) {
65
- var _b;
66
- var id = _a.id;
67
- var suggestedName = getSuggestedName(id.name);
50
+ 'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name="createFeature"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))'({ id, }) {
51
+ const suggestedName = getSuggestedName(id.name);
68
52
  context.report({
69
- loc: __assign(__assign({}, id.loc), { end: __assign(__assign({}, id.loc.end), { column: ((_b = id.typeAnnotation) === null || _b === void 0 ? void 0 : _b.range[0])
53
+ loc: {
54
+ ...id.loc,
55
+ end: {
56
+ ...id.loc.end,
57
+ column: id.typeAnnotation?.range[0]
70
58
  ? id.typeAnnotation.range[0] - 1
71
- : id.loc.end.column }) }),
59
+ : id.loc.end.column,
60
+ },
61
+ },
72
62
  messageId: exports.prefixSelectorsWithSelect,
73
63
  suggest: [
74
64
  {
@@ -76,10 +66,7 @@ exports.default = (0, rule_creator_1.createRule)({
76
66
  data: {
77
67
  name: suggestedName,
78
68
  },
79
- fix: function (fixer) {
80
- var _a, _b;
81
- return fixer.replaceTextRange([id.range[0], (_b = (_a = id.typeAnnotation) === null || _a === void 0 ? void 0 : _a.range[0]) !== null && _b !== void 0 ? _b : id.range[1]], suggestedName);
82
- },
69
+ fix: (fixer) => fixer.replaceTextRange([id.range[0], id.typeAnnotation?.range[0] ?? id.range[1]], suggestedName),
83
70
  },
84
71
  ],
85
72
  });
@@ -88,22 +75,22 @@ exports.default = (0, rule_creator_1.createRule)({
88
75
  },
89
76
  });
90
77
  function getSuggestedName(name) {
91
- var selectWord = 'select';
78
+ const selectWord = 'select';
92
79
  // Ex: 'selectfeature' => 'selectFeature'
93
- var possibleReplacedName = name.replace(new RegExp("^".concat(selectWord, "(.+)")), function (_, word) {
94
- return "".concat(selectWord).concat((0, utils_1.capitalize)(word));
80
+ let possibleReplacedName = name.replace(new RegExp(`^${selectWord}(.+)`), (_, word) => {
81
+ return `${selectWord}${(0, utils_1.capitalize)(word)}`;
95
82
  });
96
83
  if (name !== possibleReplacedName) {
97
84
  return possibleReplacedName;
98
85
  }
99
86
  // Ex: 'getCount' => 'selectCount'
100
- possibleReplacedName = name.replace(/^get([^a-z].+)/, function (_, word) {
101
- return "".concat(selectWord).concat((0, utils_1.capitalize)(word));
87
+ possibleReplacedName = name.replace(/^get([^a-z].+)/, (_, word) => {
88
+ return `${selectWord}${(0, utils_1.capitalize)(word)}`;
102
89
  });
103
90
  if (name !== possibleReplacedName) {
104
91
  return possibleReplacedName;
105
92
  }
106
93
  // Ex: 'item' => 'selectItem'
107
- return "".concat(selectWord).concat((0, utils_1.capitalize)(name));
94
+ return `${selectWord}${(0, utils_1.capitalize)(name)}`;
108
95
  }
109
96
  //# sourceMappingURL=prefix-selectors-with-select.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"prefix-selectors-with-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefix-selectors-with-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAAyC;AAE5B,QAAA,yBAAyB,GAAG,2BAA2B,CAAC;AACxD,QAAA,gCAAgC,GAC3C,kCAAkC,CAAC;AAOrC,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,qEAAqE;YACvE,WAAW,EAAE,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iCAAyB,IAAG,0CAA0C;YACvE,GAAC,wCAAgC,IAC/B,kDAAkD;eACrD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;QACd,OAAO;YACL,gRAAgR,YAAC,EAErN;;oBAD1D,EAAE,QAAA;gBAEF,IAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;gBAChD,OAAO,CAAC,MAAM,CAAC;oBACb,GAAG,wBACE,EAAE,CAAC,GAAG,KACT,GAAG,wBACE,EAAE,CAAC,GAAG,CAAC,GAAG,KACb,MAAM,EAAE,CAAA,MAAA,EAAE,CAAC,cAAc,0CAAE,KAAK,CAAC,CAAC,CAAC;gCACjC,CAAC,CAAC,EAAE,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,oBAAoB,CAAC;IAC9B,CAAC;IAED,6BAA6B;IAC7B,OAAO,UAAG,UAAU,SAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,CAAE,CAAC;AAC5C,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { capitalize } from '../../utils';\n\nexport const prefixSelectorsWithSelect = 'prefixSelectorsWithSelect';\nexport const prefixSelectorsWithSelectSuggest =\n 'prefixSelectorsWithSelectSuggest';\n\ntype MessageIds =\n | typeof prefixSelectorsWithSelect\n | typeof prefixSelectorsWithSelectSuggest;\ntype Options = readonly [];\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:\n 'The selector should start with \"select\", for example \"selectThing\".',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [],\n messages: {\n [prefixSelectorsWithSelect]: 'The selector should start with \"select\".',\n [prefixSelectorsWithSelectSuggest]:\n 'Prefix the selector with \"select\": `{{ name }}`.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n 'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name=\"createFeature\"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))'({\n id,\n }: TSESTree.VariableDeclarator & { id: TSESTree.Identifier }) {\n const suggestedName = getSuggestedName(id.name);\n context.report({\n loc: {\n ...id.loc,\n end: {\n ...id.loc.end,\n column: id.typeAnnotation?.range[0]\n ? id.typeAnnotation.range[0] - 1\n : id.loc.end.column,\n },\n },\n messageId: prefixSelectorsWithSelect,\n suggest: [\n {\n messageId: prefixSelectorsWithSelectSuggest,\n data: {\n name: suggestedName,\n },\n fix: (fixer) =>\n fixer.replaceTextRange(\n [id.range[0], id.typeAnnotation?.range[0] ?? id.range[1]],\n suggestedName\n ),\n },\n ],\n });\n },\n };\n },\n});\n\nfunction getSuggestedName(name: string) {\n const selectWord = 'select';\n // Ex: 'selectfeature' => 'selectFeature'\n let possibleReplacedName = name.replace(\n new RegExp(`^${selectWord}(.+)`),\n (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n }\n );\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'getCount' => 'selectCount'\n possibleReplacedName = name.replace(/^get([^a-z].+)/, (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n });\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'item' => 'selectItem'\n return `${selectWord}${capitalize(name)}`;\n}\n"]}
1
+ {"version":3,"file":"prefix-selectors-with-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefix-selectors-with-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAAyC;AAE5B,QAAA,yBAAyB,GAAG,2BAA2B,CAAC;AACxD,QAAA,gCAAgC,GAC3C,kCAAkC,CAAC;AAOrC,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,sEAAsE;SACzE;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iCAAyB,CAAC,EAAE,0CAA0C;YACvE,CAAC,wCAAgC,CAAC,EAChC,kDAAkD;SACrD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,OAAO;YACL,gRAAgR,CAAC,EAC/Q,EAAE,GACwD;gBAC1D,MAAM,aAA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O,oBAAoB,CAAC;IAC9B,CAAC;IAED,kCAAkC;IAClC,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE;QACxE,OAAO,GAAG,UAAU,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,IAAI,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAClC,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED,6BAA6B;IAC7B,OAAO,GAAG,UAAU,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { capitalize } from '../../utils';\n\nexport const prefixSelectorsWithSelect = 'prefixSelectorsWithSelect';\nexport const prefixSelectorsWithSelectSuggest =\n 'prefixSelectorsWithSelectSuggest';\n\ntype MessageIds =\n | typeof prefixSelectorsWithSelect\n | typeof prefixSelectorsWithSelectSuggest;\ntype Options = readonly [];\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:\n 'The selector should start with \"select\", for example \"selectEntity\".',\n },\n schema: [],\n messages: {\n [prefixSelectorsWithSelect]: 'The selector should start with \"select\".',\n [prefixSelectorsWithSelectSuggest]:\n 'Prefix the selector with \"select\": `{{ name }}`.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n 'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name=\"createFeature\"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))'({\n id,\n }: TSESTree.VariableDeclarator & { id: TSESTree.Identifier }) {\n const suggestedName = getSuggestedName(id.name);\n context.report({\n loc: {\n ...id.loc,\n end: {\n ...id.loc.end,\n column: id.typeAnnotation?.range[0]\n ? id.typeAnnotation.range[0] - 1\n : id.loc.end.column,\n },\n },\n messageId: prefixSelectorsWithSelect,\n suggest: [\n {\n messageId: prefixSelectorsWithSelectSuggest,\n data: {\n name: suggestedName,\n },\n fix: (fixer) =>\n fixer.replaceTextRange(\n [id.range[0], id.typeAnnotation?.range[0] ?? id.range[1]],\n suggestedName\n ),\n },\n ],\n });\n },\n };\n },\n});\n\nfunction getSuggestedName(name: string) {\n const selectWord = 'select';\n // Ex: 'selectfeature' => 'selectFeature'\n let possibleReplacedName = name.replace(\n new RegExp(`^${selectWord}(.+)`),\n (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n }\n );\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'getCount' => 'selectCount'\n possibleReplacedName = name.replace(/^get([^a-z].+)/, (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n });\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'item' => 'selectItem'\n return `${selectWord}${capitalize(name)}`;\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import type { TSESLint } from '@typescript-eslint/utils';
2
+ export declare const selectMethod = "selectMethod";
3
+ export declare const selectOperator = "selectOperator";
4
+ export declare const enum SelectStyle {
5
+ Method = "method",
6
+ Operator = "operator"
7
+ }
8
+ type MessageIds = `${SelectStyle}`;
9
+ type Options = readonly [MessageIds];
10
+ declare const _default: TSESLint.RuleModule<"operator" | "method", Options, TSESLint.RuleListener>;
11
+ export default _default;
@@ -22,50 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
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 __values = (this && this.__values) || function(o) {
42
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
43
- if (m) return m.call(o);
44
- if (o && typeof o.length === "number") return {
45
- next: function () {
46
- if (o && i >= o.length) o = void 0;
47
- return { value: o && o[i++], done: !o };
48
- }
49
- };
50
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
51
- };
52
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
53
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
54
- if (ar || !(i in from)) {
55
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
56
- ar[i] = from[i];
57
- }
58
- }
59
- return to.concat(ar || Array.prototype.slice.call(from));
60
- };
61
- var _a;
62
25
  Object.defineProperty(exports, "__esModule", { value: true });
63
- exports.selectOperator = exports.selectMethod = void 0;
64
- var path = __importStar(require("path"));
65
- var rule_creator_1 = require("../../rule-creator");
66
- var utils_1 = require("../../utils");
26
+ exports.SelectStyle = exports.selectOperator = exports.selectMethod = void 0;
27
+ const path = __importStar(require("path"));
28
+ const rule_creator_1 = require("../../rule-creator");
29
+ const utils_1 = require("../../utils");
67
30
  exports.selectMethod = 'selectMethod';
68
31
  exports.selectOperator = 'selectOperator';
32
+ var SelectStyle;
33
+ (function (SelectStyle) {
34
+ SelectStyle["Method"] = "method";
35
+ SelectStyle["Operator"] = "operator";
36
+ })(SelectStyle || (exports.SelectStyle = SelectStyle = {}));
69
37
  exports.default = (0, rule_creator_1.createRule)({
70
38
  name: path.parse(__filename).name,
71
39
  meta: {
@@ -73,80 +41,58 @@ exports.default = (0, rule_creator_1.createRule)({
73
41
  ngrxModule: 'store',
74
42
  docs: {
75
43
  description: 'Selector can be used either with `select` as a pipeable operator or as a method.',
76
- recommended: 'warn',
77
44
  },
78
45
  fixable: 'code',
79
46
  schema: [
80
47
  {
81
48
  type: 'string',
82
- enum: ["method" /* SelectStyle.Method */, "operator" /* SelectStyle.Operator */],
83
- additionalProperties: false,
49
+ enum: [SelectStyle.Method, SelectStyle.Operator],
84
50
  },
85
51
  ],
86
- messages: (_a = {},
87
- _a["method" /* SelectStyle.Method */] = 'Selector should be used with select method: `this.store.select(selector)`.',
88
- _a["operator" /* SelectStyle.Operator */] = 'Selector should be used with the pipeable operator: `this.store.pipe(select(selector))`.',
89
- _a),
52
+ messages: {
53
+ [SelectStyle.Method]: 'Selector should be used with select method: `this.store.select(selector)`.',
54
+ [SelectStyle.Operator]: 'Selector should be used with the pipeable operator: `this.store.pipe(select(selector))`.',
55
+ },
90
56
  },
91
- defaultOptions: ["method" /* SelectStyle.Method */],
92
- create: function (context, _a) {
93
- var _b, _c;
94
- var _d = __read(_a, 1), mode = _d[0];
95
- var _e = (0, utils_1.getNgRxStores)(context), _f = _e.identifiers, identifiers = _f === void 0 ? [] : _f, sourceCode = _e.sourceCode;
96
- var storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
57
+ defaultOptions: [SelectStyle.Method],
58
+ create: (context, [mode]) => {
59
+ const { identifiers = [], sourceCode } = (0, utils_1.getNgRxStores)(context);
60
+ const storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
97
61
  if (!storeNames) {
98
62
  return {};
99
63
  }
100
- if (mode === "operator" /* SelectStyle.Operator */) {
101
- return _b = {},
102
- _b[(0, utils_1.selectExpression)(storeNames)] = function (node) {
64
+ if (mode === SelectStyle.Operator) {
65
+ return {
66
+ [(0, utils_1.selectExpression)(storeNames)](node) {
103
67
  context.report({
104
68
  node: node.callee.property,
105
- messageId: "operator" /* SelectStyle.Operator */,
106
- fix: function (fixer) { return getMethodToOperatorFixes(node, fixer); },
69
+ messageId: SelectStyle.Operator,
70
+ fix: (fixer) => getMethodToOperatorFixes(node, fixer),
107
71
  });
108
72
  },
109
- _b;
73
+ };
110
74
  }
111
- return _c = {},
112
- _c["Program:has(".concat((0, utils_1.pipeableSelect)(storeNames), ") ImportDeclaration[source.value='").concat(utils_1.NGRX_MODULE_PATHS.store, "'] > ImportSpecifier[imported.name='select']")] = function (node) {
113
- var e_1, _a;
75
+ return {
76
+ [`Program:has(${(0, utils_1.pipeableSelect)(storeNames)}) ImportDeclaration[source.value='${utils_1.NGRX_MODULE_PATHS.store}'] > ImportSpecifier[imported.name='select']`](node) {
114
77
  context.report({
115
- node: node,
116
- messageId: "method" /* SelectStyle.Method */,
117
- fix: function (fixer) {
118
- return (0, utils_1.getImportRemoveFix)(sourceCode, [node.parent], 'select', fixer);
119
- },
78
+ node,
79
+ messageId: SelectStyle.Method,
80
+ fix: (fixer) => (0, utils_1.getImportRemoveFix)(sourceCode, [node.parent], 'select', fixer),
120
81
  });
121
- var _b = __read(context.getDeclaredVariables(node), 1), references = _b[0].references;
122
- var _loop_1 = function (identifier) {
82
+ const [{ references }] = sourceCode.getDeclaredVariables(node);
83
+ for (const { identifier } of references) {
123
84
  context.report({
124
85
  node: identifier,
125
- messageId: "method" /* SelectStyle.Method */,
126
- fix: function (fixer) {
127
- return getOperatorToMethodFixes(identifier, sourceCode, fixer);
128
- },
86
+ messageId: SelectStyle.Method,
87
+ fix: (fixer) => getOperatorToMethodFixes(identifier, sourceCode, fixer),
129
88
  });
130
- };
131
- try {
132
- for (var references_1 = __values(references), references_1_1 = references_1.next(); !references_1_1.done; references_1_1 = references_1.next()) {
133
- var identifier = references_1_1.value.identifier;
134
- _loop_1(identifier);
135
- }
136
- }
137
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
138
- finally {
139
- try {
140
- if (references_1_1 && !references_1_1.done && (_a = references_1.return)) _a.call(references_1);
141
- }
142
- finally { if (e_1) throw e_1.error; }
143
89
  }
144
90
  },
145
- _c;
91
+ };
146
92
  },
147
93
  });
148
94
  function getMethodToOperatorFixes(node, fixer) {
149
- var classDeclaration = (0, utils_1.getNearestUpperNodeFrom)(node, utils_1.isClassDeclaration);
95
+ const classDeclaration = (0, utils_1.getNearestUpperNodeFrom)(node, utils_1.isClassDeclaration);
150
96
  if (!classDeclaration) {
151
97
  return [];
152
98
  }
@@ -154,40 +100,39 @@ function getMethodToOperatorFixes(node, fixer) {
154
100
  fixer.insertTextBefore(node.callee.property, 'pipe('),
155
101
  fixer.insertTextAfter(node, ')'),
156
102
  ].concat((0, utils_1.getImportAddFix)({
157
- fixer: fixer,
103
+ fixer,
158
104
  importName: 'select',
159
105
  moduleName: utils_1.NGRX_MODULE_PATHS.store,
160
106
  node: classDeclaration,
161
107
  }));
162
108
  }
163
109
  function getOperatorToMethodFixes(identifier, sourceCode, fixer) {
164
- var _a;
165
- var select = identifier.parent;
166
- var storePipe = select === null || select === void 0 ? void 0 : select.parent;
110
+ const select = identifier.parent;
111
+ const storePipe = select?.parent;
167
112
  if (!storePipe ||
168
113
  !(0, utils_1.isCallExpression)(storePipe) ||
169
114
  !(0, utils_1.isMemberExpression)(storePipe.callee)) {
170
115
  return [];
171
116
  }
172
- var pipeContainsOnlySelect = storePipe.arguments.length === 1;
117
+ const pipeContainsOnlySelect = storePipe.arguments.length === 1;
173
118
  if (!pipeContainsOnlySelect) {
174
- var selectContent = sourceCode.getText(select);
175
- var nextTokenAfterSelect = sourceCode.getTokenAfter(select);
176
- var store = storePipe.callee.object;
177
- return __spreadArray(__spreadArray([
178
- fixer.remove(select)
179
- ], __read((nextTokenAfterSelect ? [fixer.remove(nextTokenAfterSelect)] : [])), false), [
180
- fixer.insertTextAfter(store, ".".concat(selectContent)),
181
- ], false);
119
+ const selectContent = sourceCode.getText(select);
120
+ const nextTokenAfterSelect = sourceCode.getTokenAfter(select);
121
+ const store = storePipe.callee.object;
122
+ return [
123
+ fixer.remove(select),
124
+ ...(nextTokenAfterSelect ? [fixer.remove(nextTokenAfterSelect)] : []),
125
+ fixer.insertTextAfter(store, `.${selectContent}`),
126
+ ];
182
127
  }
183
- var property = storePipe.callee.property;
184
- var nextTokenAfterPipe = sourceCode.getTokenAfter(property);
185
- var _b = __read(property.range, 2), pipeInitialRange = _b[0], pipeEndRange = _b[1];
186
- var pipeRange = [
128
+ const { property } = storePipe.callee;
129
+ const nextTokenAfterPipe = sourceCode.getTokenAfter(property);
130
+ const [pipeInitialRange, pipeEndRange] = property.range;
131
+ const pipeRange = [
187
132
  pipeInitialRange,
188
- (_a = nextTokenAfterPipe === null || nextTokenAfterPipe === void 0 ? void 0 : nextTokenAfterPipe.range[1]) !== null && _a !== void 0 ? _a : pipeEndRange,
133
+ nextTokenAfterPipe?.range[1] ?? pipeEndRange,
189
134
  ];
190
- var _c = __read(identifier.range, 2), selectEndRange = _c[1];
135
+ const [, selectEndRange] = identifier.range;
191
136
  return [
192
137
  fixer.removeRange(pipeRange),
193
138
  fixer.insertTextAfterRange([selectEndRange, selectEndRange + 1], '('),
@@ -1 +1 @@
1
- {"version":3,"file":"select-style.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/select-style.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAYqB;AAER,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAwB/C,kBAAe,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,EACT,kFAAkF;YACpF,WAAW,EAAE,MAAM;SACpB;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,0EAA0C;gBAChD,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BAAoB,CAAC,CAAC,cAAc,EAAE,cAAc,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getImportAddFix,\n getImportRemoveFix,\n getNearestUpperNodeFrom,\n getNgRxStores,\n isCallExpression,\n isClassDeclaration,\n isMemberExpression,\n NGRX_MODULE_PATHS,\n pipeableSelect,\n selectExpression,\n} from '../../utils';\n\nexport const selectMethod = 'selectMethod';\nexport const selectOperator = 'selectOperator';\n\nexport const enum SelectStyle {\n Method = 'method',\n Operator = 'operator',\n}\n\ntype MessageIds = `${SelectStyle}`;\ntype Options = readonly [MessageIds];\ntype MemberExpressionWithProperty = Omit<\n TSESTree.MemberExpression,\n 'property'\n> & {\n property: TSESTree.Identifier;\n};\ntype CallExpression = Omit<TSESTree.CallExpression, 'parent'> & {\n callee: MemberExpressionWithProperty;\n parent: TSESTree.CallExpression & {\n callee: Omit<TSESTree.MemberExpression, 'object'> & {\n object: MemberExpressionWithProperty;\n };\n };\n};\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description:\n 'Selector can be used either with `select` as a pipeable operator or as a method.',\n recommended: 'warn',\n },\n fixable: 'code',\n schema: [\n {\n type: 'string',\n enum: [SelectStyle.Method, SelectStyle.Operator],\n additionalProperties: false,\n },\n ],\n messages: {\n [SelectStyle.Method]:\n 'Selector should be used with select method: `this.store.select(selector)`.',\n [SelectStyle.Operator]:\n 'Selector should be used with the pipeable operator: `this.store.pipe(select(selector))`.',\n },\n },\n defaultOptions: [SelectStyle.Method],\n create: (context, [mode]) => {\n const { identifiers = [], sourceCode } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n if (mode === SelectStyle.Operator) {\n return {\n [selectExpression(storeNames)](node: CallExpression) {\n context.report({\n node: node.callee.property,\n messageId: SelectStyle.Operator,\n fix: (fixer) => getMethodToOperatorFixes(node, fixer),\n });\n },\n };\n }\n\n return {\n [`Program:has(${pipeableSelect(\n storeNames\n )}) ImportDeclaration[source.value='${\n NGRX_MODULE_PATHS.store\n }'] > ImportSpecifier[imported.name='select']`](\n node: TSESTree.ImportSpecifier & {\n parent: TSESTree.ImportDeclaration;\n }\n ) {\n context.report({\n node,\n messageId: SelectStyle.Method,\n fix: (fixer) =>\n getImportRemoveFix(sourceCode, [node.parent], 'select', fixer),\n });\n\n const [{ references }] = context.getDeclaredVariables(node);\n\n for (const { identifier } of references) {\n context.report({\n node: identifier,\n messageId: SelectStyle.Method,\n fix: (fixer) =>\n getOperatorToMethodFixes(identifier, sourceCode, fixer),\n });\n }\n },\n };\n },\n});\n\nfunction getMethodToOperatorFixes(\n node: CallExpression,\n fixer: TSESLint.RuleFixer\n): readonly TSESLint.RuleFix[] {\n const classDeclaration = getNearestUpperNodeFrom(node, isClassDeclaration);\n\n if (!classDeclaration) {\n return [];\n }\n\n return [\n fixer.insertTextBefore(node.callee.property, 'pipe('),\n fixer.insertTextAfter(node, ')'),\n ].concat(\n getImportAddFix({\n fixer,\n importName: 'select',\n moduleName: NGRX_MODULE_PATHS.store,\n node: classDeclaration,\n })\n );\n}\n\nfunction getOperatorToMethodFixes(\n identifier: TSESTree.Node,\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer\n): readonly TSESLint.RuleFix[] {\n const select = identifier.parent;\n const storePipe = select?.parent;\n\n if (\n !storePipe ||\n !isCallExpression(storePipe) ||\n !isMemberExpression(storePipe.callee)\n ) {\n return [];\n }\n\n const pipeContainsOnlySelect = storePipe.arguments.length === 1;\n\n if (!pipeContainsOnlySelect) {\n const selectContent = sourceCode.getText(select);\n const nextTokenAfterSelect = sourceCode.getTokenAfter(select);\n const store = storePipe.callee.object;\n return [\n fixer.remove(select),\n ...(nextTokenAfterSelect ? [fixer.remove(nextTokenAfterSelect)] : []),\n fixer.insertTextAfter(store, `.${selectContent}`),\n ];\n }\n\n const { property } = storePipe.callee;\n const nextTokenAfterPipe = sourceCode.getTokenAfter(property);\n const [pipeInitialRange, pipeEndRange] = property.range;\n const pipeRange: TSESTree.Range = [\n pipeInitialRange,\n nextTokenAfterPipe?.range[1] ?? pipeEndRange,\n ];\n const [, selectEndRange] = identifier.range;\n return [\n fixer.removeRange(pipeRange),\n fixer.insertTextAfterRange([selectEndRange, selectEndRange + 1], '('),\n ];\n}\n"]}
1
+ {"version":3,"file":"select-style.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/select-style.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAYqB;AAER,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAE/C,IAAkB,WAGjB;AAHD,WAAkB,WAAW;IAC3B,gCAAiB,CAAA;IACjB,oCAAqB,CAAA;AACvB,CAAC,EAHiB,WAAW,2BAAX,WAAW,QAG5B;AAmBD,kBAAe,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,EACT,kFAAkF;SACrF;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;aACjD;SACF;QACD,QAAQ,EAAE;YACR,CAAC,WAAW,CAAC,MAAM,CAAC,EAClB,4EAA4E;YAC9E,CAAC,WAAW,CAAC,QAAQ,CAAC,EACpB,0FAA0F;S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C;IAED,MAAM,sBAAsB,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IAEhE,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACjD,MAAM,oBAAoB,GAAG,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,OAAO;YACL,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;YACpB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,KAAK,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,aAAa,EAAE,CAAC;SAClD,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC;IACtC,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC9D,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;IACxD,MAAM,SAAS,GAAmB;QAChC,gBAAgB;QAChB,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,YAAY;KAC7C,CAAC;IACF,MAAM,CAAC,EAAE,cAAc,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;IAC5C,OAAO;QACL,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC;QAC5B,KAAK,CAAC,oBAAoB,CAAC,CAAC,cAAc,EAAE,cAAc,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getImportAddFix,\n getImportRemoveFix,\n getNearestUpperNodeFrom,\n getNgRxStores,\n isCallExpression,\n isClassDeclaration,\n isMemberExpression,\n NGRX_MODULE_PATHS,\n pipeableSelect,\n selectExpression,\n} from '../../utils';\n\nexport const selectMethod = 'selectMethod';\nexport const selectOperator = 'selectOperator';\n\nexport const enum SelectStyle {\n Method = 'method',\n Operator = 'operator',\n}\n\ntype MessageIds = `${SelectStyle}`;\ntype Options = readonly [MessageIds];\ntype MemberExpressionWithProperty = Omit<\n TSESTree.MemberExpression,\n 'property'\n> & {\n property: TSESTree.Identifier;\n};\ntype CallExpression = Omit<TSESTree.CallExpression, 'parent'> & {\n callee: MemberExpressionWithProperty;\n parent: TSESTree.CallExpression & {\n callee: Omit<TSESTree.MemberExpression, 'object'> & {\n object: MemberExpressionWithProperty;\n };\n };\n};\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description:\n 'Selector can be used either with `select` as a pipeable operator or as a method.',\n },\n fixable: 'code',\n schema: [\n {\n type: 'string',\n enum: [SelectStyle.Method, SelectStyle.Operator],\n },\n ],\n messages: {\n [SelectStyle.Method]:\n 'Selector should be used with select method: `this.store.select(selector)`.',\n [SelectStyle.Operator]:\n 'Selector should be used with the pipeable operator: `this.store.pipe(select(selector))`.',\n },\n },\n defaultOptions: [SelectStyle.Method],\n create: (context, [mode]) => {\n const { identifiers = [], sourceCode } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n if (mode === SelectStyle.Operator) {\n return {\n [selectExpression(storeNames)](node: CallExpression) {\n context.report({\n node: node.callee.property,\n messageId: SelectStyle.Operator,\n fix: (fixer) => getMethodToOperatorFixes(node, fixer),\n });\n },\n };\n }\n\n return {\n [`Program:has(${pipeableSelect(\n storeNames\n )}) ImportDeclaration[source.value='${\n NGRX_MODULE_PATHS.store\n }'] > ImportSpecifier[imported.name='select']`](\n node: TSESTree.ImportSpecifier & {\n parent: TSESTree.ImportDeclaration;\n }\n ) {\n context.report({\n node,\n messageId: SelectStyle.Method,\n fix: (fixer) =>\n getImportRemoveFix(sourceCode, [node.parent], 'select', fixer),\n });\n\n const [{ references }] = sourceCode.getDeclaredVariables(node);\n\n for (const { identifier } of references) {\n context.report({\n node: identifier,\n messageId: SelectStyle.Method,\n fix: (fixer) =>\n getOperatorToMethodFixes(identifier, sourceCode, fixer),\n });\n }\n },\n };\n },\n});\n\nfunction getMethodToOperatorFixes(\n node: CallExpression,\n fixer: TSESLint.RuleFixer\n): readonly TSESLint.RuleFix[] {\n const classDeclaration = getNearestUpperNodeFrom(node, isClassDeclaration);\n\n if (!classDeclaration) {\n return [];\n }\n\n return [\n fixer.insertTextBefore(node.callee.property, 'pipe('),\n fixer.insertTextAfter(node, ')'),\n ].concat(\n getImportAddFix({\n fixer,\n importName: 'select',\n moduleName: NGRX_MODULE_PATHS.store,\n node: classDeclaration,\n })\n );\n}\n\nfunction getOperatorToMethodFixes(\n identifier: TSESTree.Node,\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer\n): readonly TSESLint.RuleFix[] {\n const select = identifier.parent;\n const storePipe = select?.parent;\n\n if (\n !storePipe ||\n !isCallExpression(storePipe) ||\n !isMemberExpression(storePipe.callee)\n ) {\n return [];\n }\n\n const pipeContainsOnlySelect = storePipe.arguments.length === 1;\n\n if (!pipeContainsOnlySelect) {\n const selectContent = sourceCode.getText(select);\n const nextTokenAfterSelect = sourceCode.getTokenAfter(select);\n const store = storePipe.callee.object;\n return [\n fixer.remove(select),\n ...(nextTokenAfterSelect ? [fixer.remove(nextTokenAfterSelect)] : []),\n fixer.insertTextAfter(store, `.${selectContent}`),\n ];\n }\n\n const { property } = storePipe.callee;\n const nextTokenAfterPipe = sourceCode.getTokenAfter(property);\n const [pipeInitialRange, pipeEndRange] = property.range;\n const pipeRange: TSESTree.Range = [\n pipeInitialRange,\n nextTokenAfterPipe?.range[1] ?? pipeEndRange,\n ];\n const [, selectEndRange] = identifier.range;\n return [\n fixer.removeRange(pipeRange),\n fixer.insertTextAfterRange([selectEndRange, selectEndRange + 1], '('),\n ];\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const useConsistentGlobalStoreName = "useConsistentGlobalStoreName";
2
+ export declare const useConsistentGlobalStoreNameSuggest = "useConsistentGlobalStoreNameSuggest";
3
+ type MessageIds = typeof useConsistentGlobalStoreName | typeof useConsistentGlobalStoreNameSuggest;
4
+ type Options = readonly [string];
5
+ declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
6
+ export default _default;