@ngrx/eslint-plugin 18.0.0-beta.1 → 18.0.0-rc.1

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 +4 -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 +18 -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 +13 -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 +153 -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 +35 -0
  88. package/src/rules/index.js +74 -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 +10 -11
  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
@@ -0,0 +1,48 @@
1
+ import type { TSESLint, TSESTree } from '@typescript-eslint/utils';
2
+ type ConstructorFunctionExpression = TSESTree.FunctionExpression & {
3
+ parent: TSESTree.MethodDefinition & {
4
+ kind: 'constructor';
5
+ };
6
+ };
7
+ type InjectedParameter = TSESTree.Identifier & {
8
+ typeAnnotation: TSESTree.TSTypeAnnotation;
9
+ parent: ConstructorFunctionExpression | (TSESTree.TSParameterProperty & {
10
+ parent: ConstructorFunctionExpression;
11
+ }) | TSESTree.PropertyDefinition;
12
+ };
13
+ type InjectedParameterWithSourceCode = Readonly<{
14
+ identifiers?: readonly InjectedParameter[];
15
+ sourceCode: Readonly<TSESLint.SourceCode>;
16
+ }>;
17
+ export declare function getNearestUpperNodeFrom<T extends TSESTree.Node>({ parent }: TSESTree.Node, predicate: (parent: TSESTree.Node) => parent is T): T | undefined;
18
+ export declare function getImportDeclarationSpecifier(importDeclarations: readonly TSESTree.ImportDeclaration[], importName: string): {
19
+ readonly importDeclaration: TSESTree.ImportDeclaration;
20
+ readonly importSpecifier: TSESTree.ImportSpecifier;
21
+ } | undefined;
22
+ export declare function getImportDeclarations(node: TSESTree.Node, moduleName: string): readonly TSESTree.ImportDeclaration[] | undefined;
23
+ export declare function getImportAddFix({ compatibleWithTypeOnlyImport, fixer, importName, moduleName, node, }: {
24
+ compatibleWithTypeOnlyImport?: boolean;
25
+ fixer: TSESLint.RuleFixer;
26
+ importName: string;
27
+ moduleName: string;
28
+ node: TSESTree.Node;
29
+ }): TSESLint.RuleFix | TSESLint.RuleFix[];
30
+ export declare function getImportRemoveFix(sourceCode: Readonly<TSESLint.SourceCode>, importDeclarations: readonly TSESTree.ImportDeclaration[], importedName: string, fixer: TSESLint.RuleFixer): TSESLint.RuleFix | TSESLint.RuleFix[];
31
+ export declare function getNodeToCommaRemoveFix(sourceCode: Readonly<TSESLint.SourceCode>, fixer: TSESLint.RuleFixer, node: TSESTree.Node): readonly [TSESLint.RuleFix, ...TSESLint.RuleFix[]];
32
+ export declare function getInterfaceName(interfaceMember: TSESTree.Identifier | TSESTree.MemberExpression): string | undefined;
33
+ export declare function getInterfaces({ implements: classImplements, }: TSESTree.ClassDeclaration): readonly (TSESTree.Identifier | TSESTree.MemberExpression)[];
34
+ export declare function getInterface(node: TSESTree.ClassDeclaration, interfaceName: string): TSESTree.Identifier | TSESTree.MemberExpression | undefined;
35
+ export declare function getImplementsSchemaFixer({ id, implements: classImplements }: TSESTree.ClassDeclaration, interfaceName: string): {
36
+ readonly implementsNodeReplace: TSESTree.Identifier | TSESTree.TSClassImplements;
37
+ readonly implementsTextReplace: string;
38
+ };
39
+ export declare function getLast<T extends readonly unknown[]>(items: T): T[number];
40
+ export declare function getDecoratorName({ expression, }: TSESTree.Decorator): string | undefined;
41
+ export declare function getRawText(node: TSESTree.Node): string | null;
42
+ export declare function capitalize<T extends string>(text: T): Capitalize<T>;
43
+ export declare function getNgRxEffectActions(context: TSESLint.RuleContext<string, readonly unknown[]>): InjectedParameterWithSourceCode;
44
+ export declare function getNgRxComponentStores(context: TSESLint.RuleContext<string, readonly unknown[]>): InjectedParameterWithSourceCode;
45
+ export declare function getNgRxStores(context: TSESLint.RuleContext<string, readonly unknown[]>): InjectedParameterWithSourceCode;
46
+ export declare function escapeText(text: string): string;
47
+ export declare function asPattern(identifiers: readonly InjectedParameter[]): RegExp;
48
+ export {};
@@ -1,47 +1,10 @@
1
1
  "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
- if (ar || !(i in from)) {
32
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
- ar[i] = from[i];
34
- }
35
- }
36
- return to.concat(ar || Array.prototype.slice.call(from));
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.asPattern = exports.escapeText = exports.getNgRxStores = exports.getNgRxComponentStores = exports.getNgRxEffectActions = exports.capitalize = exports.getRawText = exports.getDecoratorName = exports.getLast = exports.getImplementsSchemaFixer = exports.getInterface = exports.getInterfaces = exports.getInterfaceName = exports.getNodeToCommaRemoveFix = exports.getImportRemoveFix = exports.getImportAddFix = exports.getImportDeclarations = exports.getImportDeclarationSpecifier = exports.getNearestUpperNodeFrom = void 0;
40
- var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
41
- var guards_1 = require("./guards");
42
- var ngrx_modules_1 = require("./ngrx-modules");
43
- function getNearestUpperNodeFrom(_a, predicate) {
44
- var parent = _a.parent;
4
+ const utils_1 = require("@typescript-eslint/utils");
5
+ const guards_1 = require("./guards");
6
+ const ngrx_modules_1 = require("./ngrx-modules");
7
+ function getNearestUpperNodeFrom({ parent }, predicate) {
45
8
  while (parent && !(0, guards_1.isProgram)(parent)) {
46
9
  if (predicate(parent)) {
47
10
  return parent;
@@ -52,104 +15,79 @@ function getNearestUpperNodeFrom(_a, predicate) {
52
15
  }
53
16
  exports.getNearestUpperNodeFrom = getNearestUpperNodeFrom;
54
17
  function getImportDeclarationSpecifier(importDeclarations, importName) {
55
- var e_1, _a;
56
- try {
57
- for (var importDeclarations_1 = __values(importDeclarations), importDeclarations_1_1 = importDeclarations_1.next(); !importDeclarations_1_1.done; importDeclarations_1_1 = importDeclarations_1.next()) {
58
- var importDeclaration = importDeclarations_1_1.value;
59
- var importSpecifier = importDeclaration.specifiers.find(function (importClause) {
60
- return ((0, guards_1.isImportSpecifier)(importClause) &&
61
- importClause.imported.name === importName);
62
- });
63
- if (importSpecifier) {
64
- return { importDeclaration: importDeclaration, importSpecifier: importSpecifier };
65
- }
18
+ for (const importDeclaration of importDeclarations) {
19
+ const importSpecifier = importDeclaration.specifiers.find((importClause) => {
20
+ return ((0, guards_1.isImportSpecifier)(importClause) &&
21
+ importClause.imported.name === importName);
22
+ });
23
+ if (importSpecifier) {
24
+ return { importDeclaration, importSpecifier };
66
25
  }
67
26
  }
68
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
69
- finally {
70
- try {
71
- if (importDeclarations_1_1 && !importDeclarations_1_1.done && (_a = importDeclarations_1.return)) _a.call(importDeclarations_1);
72
- }
73
- finally { if (e_1) throw e_1.error; }
74
- }
75
27
  return undefined;
76
28
  }
77
29
  exports.getImportDeclarationSpecifier = getImportDeclarationSpecifier;
78
30
  function getImportDeclarations(node, moduleName) {
79
- var parentNode = node;
31
+ let parentNode = node;
80
32
  while (parentNode && !(0, guards_1.isProgram)(parentNode)) {
81
33
  parentNode = parentNode.parent;
82
34
  }
83
- return parentNode === null || parentNode === void 0 ? void 0 : parentNode.body.filter(function (node) {
35
+ return parentNode?.body.filter((node) => {
84
36
  return (0, guards_1.isImportDeclaration)(node) && node.source.value === moduleName;
85
37
  });
86
38
  }
87
39
  exports.getImportDeclarations = getImportDeclarations;
88
- function getCorrespondentImportClause(importDeclarations, compatibleWithTypeOnlyImport) {
89
- var e_2, _a;
90
- if (compatibleWithTypeOnlyImport === void 0) { compatibleWithTypeOnlyImport = false; }
91
- var importClause;
92
- try {
93
- for (var importDeclarations_2 = __values(importDeclarations), importDeclarations_2_1 = importDeclarations_2.next(); !importDeclarations_2_1.done; importDeclarations_2_1 = importDeclarations_2.next()) {
94
- var _b = importDeclarations_2_1.value, importKind = _b.importKind, specifiers = _b.specifiers;
95
- var lastImportSpecifier = getLast(specifiers);
96
- if ((!compatibleWithTypeOnlyImport && importKind === 'type') ||
97
- (0, guards_1.isImportNamespaceSpecifier)(lastImportSpecifier)) {
98
- continue;
99
- }
100
- importClause = lastImportSpecifier;
101
- }
102
- }
103
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
104
- finally {
105
- try {
106
- if (importDeclarations_2_1 && !importDeclarations_2_1.done && (_a = importDeclarations_2.return)) _a.call(importDeclarations_2);
40
+ function getCorrespondentImportClause(importDeclarations, compatibleWithTypeOnlyImport = false) {
41
+ let importClause;
42
+ for (const { importKind, specifiers } of importDeclarations) {
43
+ const lastImportSpecifier = getLast(specifiers);
44
+ if ((!compatibleWithTypeOnlyImport && importKind === 'type') ||
45
+ (0, guards_1.isImportNamespaceSpecifier)(lastImportSpecifier)) {
46
+ continue;
107
47
  }
108
- finally { if (e_2) throw e_2.error; }
48
+ importClause = lastImportSpecifier;
109
49
  }
110
50
  return importClause;
111
51
  }
112
- function getImportAddFix(_a) {
113
- var _b = _a.compatibleWithTypeOnlyImport, compatibleWithTypeOnlyImport = _b === void 0 ? false : _b, fixer = _a.fixer, importName = _a.importName, moduleName = _a.moduleName, node = _a.node;
114
- var fullImport = "import { ".concat(importName, " } from '").concat(moduleName, "';\n");
115
- var importDeclarations = getImportDeclarations(node, moduleName);
116
- if (!(importDeclarations === null || importDeclarations === void 0 ? void 0 : importDeclarations.length)) {
52
+ function getImportAddFix({ compatibleWithTypeOnlyImport = false, fixer, importName, moduleName, node, }) {
53
+ const fullImport = `import { ${importName} } from '${moduleName}';`;
54
+ const importDeclarations = getImportDeclarations(node, moduleName);
55
+ if (!importDeclarations?.length) {
117
56
  return fixer.insertTextAfterRange([0, 0], fullImport);
118
57
  }
119
- var importDeclarationSpecifier = getImportDeclarationSpecifier(importDeclarations, importName);
58
+ const importDeclarationSpecifier = getImportDeclarationSpecifier(importDeclarations, importName);
120
59
  if (importDeclarationSpecifier) {
121
60
  return [];
122
61
  }
123
- var importClause = getCorrespondentImportClause(importDeclarations, compatibleWithTypeOnlyImport);
62
+ const importClause = getCorrespondentImportClause(importDeclarations, compatibleWithTypeOnlyImport);
124
63
  if (!importClause) {
125
64
  return fixer.insertTextAfterRange([0, 0], fullImport);
126
65
  }
127
- var replacementText = (0, guards_1.isImportDefaultSpecifier)(importClause)
128
- ? ", { ".concat(importName, " }")
129
- : ", ".concat(importName);
66
+ const replacementText = (0, guards_1.isImportDefaultSpecifier)(importClause)
67
+ ? `, { ${importName} }`
68
+ : `, ${importName}`;
130
69
  return fixer.insertTextAfter(importClause, replacementText);
131
70
  }
132
71
  exports.getImportAddFix = getImportAddFix;
133
72
  function getImportRemoveFix(sourceCode, importDeclarations, importedName, fixer) {
134
- var _a;
135
- var _b = (_a = getImportDeclarationSpecifier(importDeclarations, importedName)) !== null && _a !== void 0 ? _a : {}, importDeclaration = _b.importDeclaration, importSpecifier = _b.importSpecifier;
73
+ const { importDeclaration, importSpecifier } = getImportDeclarationSpecifier(importDeclarations, importedName) ?? {};
136
74
  if (!importDeclaration || !importSpecifier) {
137
75
  return [];
138
76
  }
139
- var isFirstImportSpecifier = importDeclaration.specifiers[0] === importSpecifier;
140
- var isLastImportSpecifier = getLast(importDeclaration.specifiers) === importSpecifier;
141
- var isSingleImportSpecifier = isFirstImportSpecifier && isLastImportSpecifier;
77
+ const isFirstImportSpecifier = importDeclaration.specifiers[0] === importSpecifier;
78
+ const isLastImportSpecifier = getLast(importDeclaration.specifiers) === importSpecifier;
79
+ const isSingleImportSpecifier = isFirstImportSpecifier && isLastImportSpecifier;
142
80
  if (isSingleImportSpecifier) {
143
81
  return fixer.remove(importDeclaration);
144
82
  }
145
- var tokenAfterImportSpecifier = sourceCode.getTokenAfter(importSpecifier);
83
+ const tokenAfterImportSpecifier = sourceCode.getTokenAfter(importSpecifier);
146
84
  if (isFirstImportSpecifier && tokenAfterImportSpecifier) {
147
85
  return fixer.removeRange([
148
86
  importSpecifier.range[0],
149
87
  tokenAfterImportSpecifier.range[1],
150
88
  ]);
151
89
  }
152
- var tokenBeforeImportSpecifier = sourceCode.getTokenBefore(importSpecifier);
90
+ const tokenBeforeImportSpecifier = sourceCode.getTokenBefore(importSpecifier);
153
91
  if (!tokenBeforeImportSpecifier) {
154
92
  return [];
155
93
  }
@@ -160,11 +98,12 @@ function getImportRemoveFix(sourceCode, importDeclarations, importedName, fixer)
160
98
  }
161
99
  exports.getImportRemoveFix = getImportRemoveFix;
162
100
  function getNodeToCommaRemoveFix(sourceCode, fixer, node) {
163
- var nextToken = sourceCode.getTokenAfter(node);
164
- var isNextTokenComma = nextToken && experimental_utils_1.ASTUtils.isCommaToken(nextToken);
165
- return __spreadArray([
166
- fixer.remove(node)
167
- ], __read((isNextTokenComma ? [fixer.remove(nextToken)] : [])), false);
101
+ const nextToken = sourceCode.getTokenAfter(node);
102
+ const isNextTokenComma = nextToken && utils_1.ASTUtils.isCommaToken(nextToken);
103
+ return [
104
+ fixer.remove(node),
105
+ ...(isNextTokenComma ? [fixer.remove(nextToken)] : []),
106
+ ];
168
107
  }
169
108
  exports.getNodeToCommaRemoveFix = getNodeToCommaRemoveFix;
170
109
  function getInterfaceName(interfaceMember) {
@@ -176,34 +115,28 @@ function getInterfaceName(interfaceMember) {
176
115
  : undefined;
177
116
  }
178
117
  exports.getInterfaceName = getInterfaceName;
179
- function getInterfaces(_a) {
180
- var classImplements = _a.implements;
181
- return (classImplements !== null && classImplements !== void 0 ? classImplements : [])
182
- .map(function (_a) {
183
- var expression = _a.expression;
184
- return expression;
185
- })
118
+ function getInterfaces({ implements: classImplements, }) {
119
+ return (classImplements ?? [])
120
+ .map(({ expression }) => expression)
186
121
  .filter(guards_1.isIdentifierOrMemberExpression);
187
122
  }
188
123
  exports.getInterfaces = getInterfaces;
189
124
  function getInterface(node, interfaceName) {
190
- return getInterfaces(node).find(function (interfaceMember) { return getInterfaceName(interfaceMember) === interfaceName; });
125
+ return getInterfaces(node).find((interfaceMember) => getInterfaceName(interfaceMember) === interfaceName);
191
126
  }
192
127
  exports.getInterface = getInterface;
193
- function getImplementsSchemaFixer(_a, interfaceName) {
194
- var id = _a.id, classImplements = _a.implements;
195
- var _b = __read(classImplements && classImplements.length
196
- ? [getLast(classImplements), ", ".concat(interfaceName)]
197
- : [id, " implements ".concat(interfaceName)], 2), implementsNodeReplace = _b[0], implementsTextReplace = _b[1];
198
- return { implementsNodeReplace: implementsNodeReplace, implementsTextReplace: implementsTextReplace };
128
+ function getImplementsSchemaFixer({ id, implements: classImplements }, interfaceName) {
129
+ const [implementsNodeReplace, implementsTextReplace] = classImplements && classImplements.length
130
+ ? [getLast(classImplements), `, ${interfaceName}`]
131
+ : [id, ` implements ${interfaceName}`];
132
+ return { implementsNodeReplace, implementsTextReplace };
199
133
  }
200
134
  exports.getImplementsSchemaFixer = getImplementsSchemaFixer;
201
135
  function getLast(items) {
202
136
  return items.slice(-1)[0];
203
137
  }
204
138
  exports.getLast = getLast;
205
- function getDecoratorName(_a) {
206
- var expression = _a.expression;
139
+ function getDecoratorName({ expression, }) {
207
140
  if ((0, guards_1.isIdentifier)(expression)) {
208
141
  return expression.name;
209
142
  }
@@ -225,35 +158,30 @@ function getRawText(node) {
225
158
  return node.raw;
226
159
  }
227
160
  if ((0, guards_1.isTemplateElement)(node)) {
228
- return "`".concat(node.value.raw, "`");
161
+ return `\`${node.value.raw}\``;
229
162
  }
230
163
  if ((0, guards_1.isTemplateLiteral)(node)) {
231
- return "`".concat(node.quasis[0].value.raw, "`");
164
+ return `\`${node.quasis[0].value.raw}\``;
232
165
  }
233
166
  return null;
234
167
  }
235
168
  exports.getRawText = getRawText;
236
169
  function capitalize(text) {
237
- return "".concat(text[0].toUpperCase()).concat(text.slice(1));
170
+ return `${text[0].toUpperCase()}${text.slice(1)}`;
238
171
  }
239
172
  exports.capitalize = capitalize;
240
173
  function getInjectedParametersWithSourceCode(context, moduleName, importName) {
241
- var _a, _b, _c, _d, _e;
242
- var sourceCode = context.getSourceCode();
243
- var importDeclarations = (_a = getImportDeclarations(sourceCode.ast, moduleName)) !== null && _a !== void 0 ? _a : [];
244
- var importSpecifier = ((_b = getImportDeclarationSpecifier(importDeclarations, importName)) !== null && _b !== void 0 ? _b : {}).importSpecifier;
245
- var injectImportDeclarations = (_c = getImportDeclarations(sourceCode.ast, '@angular/core')) !== null && _c !== void 0 ? _c : [];
246
- var injectImportSpecifier = ((_d = getImportDeclarationSpecifier(injectImportDeclarations, 'inject')) !== null && _d !== void 0 ? _d : {}).importSpecifier;
174
+ const sourceCode = context.getSourceCode();
175
+ const importDeclarations = getImportDeclarations(sourceCode.ast, moduleName) ?? [];
176
+ const { importSpecifier } = getImportDeclarationSpecifier(importDeclarations, importName) ?? {};
177
+ const injectImportDeclarations = getImportDeclarations(sourceCode.ast, '@angular/core') ?? [];
178
+ const { importSpecifier: injectImportSpecifier } = getImportDeclarationSpecifier(injectImportDeclarations, 'inject') ?? {};
247
179
  if (!importSpecifier) {
248
- return { sourceCode: sourceCode };
180
+ return { sourceCode };
249
181
  }
250
- var variables = context.getDeclaredVariables(importSpecifier);
251
- var typedVariable = variables.find(function (_a) {
252
- var name = _a.name;
253
- return name === importName;
254
- });
255
- var identifiers = (_e = typedVariable === null || typedVariable === void 0 ? void 0 : typedVariable.references) === null || _e === void 0 ? void 0 : _e.reduce(function (identifiers, _a) {
256
- var parent = _a.identifier.parent;
182
+ const variables = sourceCode.getDeclaredVariables(importSpecifier);
183
+ const typedVariable = variables.find(({ name }) => name === importName);
184
+ const identifiers = typedVariable?.references?.reduce((identifiers, { identifier: { parent } }) => {
257
185
  if (!parent) {
258
186
  return identifiers;
259
187
  }
@@ -264,7 +192,7 @@ function getInjectedParametersWithSourceCode(context, moduleName, importName) {
264
192
  (0, guards_1.isIdentifier)(parent.parent.parent)) {
265
193
  return identifiers.concat(parent.parent.parent);
266
194
  }
267
- var parentToCheck = (0, guards_1.isTSInstantiationExpression)(parent)
195
+ const parentToCheck = (0, guards_1.isTSInstantiationExpression)(parent)
268
196
  ? parent.parent
269
197
  : parent;
270
198
  if (parentToCheck &&
@@ -279,7 +207,7 @@ function getInjectedParametersWithSourceCode(context, moduleName, importName) {
279
207
  }
280
208
  return identifiers;
281
209
  }, []);
282
- return { identifiers: identifiers, sourceCode: sourceCode };
210
+ return { identifiers, sourceCode };
283
211
  }
284
212
  function getNgRxEffectActions(context) {
285
213
  return getInjectedParametersWithSourceCode(context, ngrx_modules_1.NGRX_MODULE_PATHS.effects, 'Actions');
@@ -299,11 +227,8 @@ function escapeText(text) {
299
227
  }
300
228
  exports.escapeText = escapeText;
301
229
  function asPattern(identifiers) {
302
- var escapedNames = identifiers.map(function (_a) {
303
- var name = _a.name;
304
- return escapeText(name);
305
- });
306
- return new RegExp("^(".concat(escapedNames.join('|'), ")$"));
230
+ const escapedNames = identifiers.map(({ name }) => escapeText(name));
231
+ return new RegExp(`^(${escapedNames.join('|')})$`);
307
232
  }
308
233
  exports.asPattern = asPattern;
309
234
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAiE;AACjE,mCAkBkB;AAClB,+CAAmD;AAoBnD,SAAgB,uBAAuB,CACrC,EAAyB,EACzB,SAAiD;QAD/C,MAAM,YAAA;IAGR,OAAO,MAAM,IAAI,CAAC,IAAA,kBAAS,EAAC,MAAM,CAAC,EAAE,CAAC;QACpC,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YACtB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAbD,0DAaC;AAED,SAAgB,6BAA6B,CAC3C,kBAAyD,EACzD,UAAkB;;;QAElB,KAAgC,IAAA,uBAAA,SAAA,kBAAkB,CAAA,sDAAA,sFAAE,CAAC;YAAhD,IAAM,iBAAiB,+BAAA;YAC1B,IAAM,eAAe,GAAG,iBAAiB,CAAC,UAAU,C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,EAAE,WAAW,aAAA,EAAE,UAAU,YAAA,EAAE,CAAC;AACrC,CAAC;AAED,SAAgB,oBAAoB,CAClC,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,OAAO,EACzB,SAAS,CACV,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,sBAAsB,CACpC,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,iBAAiB,CAAC,EACpC,gBAAgB,CACjB,CAAC;AACJ,CAAC;AARD,wDAQC;AAED,SAAgB,aAAa,CAC3B,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,KAAK,EACvB,OAAO,CACR,CAAC;AACJ,CAAC;AARD,sCAQC;AAED,6FAA6F;AAC7F,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAFD,gCAEC;AAED,SAAgB,SAAS,CAAC,WAAyC;IACjE,IAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,EAAQ;YAAN,IAAI,UAAA;QAAO,OAAA,UAAU,CAAC,IAAI,CAAC;IAAhB,CAAgB,CAAC,CAAC;IACrE,OAAO,IAAI,MAAM,CAAC,YAAK,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,OAAI,CAAC,CAAC;AACrD,CAAC;AAHD,8BAGC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ASTUtils } from '@typescript-eslint/experimental-utils';\nimport {\n isCallExpression,\n isIdentifier,\n isIdentifierOrMemberExpression,\n isImportDeclaration,\n isImportDefaultSpecifier,\n isImportNamespaceSpecifier,\n isImportSpecifier,\n isLiteral,\n isMethodDefinition,\n isProgram,\n isProperty,\n isPropertyDefinition,\n isTSTypeAnnotation,\n isTSTypeReference,\n isTemplateElement,\n isTemplateLiteral,\n isTSInstantiationExpression,\n} from './guards';\nimport { NGRX_MODULE_PATHS } from './ngrx-modules';\n\ntype ConstructorFunctionExpression = TSESTree.FunctionExpression & {\n parent: TSESTree.MethodDefinition & { kind: 'constructor' };\n};\ntype InjectedParameter =\n | TSESTree.Identifier & {\n typeAnnotation: TSESTree.TSTypeAnnotation;\n parent:\n | ConstructorFunctionExpression\n | (TSESTree.TSParameterProperty & {\n parent: ConstructorFunctionExpression;\n })\n | TSESTree.PropertyDefinition;\n };\ntype InjectedParameterWithSourceCode = Readonly<{\n identifiers?: readonly InjectedParameter[];\n sourceCode: Readonly<TSESLint.SourceCode>;\n}>;\n\nexport function getNearestUpperNodeFrom<T extends TSESTree.Node>(\n { parent }: TSESTree.Node,\n predicate: (parent: TSESTree.Node) => parent is T\n): T | undefined {\n while (parent && !isProgram(parent)) {\n if (predicate(parent)) {\n return parent;\n }\n\n parent = parent.parent;\n }\n\n return undefined;\n}\n\nexport function getImportDeclarationSpecifier(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importName: string\n) {\n for (const importDeclaration of importDeclarations) {\n const importSpecifier = importDeclaration.specifiers.find(\n (importClause): importClause is TSESTree.ImportSpecifier => {\n return (\n isImportSpecifier(importClause) &&\n importClause.imported.name === importName\n );\n }\n );\n\n if (importSpecifier) {\n return { importDeclaration, importSpecifier } as const;\n }\n }\n\n return undefined;\n}\n\nexport function getImportDeclarations(\n node: TSESTree.Node,\n moduleName: string\n): readonly TSESTree.ImportDeclaration[] | undefined {\n let parentNode: TSESTree.Node | undefined = node;\n\n while (parentNode && !isProgram(parentNode)) {\n parentNode = parentNode.parent;\n }\n\n return parentNode?.body.filter((node): node is TSESTree.ImportDeclaration => {\n return isImportDeclaration(node) && node.source.value === moduleName;\n });\n}\n\nfunction getCorrespondentImportClause(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n compatibleWithTypeOnlyImport = false\n) {\n let importClause: TSESTree.ImportClause | undefined;\n\n for (const { importKind, specifiers } of importDeclarations) {\n const lastImportSpecifier = getLast(specifiers);\n\n if (\n (!compatibleWithTypeOnlyImport && importKind === 'type') ||\n isImportNamespaceSpecifier(lastImportSpecifier)\n ) {\n continue;\n }\n\n importClause = lastImportSpecifier;\n }\n\n return importClause;\n}\n\nexport function getImportAddFix({\n compatibleWithTypeOnlyImport = false,\n fixer,\n importName,\n moduleName,\n node,\n}: {\n compatibleWithTypeOnlyImport?: boolean;\n fixer: TSESLint.RuleFixer;\n importName: string;\n moduleName: string;\n node: TSESTree.Node;\n}): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const fullImport = `import { ${importName} } from '${moduleName}';\\n`;\n const importDeclarations = getImportDeclarations(node, moduleName);\n\n if (!importDeclarations?.length) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const importDeclarationSpecifier = getImportDeclarationSpecifier(\n importDeclarations,\n importName\n );\n\n if (importDeclarationSpecifier) {\n return [];\n }\n\n const importClause = getCorrespondentImportClause(\n importDeclarations,\n compatibleWithTypeOnlyImport\n );\n\n if (!importClause) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const replacementText = isImportDefaultSpecifier(importClause)\n ? `, { ${importName} }`\n : `, ${importName}`;\n return fixer.insertTextAfter(importClause, replacementText);\n}\n\nexport function getImportRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importedName: string,\n fixer: TSESLint.RuleFixer\n): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const { importDeclaration, importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importedName) ?? {};\n\n if (!importDeclaration || !importSpecifier) {\n return [];\n }\n\n const isFirstImportSpecifier =\n importDeclaration.specifiers[0] === importSpecifier;\n const isLastImportSpecifier =\n getLast(importDeclaration.specifiers) === importSpecifier;\n const isSingleImportSpecifier =\n isFirstImportSpecifier && isLastImportSpecifier;\n\n if (isSingleImportSpecifier) {\n return fixer.remove(importDeclaration);\n }\n\n const tokenAfterImportSpecifier = sourceCode.getTokenAfter(importSpecifier);\n\n if (isFirstImportSpecifier && tokenAfterImportSpecifier) {\n return fixer.removeRange([\n importSpecifier.range[0],\n tokenAfterImportSpecifier.range[1],\n ]);\n }\n\n const tokenBeforeImportSpecifier = sourceCode.getTokenBefore(importSpecifier);\n\n if (!tokenBeforeImportSpecifier) {\n return [];\n }\n\n return fixer.removeRange([\n tokenBeforeImportSpecifier.range[0],\n importSpecifier.range[1],\n ]);\n}\n\nexport function getNodeToCommaRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer,\n node: TSESTree.Node\n) {\n const nextToken = sourceCode.getTokenAfter(node);\n const isNextTokenComma = nextToken && ASTUtils.isCommaToken(nextToken);\n return [\n fixer.remove(node),\n ...(isNextTokenComma ? [fixer.remove(nextToken)] : []),\n ] as const;\n}\n\nexport function getInterfaceName(\n interfaceMember: TSESTree.Identifier | TSESTree.MemberExpression\n): string | undefined {\n if (isIdentifier(interfaceMember)) {\n return interfaceMember.name;\n }\n\n return isIdentifier(interfaceMember.property)\n ? interfaceMember.property.name\n : undefined;\n}\n\nexport function getInterfaces({\n implements: classImplements,\n}: TSESTree.ClassDeclaration): readonly (\n | TSESTree.Identifier\n | TSESTree.MemberExpression\n)[] {\n return (classImplements ?? [])\n .map(({ expression }) => expression)\n .filter(isIdentifierOrMemberExpression);\n}\n\nexport function getInterface(\n node: TSESTree.ClassDeclaration,\n interfaceName: string\n): TSESTree.Identifier | TSESTree.MemberExpression | undefined {\n return getInterfaces(node).find(\n (interfaceMember) => getInterfaceName(interfaceMember) === interfaceName\n );\n}\n\nexport function getImplementsSchemaFixer(\n { id, implements: classImplements }: TSESTree.ClassDeclaration,\n interfaceName: string\n) {\n const [implementsNodeReplace, implementsTextReplace] =\n classImplements && classImplements.length\n ? [getLast(classImplements), `, ${interfaceName}`]\n : [id as TSESTree.Identifier, ` implements ${interfaceName}`];\n\n return { implementsNodeReplace, implementsTextReplace } as const;\n}\n\nexport function getLast<T extends readonly unknown[]>(items: T): T[number] {\n return items.slice(-1)[0];\n}\n\nexport function getDecoratorName({\n expression,\n}: TSESTree.Decorator): string | undefined {\n if (isIdentifier(expression)) {\n return expression.name;\n }\n\n return isCallExpression(expression) && isIdentifier(expression.callee)\n ? expression.callee.name\n : undefined;\n}\n\nexport function getRawText(node: TSESTree.Node): string | null {\n if (isIdentifier(node)) {\n return node.name;\n }\n\n if (\n isPropertyDefinition(node) ||\n isMethodDefinition(node) ||\n isProperty(node)\n ) {\n return getRawText(node.key);\n }\n\n if (isLiteral(node)) {\n return node.raw;\n }\n\n if (isTemplateElement(node)) {\n return `\\`${node.value.raw}\\``;\n }\n\n if (isTemplateLiteral(node)) {\n return `\\`${node.quasis[0].value.raw}\\``;\n }\n\n return null;\n}\n\nexport function capitalize<T extends string>(text: T): Capitalize<T> {\n return `${text[0].toUpperCase()}${text.slice(1)}` as Capitalize<T>;\n}\n\nfunction getInjectedParametersWithSourceCode(\n context: TSESLint.RuleContext<string, readonly unknown[]>,\n moduleName: string,\n importName: string\n): InjectedParameterWithSourceCode {\n const sourceCode = context.getSourceCode();\n const importDeclarations =\n getImportDeclarations(sourceCode.ast, moduleName) ?? [];\n const { importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importName) ?? {};\n\n const injectImportDeclarations =\n getImportDeclarations(sourceCode.ast, '@angular/core') ?? [];\n\n const { importSpecifier: injectImportSpecifier } =\n getImportDeclarationSpecifier(injectImportDeclarations, 'inject') ?? {};\n\n if (!importSpecifier) {\n return { sourceCode };\n }\n\n const variables = context.getDeclaredVariables(importSpecifier);\n const typedVariable = variables.find(({ name }) => name === importName);\n const identifiers = typedVariable?.references?.reduce<\n readonly InjectedParameter[]\n >((identifiers, { identifier: { parent } }) => {\n if (!parent) {\n return identifiers;\n }\n\n if (\n isTSTypeReference(parent) &&\n parent.parent &&\n isTSTypeAnnotation(parent.parent) &&\n parent.parent.parent &&\n isIdentifier(parent.parent.parent)\n ) {\n return identifiers.concat(parent.parent.parent as InjectedParameter);\n }\n\n const parentToCheck = isTSInstantiationExpression(parent)\n ? parent.parent\n : parent;\n\n if (\n parentToCheck &&\n isCallExpression(parentToCheck) &&\n isIdentifier(parentToCheck.callee) &&\n parentToCheck.callee.name == 'inject' &&\n parentToCheck.parent &&\n isPropertyDefinition(parentToCheck.parent) &&\n isIdentifier(parentToCheck.parent.key) &&\n injectImportSpecifier\n ) {\n return identifiers.concat(parentToCheck.parent.key as InjectedParameter);\n }\n\n return identifiers;\n }, []);\n return { identifiers, sourceCode };\n}\n\nexport function getNgRxEffectActions(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.effects,\n 'Actions'\n );\n}\n\nexport function getNgRxComponentStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS['component-store'],\n 'ComponentStore'\n );\n}\n\nexport function getNgRxStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.store,\n 'Store'\n );\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nexport function escapeText(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function asPattern(identifiers: readonly InjectedParameter[]): RegExp {\n const escapedNames = identifiers.map(({ name }) => escapeText(name));\n return new RegExp(`^(${escapedNames.join('|')})$`);\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/utils.ts"],"names":[],"mappings":";;;AACA,oDAAoD;AACpD,qCAkBkB;AAClB,iDAAmD;AAoBnD,SAAgB,uBAAuB,CACrC,EAAE,MAAM,EAAiB,EACzB,SAAiD;IAEjD,O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C,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACrC,CAAC;AAED,SAAgB,oBAAoB,CAClC,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,OAAO,EACzB,SAAS,CACV,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,sBAAsB,CACpC,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,iBAAiB,CAAC,EACpC,gBAAgB,CACjB,CAAC;AACJ,CAAC;AARD,wDAQC;AAED,SAAgB,aAAa,CAC3B,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,KAAK,EACvB,OAAO,CACR,CAAC;AACJ,CAAC;AARD,sCAQC;AAED,6FAA6F;AAC7F,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAFD,gCAEC;AAED,SAAgB,SAAS,CAAC,WAAyC;IACjE,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IACrE,OAAO,IAAI,MAAM,CAAC,KAAK,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC;AAHD,8BAGC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/utils';\nimport { ASTUtils } from '@typescript-eslint/utils';\nimport {\n isCallExpression,\n isIdentifier,\n isIdentifierOrMemberExpression,\n isImportDeclaration,\n isImportDefaultSpecifier,\n isImportNamespaceSpecifier,\n isImportSpecifier,\n isLiteral,\n isMethodDefinition,\n isProgram,\n isProperty,\n isPropertyDefinition,\n isTSTypeAnnotation,\n isTSTypeReference,\n isTemplateElement,\n isTemplateLiteral,\n isTSInstantiationExpression,\n} from './guards';\nimport { NGRX_MODULE_PATHS } from './ngrx-modules';\n\ntype ConstructorFunctionExpression = TSESTree.FunctionExpression & {\n parent: TSESTree.MethodDefinition & { kind: 'constructor' };\n};\ntype InjectedParameter =\n | TSESTree.Identifier & {\n typeAnnotation: TSESTree.TSTypeAnnotation;\n parent:\n | ConstructorFunctionExpression\n | (TSESTree.TSParameterProperty & {\n parent: ConstructorFunctionExpression;\n })\n | TSESTree.PropertyDefinition;\n };\ntype InjectedParameterWithSourceCode = Readonly<{\n identifiers?: readonly InjectedParameter[];\n sourceCode: Readonly<TSESLint.SourceCode>;\n}>;\n\nexport function getNearestUpperNodeFrom<T extends TSESTree.Node>(\n { parent }: TSESTree.Node,\n predicate: (parent: TSESTree.Node) => parent is T\n): T | undefined {\n while (parent && !isProgram(parent)) {\n if (predicate(parent)) {\n return parent;\n }\n\n parent = parent.parent;\n }\n\n return undefined;\n}\n\nexport function getImportDeclarationSpecifier(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importName: string\n) {\n for (const importDeclaration of importDeclarations) {\n const importSpecifier = importDeclaration.specifiers.find(\n (importClause): importClause is TSESTree.ImportSpecifier => {\n return (\n isImportSpecifier(importClause) &&\n importClause.imported.name === importName\n );\n }\n );\n\n if (importSpecifier) {\n return { importDeclaration, importSpecifier } as const;\n }\n }\n\n return undefined;\n}\n\nexport function getImportDeclarations(\n node: TSESTree.Node,\n moduleName: string\n): readonly TSESTree.ImportDeclaration[] | undefined {\n let parentNode: TSESTree.Node | undefined = node;\n\n while (parentNode && !isProgram(parentNode)) {\n parentNode = parentNode.parent;\n }\n\n return parentNode?.body.filter((node): node is TSESTree.ImportDeclaration => {\n return isImportDeclaration(node) && node.source.value === moduleName;\n });\n}\n\nfunction getCorrespondentImportClause(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n compatibleWithTypeOnlyImport = false\n) {\n let importClause: TSESTree.ImportClause | undefined;\n\n for (const { importKind, specifiers } of importDeclarations) {\n const lastImportSpecifier = getLast(specifiers);\n\n if (\n (!compatibleWithTypeOnlyImport && importKind === 'type') ||\n isImportNamespaceSpecifier(lastImportSpecifier)\n ) {\n continue;\n }\n\n importClause = lastImportSpecifier;\n }\n\n return importClause;\n}\n\nexport function getImportAddFix({\n compatibleWithTypeOnlyImport = false,\n fixer,\n importName,\n moduleName,\n node,\n}: {\n compatibleWithTypeOnlyImport?: boolean;\n fixer: TSESLint.RuleFixer;\n importName: string;\n moduleName: string;\n node: TSESTree.Node;\n}): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const fullImport = `import { ${importName} } from '${moduleName}';`;\n const importDeclarations = getImportDeclarations(node, moduleName);\n\n if (!importDeclarations?.length) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const importDeclarationSpecifier = getImportDeclarationSpecifier(\n importDeclarations,\n importName\n );\n\n if (importDeclarationSpecifier) {\n return [];\n }\n\n const importClause = getCorrespondentImportClause(\n importDeclarations,\n compatibleWithTypeOnlyImport\n );\n\n if (!importClause) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const replacementText = isImportDefaultSpecifier(importClause)\n ? `, { ${importName} }`\n : `, ${importName}`;\n return fixer.insertTextAfter(importClause, replacementText);\n}\n\nexport function getImportRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importedName: string,\n fixer: TSESLint.RuleFixer\n): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const { importDeclaration, importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importedName) ?? {};\n\n if (!importDeclaration || !importSpecifier) {\n return [];\n }\n\n const isFirstImportSpecifier =\n importDeclaration.specifiers[0] === importSpecifier;\n const isLastImportSpecifier =\n getLast(importDeclaration.specifiers) === importSpecifier;\n const isSingleImportSpecifier =\n isFirstImportSpecifier && isLastImportSpecifier;\n\n if (isSingleImportSpecifier) {\n return fixer.remove(importDeclaration);\n }\n\n const tokenAfterImportSpecifier = sourceCode.getTokenAfter(importSpecifier);\n\n if (isFirstImportSpecifier && tokenAfterImportSpecifier) {\n return fixer.removeRange([\n importSpecifier.range[0],\n tokenAfterImportSpecifier.range[1],\n ]);\n }\n\n const tokenBeforeImportSpecifier = sourceCode.getTokenBefore(importSpecifier);\n\n if (!tokenBeforeImportSpecifier) {\n return [];\n }\n\n return fixer.removeRange([\n tokenBeforeImportSpecifier.range[0],\n importSpecifier.range[1],\n ]);\n}\n\nexport function getNodeToCommaRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer,\n node: TSESTree.Node\n) {\n const nextToken = sourceCode.getTokenAfter(node);\n const isNextTokenComma = nextToken && ASTUtils.isCommaToken(nextToken);\n return [\n fixer.remove(node),\n ...(isNextTokenComma ? [fixer.remove(nextToken)] : []),\n ] as const;\n}\n\nexport function getInterfaceName(\n interfaceMember: TSESTree.Identifier | TSESTree.MemberExpression\n): string | undefined {\n if (isIdentifier(interfaceMember)) {\n return interfaceMember.name;\n }\n\n return isIdentifier(interfaceMember.property)\n ? interfaceMember.property.name\n : undefined;\n}\n\nexport function getInterfaces({\n implements: classImplements,\n}: TSESTree.ClassDeclaration): readonly (\n | TSESTree.Identifier\n | TSESTree.MemberExpression\n)[] {\n return (classImplements ?? [])\n .map(({ expression }) => expression)\n .filter(isIdentifierOrMemberExpression);\n}\n\nexport function getInterface(\n node: TSESTree.ClassDeclaration,\n interfaceName: string\n): TSESTree.Identifier | TSESTree.MemberExpression | undefined {\n return getInterfaces(node).find(\n (interfaceMember) => getInterfaceName(interfaceMember) === interfaceName\n );\n}\n\nexport function getImplementsSchemaFixer(\n { id, implements: classImplements }: TSESTree.ClassDeclaration,\n interfaceName: string\n) {\n const [implementsNodeReplace, implementsTextReplace] =\n classImplements && classImplements.length\n ? [getLast(classImplements), `, ${interfaceName}`]\n : [id as TSESTree.Identifier, ` implements ${interfaceName}`];\n\n return { implementsNodeReplace, implementsTextReplace } as const;\n}\n\nexport function getLast<T extends readonly unknown[]>(items: T): T[number] {\n return items.slice(-1)[0];\n}\n\nexport function getDecoratorName({\n expression,\n}: TSESTree.Decorator): string | undefined {\n if (isIdentifier(expression)) {\n return expression.name;\n }\n\n return isCallExpression(expression) && isIdentifier(expression.callee)\n ? expression.callee.name\n : undefined;\n}\n\nexport function getRawText(node: TSESTree.Node): string | null {\n if (isIdentifier(node)) {\n return node.name;\n }\n\n if (\n isPropertyDefinition(node) ||\n isMethodDefinition(node) ||\n isProperty(node)\n ) {\n return getRawText(node.key);\n }\n\n if (isLiteral(node)) {\n return node.raw;\n }\n\n if (isTemplateElement(node)) {\n return `\\`${node.value.raw}\\``;\n }\n\n if (isTemplateLiteral(node)) {\n return `\\`${node.quasis[0].value.raw}\\``;\n }\n\n return null;\n}\n\nexport function capitalize<T extends string>(text: T): Capitalize<T> {\n return `${text[0].toUpperCase()}${text.slice(1)}` as Capitalize<T>;\n}\n\nfunction getInjectedParametersWithSourceCode(\n context: TSESLint.RuleContext<string, readonly unknown[]>,\n moduleName: string,\n importName: string\n): InjectedParameterWithSourceCode {\n const sourceCode = context.getSourceCode();\n const importDeclarations =\n getImportDeclarations(sourceCode.ast, moduleName) ?? [];\n const { importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importName) ?? {};\n\n const injectImportDeclarations =\n getImportDeclarations(sourceCode.ast, '@angular/core') ?? [];\n\n const { importSpecifier: injectImportSpecifier } =\n getImportDeclarationSpecifier(injectImportDeclarations, 'inject') ?? {};\n\n if (!importSpecifier) {\n return { sourceCode };\n }\n\n const variables = sourceCode.getDeclaredVariables(importSpecifier);\n const typedVariable = variables.find(({ name }) => name === importName);\n const identifiers = typedVariable?.references?.reduce<\n readonly InjectedParameter[]\n >((identifiers, { identifier: { parent } }) => {\n if (!parent) {\n return identifiers;\n }\n\n if (\n isTSTypeReference(parent) &&\n parent.parent &&\n isTSTypeAnnotation(parent.parent) &&\n parent.parent.parent &&\n isIdentifier(parent.parent.parent)\n ) {\n return identifiers.concat(parent.parent.parent as InjectedParameter);\n }\n\n const parentToCheck = isTSInstantiationExpression(parent)\n ? parent.parent\n : parent;\n\n if (\n parentToCheck &&\n isCallExpression(parentToCheck) &&\n isIdentifier(parentToCheck.callee) &&\n parentToCheck.callee.name == 'inject' &&\n parentToCheck.parent &&\n isPropertyDefinition(parentToCheck.parent) &&\n isIdentifier(parentToCheck.parent.key) &&\n injectImportSpecifier\n ) {\n return identifiers.concat(parentToCheck.parent.key as InjectedParameter);\n }\n\n return identifiers;\n }, []);\n return { identifiers, sourceCode };\n}\n\nexport function getNgRxEffectActions(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.effects,\n 'Actions'\n );\n}\n\nexport function getNgRxComponentStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS['component-store'],\n 'ComponentStore'\n );\n}\n\nexport function getNgRxStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.store,\n 'Store'\n );\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nexport function escapeText(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function asPattern(identifiers: readonly InjectedParameter[]): RegExp {\n const escapedNames = identifiers.map(({ name }) => escapeText(name));\n return new RegExp(`^(${escapedNames.join('|')})$`);\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare function ngrxVersionSatisfies(pkg: string, version: string): boolean;
@@ -24,25 +24,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ngrxVersionSatisfies = exports.clearCache = exports.setNgrxVersion = void 0;
27
- var semver = __importStar(require("semver"));
28
- var noopVersion = '0.0.0';
29
- var versionsCache = new Map();
30
- var satisfiesCache = new Map();
27
+ const semver = __importStar(require("semver"));
28
+ const noopVersion = '0.0.0';
29
+ const versionsCache = new Map();
30
+ const satisfiesCache = new Map();
31
31
  function getNgrxVersion(pkg) {
32
32
  if (!versionsCache.has(pkg)) {
33
- var version = readPlatformVersion(pkg);
34
- versionsCache.set(pkg, version !== null && version !== void 0 ? version : noopVersion);
33
+ const version = readPlatformVersion(pkg);
34
+ versionsCache.set(pkg, version ?? noopVersion);
35
35
  }
36
36
  return versionsCache.get(pkg);
37
37
  }
38
38
  function readPlatformVersion(pkg) {
39
- var _a;
40
39
  try {
41
- // eslint-disable-next-line @typescript-eslint/no-var-requires
42
- var ngrxVersion = require("".concat(pkg, "/package.json"));
43
- return (_a = ngrxVersion.version) === null || _a === void 0 ? void 0 : _a.replace(/[^\d.]/g, '');
40
+ // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-require-imports
41
+ const ngrxVersion = require(`${pkg}/package.json`);
42
+ return ngrxVersion.version?.replace(/[^\d.]/g, '');
44
43
  }
45
- catch (_b) {
44
+ catch {
46
45
  return null;
47
46
  }
48
47
  }
@@ -1 +1 @@
1
- {"version":3,"file":"versions.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/versions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAiC;AAEjC,IAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,IAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;AAChD,IAAM,cAAc,GAAG,IAAI,GAAG,EAAmB,CAAC;AAElD,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,IAAM,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACzC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,aAAa,CAAC,GAAG,CAAC,GAAG,CAAW,CAAC;AAC1C,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAW;;IACtC,IAAI,CAAC;QACH,8DAA8D;QAC9D,IAAM,WAAW,GAAG,OAAO,CAAC,UAAG,GAAG,kBAAe,CAEhD,CAAC;QACF,OAAO,MAAA,WAAW,CAAC,OAAO,0CAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,iCAAiC;AACjC,SAAgB,cAAc,CAAC,GAAW,EAAE,OAAe;IACzD,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAFD,wCAEC;AAED,iCAAiC;AACjC,SAAgB,UAAU;IACxB,aAAa,CAAC,KAAK,EAAE,CAAC;IACtB,cAAc,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC;AAHD,gCAGC;AAED,SAAS,gBAAgB,CAAC,GAAW,EAAE,OAAe;IACpD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAY,CAAC;AAC5C,CAAC;AAED,SAAgB,oBAAoB,CAAC,GAAW,EAAE,OAAe;IAC/D,OAAO,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAFD,oDAEC","sourcesContent":["import * as semver from 'semver';\n\nconst noopVersion = '0.0.0';\nconst versionsCache = new Map<string, string>();\nconst satisfiesCache = new Map<string, boolean>();\n\nfunction getNgrxVersion(pkg: string): string {\n if (!versionsCache.has(pkg)) {\n const version = readPlatformVersion(pkg);\n versionsCache.set(pkg, version ?? noopVersion);\n }\n\n return versionsCache.get(pkg) as string;\n}\n\nfunction readPlatformVersion(pkg: string) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const ngrxVersion = require(`${pkg}/package.json`) as {\n version?: string;\n };\n return ngrxVersion.version?.replace(/[^\\d.]/g, '');\n } catch {\n return null;\n }\n}\n\n// @internal for testing purposes\nexport function setNgrxVersion(pkg: string, version: string): void {\n versionsCache.set(pkg, version);\n}\n\n// @internal for testing purposes\nexport function clearCache() {\n versionsCache.clear();\n satisfiesCache.clear();\n}\n\nfunction versionSatisfies(pkg: string, version: string) {\n if (!satisfiesCache.has(pkg)) {\n satisfiesCache.set(pkg, semver.satisfies(getNgrxVersion(pkg), version));\n }\n\n return satisfiesCache.get(pkg) as boolean;\n}\n\nexport function ngrxVersionSatisfies(pkg: string, version: string): boolean {\n return versionSatisfies(pkg, version);\n}\n"]}
1
+ {"version":3,"file":"versions.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/versions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAEjC,MAAM,WAAW,GAAG,OAAO,CAAC;AAC5B,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;AAChD,MAAM,cAAc,GAAG,IAAI,GAAG,EAAmB,CAAC;AAElD,SAAS,cAAc,CAAC,GAAW;IACjC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,MAAM,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACzC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,IAAI,WAAW,CAAC,CAAC;IACjD,CAAC;IAED,OAAO,aAAa,CAAC,GAAG,CAAC,GAAG,CAAW,CAAC;AAC1C,CAAC;AAED,SAAS,mBAAmB,CAAC,GAAW;IACtC,IAAI,CAAC;QACH,oGAAoG;QACpG,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,GAAG,eAAe,CAEhD,CAAC;QACF,OAAO,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,iCAAiC;AACjC,SAAgB,cAAc,CAAC,GAAW,EAAE,OAAe;IACzD,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAFD,wCAEC;AAED,iCAAiC;AACjC,SAAgB,UAAU;IACxB,aAAa,CAAC,KAAK,EAAE,CAAC;IACtB,cAAc,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC;AAHD,gCAGC;AAED,SAAS,gBAAgB,CAAC,GAAW,EAAE,OAAe;IACpD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAY,CAAC;AAC5C,CAAC;AAED,SAAgB,oBAAoB,CAAC,GAAW,EAAE,OAAe;IAC/D,OAAO,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC;AAFD,oDAEC","sourcesContent":["import * as semver from 'semver';\n\nconst noopVersion = '0.0.0';\nconst versionsCache = new Map<string, string>();\nconst satisfiesCache = new Map<string, boolean>();\n\nfunction getNgrxVersion(pkg: string): string {\n if (!versionsCache.has(pkg)) {\n const version = readPlatformVersion(pkg);\n versionsCache.set(pkg, version ?? noopVersion);\n }\n\n return versionsCache.get(pkg) as string;\n}\n\nfunction readPlatformVersion(pkg: string) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-require-imports\n const ngrxVersion = require(`${pkg}/package.json`) as {\n version?: string;\n };\n return ngrxVersion.version?.replace(/[^\\d.]/g, '');\n } catch {\n return null;\n }\n}\n\n// @internal for testing purposes\nexport function setNgrxVersion(pkg: string, version: string): void {\n versionsCache.set(pkg, version);\n}\n\n// @internal for testing purposes\nexport function clearCache() {\n versionsCache.clear();\n satisfiesCache.clear();\n}\n\nfunction versionSatisfies(pkg: string, version: string) {\n if (!satisfiesCache.has(pkg)) {\n satisfiesCache.set(pkg, semver.satisfies(getNgrxVersion(pkg), version));\n }\n\n return satisfiesCache.get(pkg) as boolean;\n}\n\nexport function ngrxVersionSatisfies(pkg: string, version: string): boolean {\n return versionSatisfies(pkg, version);\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './helper-functions';
2
+ export * from './selectors';
@@ -0,0 +1,29 @@
1
+ export declare const effectCreator = "PropertyDefinition[value.callee.name='createEffect']";
2
+ export declare const createEffectExpression = "CallExpression[callee.name='createEffect']";
3
+ export declare const effectDecorator = "Decorator[expression.callee.name='Effect']";
4
+ export declare const propertyDefinitionWithEffectDecorator: "ClassDeclaration > ClassBody > PropertyDefinition > Decorator[expression.callee.name='Effect']";
5
+ export declare const actionCreator = "CallExpression[callee.name='createAction']";
6
+ export declare const actionCreatorWithLiteral: "CallExpression[callee.name='createAction'][arguments.0.type='Literal'][arguments.0.raw=/^'/]";
7
+ export declare const actionCreatorProps: "CallExpression[callee.name='createAction'] > CallExpression[callee.name='props']";
8
+ export declare const actionCreatorPropsComputed: "CallExpression[callee.name='createAction'] > CallExpression[callee.name='props'] > TSTypeParameterInstantiation > :matches(TSTypeReference[typeName.name!='Readonly'], [type=/^TS(.*)(Keyword|Type)$/])";
9
+ export declare const constructorDefinition = "MethodDefinition[kind='constructor']";
10
+ export declare function metadataProperty(key: RegExp): string;
11
+ export declare function metadataProperty<TKey extends string>(key: TKey): `Property:matches([key.name=${TKey}][computed=false], [key.value=${TKey}], [key.quasis.0.value.raw=${TKey}])`;
12
+ export declare const ngModuleDecorator = "ClassDeclaration > Decorator > CallExpression[callee.name='NgModule']";
13
+ export declare const ngModuleImports: "ClassDeclaration > Decorator > CallExpression[callee.name='NgModule'] ObjectExpression Property:matches([key.name=imports][computed=false], [key.value=imports], [key.quasis.0.value.raw=imports]) > ArrayExpression";
14
+ export declare const ngModuleProviders: "ClassDeclaration > Decorator > CallExpression[callee.name='NgModule'] ObjectExpression Property:matches([key.name=providers][computed=false], [key.value=providers], [key.quasis.0.value.raw=providers]) > ArrayExpression";
15
+ export declare const effectsInNgModuleImports: "ClassDeclaration > Decorator > CallExpression[callee.name='NgModule'] ObjectExpression Property:matches([key.name=imports][computed=false], [key.value=imports], [key.quasis.0.value.raw=imports]) > ArrayExpression CallExpression[callee.object.name='EffectsModule'][callee.property.name=/^for(Root|Feature)$/] ArrayExpression > Identifier";
16
+ export declare const effectsInNgModuleProviders: "ClassDeclaration > Decorator > CallExpression[callee.name='NgModule'] ObjectExpression Property:matches([key.name=providers][computed=false], [key.value=providers], [key.quasis.0.value.raw=providers]) > ArrayExpression Identifier";
17
+ export declare const namedExpression: (name: RegExp | string) => `:matches(MethodDefinition[kind='constructor'] CallExpression[callee.object.name=${string}], CallExpression[callee.object.object.type='ThisExpression'][callee.object.property.name=${string}])`;
18
+ export declare const namedCallableExpression: (name: RegExp | string) => `:matches(:matches(MethodDefinition[kind='constructor'] CallExpression[callee.object.name=${string}], CallExpression[callee.object.object.type='ThisExpression'][callee.object.property.name=${string}]), MethodDefinition[kind='constructor'] CallExpression[callee.object.callee.object.name=${string}], CallExpression[callee.object.callee.object.object.type='ThisExpression'][callee.object.callee.object.property.name=${string}])`;
19
+ export declare const pipeExpression: (name: RegExp | string) => `:matches(MethodDefinition[kind='constructor'] CallExpression[callee.object.name=${string}], CallExpression[callee.object.object.type='ThisExpression'][callee.object.property.name=${string}])[callee.property.name='pipe']`;
20
+ export declare const pipeableSelect: (name: RegExp | string) => `:matches(MethodDefinition[kind='constructor'] CallExpression[callee.object.name=${string}], CallExpression[callee.object.object.type='ThisExpression'][callee.object.property.name=${string}])[callee.property.name='pipe'] CallExpression[callee.name='select']`;
21
+ export declare const selectExpression: (name: RegExp | string) => `:matches(MethodDefinition[kind='constructor'] CallExpression[callee.object.name=${string}], CallExpression[callee.object.object.type='ThisExpression'][callee.object.property.name=${string}])[callee.property.name='select']`;
22
+ export declare const dispatchExpression: (name: RegExp | string) => `:matches(MethodDefinition[kind='constructor'] CallExpression[callee.object.name=${string}], CallExpression[callee.object.object.type='ThisExpression'][callee.object.property.name=${string}])[callee.property.name='dispatch']`;
23
+ export declare const dispatchInEffects: (name: RegExp | string) => `CallExpression[callee.name='createEffect'] :matches(MethodDefinition[kind='constructor'] CallExpression[callee.object.name=${string}], CallExpression[callee.object.object.type='ThisExpression'][callee.object.property.name=${string}])[callee.property.name='dispatch'] > MemberExpression:has(Identifier[name=${string}])`;
24
+ export declare const createReducer = "CallExpression[callee.name='createReducer']";
25
+ export declare const onFunctionWithoutType: "CallExpression[callee.name='createReducer'] CallExpression[callee.name='on'] > ArrowFunctionExpression:not([returnType.typeAnnotation], :has(CallExpression))";
26
+ export declare const storeActionReducerMap: "ClassDeclaration > Decorator > CallExpression[callee.name='NgModule'] ObjectExpression Property:matches([key.name=imports][computed=false], [key.value=imports], [key.quasis.0.value.raw=imports]) > ArrayExpression CallExpression[callee.object.name='StoreModule'][callee.property.name=/^for(Root|Feature)$/] > ObjectExpression:first-child";
27
+ export declare const actionReducerMap = "VariableDeclarator[id.typeAnnotation.typeAnnotation.typeName.name='ActionReducerMap'] > ObjectExpression";
28
+ export declare const mapLikeOperatorsExplicitReturn: "CallExpression[callee.name=/^(concat|exhaust|flat|merge|switch)Map$/] ReturnStatement";
29
+ export declare const mapLikeOperatorsImplicitReturn: ":matches(CallExpression[callee.name=/^(concat|merge|switch)MapTo$/], CallExpression[callee.name=/^(concat|exhaust|flat|merge|switch)Map$/] > ArrowFunctionExpression)";