@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.
- package/jest.config.d.ts +15 -0
- package/package.json +3 -5
- package/schematics/ng-add/index.d.ts +3 -0
- package/schematics/ng-add/index.js +32 -20
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/schema.d.ts +3 -0
- package/schematics/ng-add/schema.js.map +1 -1
- package/schematics/ng-add/schema.json +16 -51
- package/scripts/generate-config.d.ts +1 -0
- package/scripts/generate-config.js +73 -73
- package/scripts/generate-config.js.map +1 -1
- package/scripts/generate-docs.d.ts +1 -0
- package/scripts/generate-docs.js +33 -65
- package/scripts/generate-docs.js.map +1 -1
- package/scripts/generate-overview.d.ts +1 -0
- package/scripts/generate-overview.js +43 -75
- package/scripts/generate-overview.js.map +1 -1
- package/spec/utils/from-fixture.d.ts +8 -0
- package/spec/utils/from-fixture.js +62 -0
- package/spec/utils/from-fixture.js.map +1 -0
- package/spec/utils/index.d.ts +2 -0
- package/spec/utils/index.js +16 -19
- package/spec/utils/index.js.map +1 -1
- package/spec/utils/rule-tester.d.ts +5 -0
- package/spec/utils/rule-tester.js +23 -0
- package/spec/utils/rule-tester.js.map +1 -0
- package/src/configs/all.d.ts +7 -0
- package/src/configs/all.js +56 -32
- package/src/configs/all.js.map +1 -1
- package/src/configs/all.json +42 -0
- package/src/configs/component-store.d.ts +7 -0
- package/src/configs/component-store.js +23 -8
- package/src/configs/component-store.js.map +1 -1
- package/src/configs/component-store.json +9 -0
- package/src/configs/effects.d.ts +7 -0
- package/src/configs/effects.js +32 -11
- package/src/configs/effects.js.map +1 -1
- package/src/configs/effects.json +13 -0
- package/src/configs/operators.d.ts +7 -0
- package/src/configs/operators.js +28 -0
- package/src/configs/operators.js.map +1 -0
- package/src/configs/operators.json +7 -0
- package/src/configs/signals.d.ts +7 -0
- package/src/configs/signals.js +34 -0
- package/src/configs/signals.js.map +1 -0
- package/src/configs/signals.json +8 -0
- package/src/configs/store.d.ts +7 -0
- package/src/configs/store.js +38 -23
- package/src/configs/store.js.map +1 -1
- package/src/configs/store.json +24 -0
- package/src/index.d.ts +141 -0
- package/src/index.js +18 -3
- package/src/index.js.map +1 -1
- package/src/rule-creator.d.ts +24 -0
- package/src/rule-creator.js +12 -58
- package/src/rule-creator.js.map +1 -1
- package/src/rules/component-store/avoid-combining-component-store-selectors.d.ts +3 -0
- package/src/rules/component-store/avoid-combining-component-store-selectors.js +22 -47
- package/src/rules/component-store/avoid-combining-component-store-selectors.js.map +1 -1
- package/src/rules/component-store/avoid-mapping-component-store-selectors.d.ts +3 -0
- package/src/rules/component-store/avoid-mapping-component-store-selectors.js +17 -20
- package/src/rules/component-store/avoid-mapping-component-store-selectors.js.map +1 -1
- package/src/rules/component-store/updater-explicit-return-type.d.ts +3 -0
- package/src/rules/component-store/updater-explicit-return-type.js +17 -20
- package/src/rules/component-store/updater-explicit-return-type.js.map +1 -1
- package/src/rules/effects/avoid-cyclic-effects.d.ts +4 -0
- package/src/rules/effects/avoid-cyclic-effects.js +47 -109
- package/src/rules/effects/avoid-cyclic-effects.js.map +1 -1
- package/src/rules/effects/no-dispatch-in-effects.d.ts +5 -0
- package/src/rules/effects/no-dispatch-in-effects.js +17 -21
- package/src/rules/effects/no-dispatch-in-effects.js.map +1 -1
- package/src/rules/effects/no-effects-in-providers.d.ts +3 -0
- package/src/rules/effects/no-effects-in-providers.js +18 -49
- package/src/rules/effects/no-effects-in-providers.js.map +1 -1
- package/src/rules/effects/no-multiple-actions-in-effects.d.ts +5 -0
- package/src/rules/effects/no-multiple-actions-in-effects.js +31 -24
- package/src/rules/effects/no-multiple-actions-in-effects.js.map +1 -1
- package/src/rules/effects/prefer-action-creator-in-of-type.d.ts +3 -0
- package/src/rules/effects/prefer-action-creator-in-of-type.js +10 -13
- package/src/rules/effects/prefer-action-creator-in-of-type.js.map +1 -1
- package/src/rules/effects/prefer-effect-callback-in-block-statement.d.ts +4 -0
- package/src/rules/effects/prefer-effect-callback-in-block-statement.js +24 -43
- package/src/rules/effects/prefer-effect-callback-in-block-statement.js.map +1 -1
- package/src/rules/effects/use-effects-lifecycle-interface.d.ts +3 -0
- package/src/rules/effects/use-effects-lifecycle-interface.js +21 -24
- package/src/rules/effects/use-effects-lifecycle-interface.js.map +1 -1
- package/src/rules/index.d.ts +33 -0
- package/src/rules/index.js +69 -53
- package/src/rules/index.js.map +1 -1
- package/src/rules/operators/prefer-concat-latest-from.d.ts +7 -0
- package/src/rules/operators/prefer-concat-latest-from.js +123 -0
- package/src/rules/operators/prefer-concat-latest-from.js.map +1 -0
- package/src/rules/signals/signal-state-no-arrays-at-root-level.d.ts +3 -0
- package/src/rules/signals/signal-state-no-arrays-at-root-level.js +59 -0
- package/src/rules/signals/signal-state-no-arrays-at-root-level.js.map +1 -0
- package/src/rules/signals/with-state-no-arrays-at-root-level.d.ts +4 -0
- package/src/rules/signals/with-state-no-arrays-at-root-level.js +72 -0
- package/src/rules/signals/with-state-no-arrays-at-root-level.js.map +1 -0
- package/src/rules/store/avoid-combining-selectors.d.ts +3 -0
- package/src/rules/store/avoid-combining-selectors.js +20 -45
- package/src/rules/store/avoid-combining-selectors.js.map +1 -1
- package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.d.ts +3 -0
- package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js +20 -47
- package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js.map +1 -1
- package/src/rules/store/avoid-duplicate-actions-in-reducer.d.ts +5 -0
- package/src/rules/store/avoid-duplicate-actions-in-reducer.js +33 -101
- package/src/rules/store/avoid-duplicate-actions-in-reducer.js.map +1 -1
- package/src/rules/store/avoid-mapping-selectors.d.ts +3 -0
- package/src/rules/store/avoid-mapping-selectors.js +24 -30
- package/src/rules/store/avoid-mapping-selectors.js.map +1 -1
- package/src/rules/store/good-action-hygiene.d.ts +3 -0
- package/src/rules/store/good-action-hygiene.js +14 -34
- package/src/rules/store/good-action-hygiene.js.map +1 -1
- package/src/rules/store/no-multiple-global-stores.d.ts +6 -0
- package/src/rules/store/no-multiple-global-stores.js +34 -96
- package/src/rules/store/no-multiple-global-stores.js.map +1 -1
- package/src/rules/store/no-reducer-in-key-names.d.ts +5 -0
- package/src/rules/store/no-reducer-in-key-names.js +16 -20
- package/src/rules/store/no-reducer-in-key-names.js.map +1 -1
- package/src/rules/store/no-store-subscription.d.ts +3 -0
- package/src/rules/store/no-store-subscription.js +13 -16
- package/src/rules/store/no-store-subscription.js.map +1 -1
- package/src/rules/store/no-typed-global-store.d.ts +5 -0
- package/src/rules/store/no-typed-global-store.js +29 -70
- package/src/rules/store/no-typed-global-store.js.map +1 -1
- package/src/rules/store/on-function-explicit-return-type.d.ts +6 -0
- package/src/rules/store/on-function-explicit-return-type.js +23 -43
- package/src/rules/store/on-function-explicit-return-type.js.map +1 -1
- package/src/rules/store/prefer-action-creator-in-dispatch.d.ts +3 -0
- package/src/rules/store/prefer-action-creator-in-dispatch.js +15 -18
- package/src/rules/store/prefer-action-creator-in-dispatch.js.map +1 -1
- package/src/rules/store/prefer-action-creator.d.ts +3 -0
- package/src/rules/store/prefer-action-creator.js +10 -13
- package/src/rules/store/prefer-action-creator.js.map +1 -1
- package/src/rules/store/prefer-inline-action-props.d.ts +5 -0
- package/src/rules/store/prefer-inline-action-props.js +14 -18
- package/src/rules/store/prefer-inline-action-props.js.map +1 -1
- package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.d.ts +5 -0
- package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js +16 -37
- package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js.map +1 -1
- package/src/rules/store/prefer-selector-in-select.d.ts +3 -0
- package/src/rules/store/prefer-selector-in-select.js +21 -46
- package/src/rules/store/prefer-selector-in-select.js.map +1 -1
- package/src/rules/store/prefix-selectors-with-select.d.ts +5 -0
- package/src/rules/store/prefix-selectors-with-select.js +26 -39
- package/src/rules/store/prefix-selectors-with-select.js.map +1 -1
- package/src/rules/store/select-style.d.ts +11 -0
- package/src/rules/store/select-style.js +53 -108
- package/src/rules/store/select-style.js.map +1 -1
- package/src/rules/store/use-consistent-global-store-name.d.ts +6 -0
- package/src/rules/store/use-consistent-global-store-name.js +24 -80
- package/src/rules/store/use-consistent-global-store-name.js.map +1 -1
- package/src/utils/helper-functions/docs.d.ts +1 -0
- package/src/utils/helper-functions/docs.js +1 -3
- package/src/utils/helper-functions/docs.js.map +1 -1
- package/src/utils/helper-functions/folder.d.ts +5 -0
- package/src/utils/helper-functions/folder.js +16 -88
- package/src/utils/helper-functions/folder.js.map +1 -1
- package/src/utils/helper-functions/guards.d.ts +97 -0
- package/src/utils/helper-functions/guards.js +27 -31
- package/src/utils/helper-functions/guards.js.map +1 -1
- package/src/utils/helper-functions/index.d.ts +6 -0
- package/src/utils/helper-functions/ngrx-modules.d.ts +8 -0
- package/src/utils/helper-functions/ngrx-modules.js +7 -6
- package/src/utils/helper-functions/ngrx-modules.js.map +1 -1
- package/src/utils/helper-functions/rules.d.ts +3 -0
- package/src/utils/helper-functions/rules.js +47 -0
- package/src/utils/helper-functions/rules.js.map +1 -0
- package/src/utils/helper-functions/utils.d.ts +48 -0
- package/src/utils/helper-functions/utils.js +68 -143
- package/src/utils/helper-functions/utils.js.map +1 -1
- package/src/utils/helper-functions/versions.d.ts +1 -0
- package/src/utils/helper-functions/versions.js +9 -10
- package/src/utils/helper-functions/versions.js.map +1 -1
- package/src/utils/index.d.ts +2 -0
- package/src/utils/selectors/index.d.ts +29 -0
- package/src/utils/selectors/index.js +30 -44
- package/src/utils/selectors/index.js.map +1 -1
- package/v9/index.d.ts +29 -0
- package/v9/index.js +38 -0
- package/v9/index.js.map +1 -0
- package/src/configs/all-requiring-type-checking.js +0 -46
- package/src/configs/all-requiring-type-checking.js.map +0 -1
- package/src/configs/component-store-strict.js +0 -15
- package/src/configs/component-store-strict.js.map +0 -1
- package/src/configs/effects-requiring-type-checking.js +0 -25
- package/src/configs/effects-requiring-type-checking.js.map +0 -1
- package/src/configs/effects-strict-requiring-type-checking.js +0 -25
- package/src/configs/effects-strict-requiring-type-checking.js.map +0 -1
- package/src/configs/effects-strict.js +0 -18
- package/src/configs/effects-strict.js.map +0 -1
- package/src/configs/index.js +0 -33
- package/src/configs/index.js.map +0 -1
- package/src/configs/recommended-requiring-type-checking.js +0 -46
- package/src/configs/recommended-requiring-type-checking.js.map +0 -1
- package/src/configs/recommended.js +0 -39
- package/src/configs/recommended.js.map +0 -1
- package/src/configs/store-strict.js +0 -30
- package/src/configs/store-strict.js.map +0 -1
- package/src/configs/strict-requiring-type-checking.js +0 -46
- package/src/configs/strict-requiring-type-checking.js.map +0 -1
- package/src/configs/strict.js +0 -39
- package/src/configs/strict.js.map +0 -1
- package/src/rules/effects/prefer-concat-latest-from.js +0 -153
- package/src/rules/effects/prefer-concat-latest-from.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"with-state-no-arrays-at-root-level.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/signals/with-state-no-arrays-at-root-level.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsE;AACtE,2CAA6B;AAC7B,qDAAgD;AAChD,uCAAgD;AAEnC,QAAA,SAAS,GAAG,8BAA8B,CAAC;AAKxD,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,SAAS;QACrB,IAAI,EAAE;YACJ,WAAW,EAAE,sEAAsE;YACnF,oBAAoB,EAAE,IAAI;SAC3B;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iBAAS,CAAC,EAAE,4CAA4C;SAC1D;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,OAAO;YACL,CAAC,uCAAuC,CAAC,CAAC,IAA6B;gBACrE,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC;gBAClC,IAAI,IAAA,yBAAiB,EAAC,QAAQ,CAAC,EAAE,CAAC;oBAChC,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,QAAQ;wBACd,SAAS,EAAT,iBAAS;qBACV,CAAC,CAAC;gBACL,CAAC;qBAAM,IAAI,QAAQ,EAAE,CAAC;oBACpB,MAAM,QAAQ,GAAG,mBAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;oBACxD,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;oBACtD,MAAM,IAAI,GAAG,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;oBAElD,IAAI,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;wBAClC,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,QAAQ;4BACd,SAAS,EAAT,iBAAS;yBACV,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import { ESLintUtils, type TSESTree } from '@typescript-eslint/utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { isArrayExpression } from '../../utils';\n\nexport const messageId = 'withStateNoArraysAtRootLevel';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'problem',\n ngrxModule: 'signals',\n docs: {\n description: `withState should accept a record or dictionary as an input argument.`,\n requiresTypeChecking: true,\n },\n schema: [],\n messages: {\n [messageId]: `Wrap the array in an record or dictionary.`,\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n [`CallExpression[callee.name=withState]`](node: TSESTree.CallExpression) {\n const [argument] = node.arguments;\n if (isArrayExpression(argument)) {\n context.report({\n node: argument,\n messageId,\n });\n } else if (argument) {\n const services = ESLintUtils.getParserServices(context);\n const typeChecker = services.program.getTypeChecker();\n const type = services.getTypeAtLocation(argument);\n\n if (typeChecker.isArrayType(type)) {\n context.report({\n node: argument,\n messageId,\n });\n }\n }\n },\n };\n },\n});\n"]}
|
|
@@ -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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const rule_creator_1 = require("../../rule-creator");
|
|
29
|
+
const utils_1 = require("../../utils");
|
|
42
30
|
exports.messageId = 'avoidCombiningSelectors';
|
|
43
31
|
exports.default = (0, rule_creator_1.createRule)({
|
|
44
32
|
name: path.parse(__filename).name,
|
|
@@ -47,48 +35,35 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
47
35
|
ngrxModule: 'store',
|
|
48
36
|
docs: {
|
|
49
37
|
description: 'Prefer combining selectors at the selector level.',
|
|
50
|
-
recommended: 'warn',
|
|
51
38
|
},
|
|
52
39
|
schema: [],
|
|
53
|
-
messages:
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
messages: {
|
|
41
|
+
[exports.messageId]: 'Combine selectors at the selector level.',
|
|
42
|
+
},
|
|
56
43
|
},
|
|
57
44
|
defaultOptions: [],
|
|
58
|
-
create:
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
return
|
|
68
|
-
|
|
51
|
+
const pipeableOrStoreSelect = `:matches(${(0, utils_1.namedExpression)(storeNames)}[callee.property.name='pipe']:has(CallExpression[callee.name='select']), ${(0, utils_1.selectExpression)(storeNames)})`;
|
|
52
|
+
const selectsInArray = [];
|
|
53
|
+
return {
|
|
54
|
+
[`CallExpression[callee.name='combineLatest'] ${pipeableOrStoreSelect} ~ ${pipeableOrStoreSelect}`](node) {
|
|
69
55
|
selectsInArray.push(node);
|
|
70
56
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
node: node,
|
|
78
|
-
messageId: exports.messageId,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
-
finally {
|
|
84
|
-
try {
|
|
85
|
-
if (selectsInArray_1_1 && !selectsInArray_1_1.done && (_a = selectsInArray_1.return)) _a.call(selectsInArray_1);
|
|
86
|
-
}
|
|
87
|
-
finally { if (e_1) throw e_1.error; }
|
|
57
|
+
[`CallExpression[callee.name='combineLatest']:exit`]() {
|
|
58
|
+
for (const node of selectsInArray) {
|
|
59
|
+
context.report({
|
|
60
|
+
node,
|
|
61
|
+
messageId: exports.messageId,
|
|
62
|
+
});
|
|
88
63
|
}
|
|
89
64
|
selectsInArray.length = 0;
|
|
90
65
|
},
|
|
91
|
-
|
|
66
|
+
};
|
|
92
67
|
},
|
|
93
68
|
});
|
|
94
69
|
//# sourceMappingURL=avoid-combining-selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avoid-combining-selectors.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-combining-selectors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avoid-combining-selectors.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-combining-selectors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAKqB;AAER,QAAA,SAAS,GAAG,yBAAyB,CAAC;AAKnD,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,EAAE,mDAAmD;SACjE;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iBAAS,CAAC,EAAE,0CAA0C;SACxD;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,MAAM,qBAAqB,GAAG,YAAY,IAAA,uBAAe,EACvD,UAAU,CACX,4EAA4E,IAAA,wBAAgB,EAC3F,UAAU,CACX,GAAY,CAAC;QAEd,MAAM,cAAc,GAA8B,EAAE,CAAC;QACrD,OAAO;YACL,CAAC,+CAA+C,qBAAqB,MAAM,qBAAqB,EAAE,CAAC,CACjG,IAA6B;gBAE7B,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YACD,CAAC,kDAAkD,CAAC;gBAClD,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;oBAClC,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI;wBACJ,SAAS,EAAT,iBAAS;qBACV,CAAC,CAAC;gBACL,CAAC;gBACD,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;YAC5B,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 namedExpression,\n selectExpression,\n} from '../../utils';\n\nexport const messageId = 'avoidCombiningSelectors';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description: 'Prefer combining selectors at the selector level.',\n },\n schema: [],\n messages: {\n [messageId]: 'Combine selectors at the selector level.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n const pipeableOrStoreSelect = `:matches(${namedExpression(\n storeNames\n )}[callee.property.name='pipe']:has(CallExpression[callee.name='select']), ${selectExpression(\n storeNames\n )})` as const;\n\n const selectsInArray: TSESTree.CallExpression[] = [];\n return {\n [`CallExpression[callee.name='combineLatest'] ${pipeableOrStoreSelect} ~ ${pipeableOrStoreSelect}`](\n node: TSESTree.CallExpression\n ) {\n selectsInArray.push(node);\n },\n [`CallExpression[callee.name='combineLatest']:exit`]() {\n for (const node of selectsInArray) {\n context.report({\n node,\n messageId,\n });\n }\n selectsInArray.length = 0;\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const messageId = "avoidDispatchingMultipleActionsSequentially";
|
|
2
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<"avoidDispatchingMultipleActionsSequentially", readonly [], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
3
|
+
export default _default;
|
|
@@ -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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const rule_creator_1 = require("../../rule-creator");
|
|
29
|
+
const utils_1 = require("../../utils");
|
|
42
30
|
exports.messageId = 'avoidDispatchingMultipleActionsSequentially';
|
|
43
31
|
exports.default = (0, rule_creator_1.createRule)({
|
|
44
32
|
name: path.parse(__filename).name,
|
|
@@ -47,52 +35,37 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
47
35
|
ngrxModule: 'store',
|
|
48
36
|
docs: {
|
|
49
37
|
description: 'It is recommended to only dispatch one `Action` at a time.',
|
|
50
|
-
recommended: 'warn',
|
|
51
38
|
},
|
|
52
39
|
schema: [],
|
|
53
|
-
messages:
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
messages: {
|
|
41
|
+
[exports.messageId]: 'Avoid dispatching many actions in a row to accomplish a larger conceptual "transaction".',
|
|
42
|
+
},
|
|
56
43
|
},
|
|
57
44
|
defaultOptions: [],
|
|
58
|
-
create:
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
66
|
-
return
|
|
67
|
-
|
|
51
|
+
const collectedDispatches = [];
|
|
52
|
+
return {
|
|
53
|
+
[`BlockStatement > ExpressionStatement > ${(0, utils_1.dispatchExpression)(storeNames)}`](node) {
|
|
68
54
|
collectedDispatches.push(node);
|
|
69
55
|
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var withSameParent = collectedDispatches.filter(function (d1) {
|
|
73
|
-
return collectedDispatches.some(function (d2) { var _a, _b; return d2 !== d1 && ((_a = d2.parent) === null || _a === void 0 ? void 0 : _a.parent) === ((_b = d1.parent) === null || _b === void 0 ? void 0 : _b.parent); });
|
|
74
|
-
});
|
|
56
|
+
'BlockStatement:exit'() {
|
|
57
|
+
const withSameParent = collectedDispatches.filter((d1) => collectedDispatches.some((d2) => d2 !== d1 && d2.parent?.parent === d1.parent?.parent));
|
|
75
58
|
if (withSameParent.length > 1) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
messageId: exports.messageId,
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
86
|
-
finally {
|
|
87
|
-
try {
|
|
88
|
-
if (withSameParent_1_1 && !withSameParent_1_1.done && (_a = withSameParent_1.return)) _a.call(withSameParent_1);
|
|
89
|
-
}
|
|
90
|
-
finally { if (e_1) throw e_1.error; }
|
|
59
|
+
for (const node of withSameParent) {
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
messageId: exports.messageId,
|
|
63
|
+
});
|
|
91
64
|
}
|
|
92
65
|
}
|
|
93
66
|
collectedDispatches.length = 0;
|
|
94
67
|
},
|
|
95
|
-
|
|
68
|
+
};
|
|
96
69
|
},
|
|
97
70
|
});
|
|
98
71
|
//# sourceMappingURL=avoid-dispatching-multiple-actions-sequentially.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avoid-dispatching-multiple-actions-sequentially.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-dispatching-multiple-actions-sequentially.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avoid-dispatching-multiple-actions-sequentially.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-dispatching-multiple-actions-sequentially.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAA2E;AAE9D,QAAA,SAAS,GAAG,6CAA6C,CAAC;AAKvE,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,EAAE,4DAA4D;SAC1E;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iBAAS,CAAC,EACT,0FAA0F;SAC7F;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,MAAM,mBAAmB,GAA8B,EAAE,CAAC;QAE1D,OAAO;YACL,CAAC,0CAA0C,IAAA,0BAAkB,EAC3D,UAAU,CACX,EAAE,CAAC,CAAC,IAA6B;gBAChC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,CAAC;YACD,qBAAqB;gBACnB,MAAM,cAAc,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CACvD,mBAAmB,CAAC,IAAI,CACtB,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAC7D,CACF,CAAC;gBACF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC9B,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE,CAAC;wBAClC,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAT,iBAAS;yBACV,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAED,mBAAmB,CAAC,MAAM,GAAG,CAAC,CAAC;YACjC,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 { asPattern, dispatchExpression, getNgRxStores } from '../../utils';\n\nexport const messageId = 'avoidDispatchingMultipleActionsSequentially';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description: 'It is recommended to only dispatch one `Action` at a time.',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Avoid dispatching many actions in a row to accomplish a larger conceptual \"transaction\".',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n const collectedDispatches: TSESTree.CallExpression[] = [];\n\n return {\n [`BlockStatement > ExpressionStatement > ${dispatchExpression(\n storeNames\n )}`](node: TSESTree.CallExpression) {\n collectedDispatches.push(node);\n },\n 'BlockStatement:exit'() {\n const withSameParent = collectedDispatches.filter((d1) =>\n collectedDispatches.some(\n (d2) => d2 !== d1 && d2.parent?.parent === d1.parent?.parent\n )\n );\n if (withSameParent.length > 1) {\n for (const node of withSameParent) {\n context.report({\n node,\n messageId,\n });\n }\n }\n\n collectedDispatches.length = 0;\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const avoidDuplicateActionsInReducer = "avoidDuplicateActionsInReducer";
|
|
2
|
+
export declare const avoidDuplicateActionsInReducerSuggest = "avoidDuplicateActionsInReducerSuggest";
|
|
3
|
+
type MessageIds = typeof avoidDuplicateActionsInReducer | typeof avoidDuplicateActionsInReducerSuggest;
|
|
4
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, readonly [], import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
5
|
+
export default _default;
|
|
@@ -22,48 +22,11 @@ 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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
42
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
43
|
-
if (ar || !(i in from)) {
|
|
44
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
45
|
-
ar[i] = from[i];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
49
|
-
};
|
|
50
|
-
var __values = (this && this.__values) || function(o) {
|
|
51
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
52
|
-
if (m) return m.call(o);
|
|
53
|
-
if (o && typeof o.length === "number") return {
|
|
54
|
-
next: function () {
|
|
55
|
-
if (o && i >= o.length) o = void 0;
|
|
56
|
-
return { value: o && o[i++], done: !o };
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
60
|
-
};
|
|
61
|
-
var _a;
|
|
62
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
26
|
exports.avoidDuplicateActionsInReducerSuggest = exports.avoidDuplicateActionsInReducer = void 0;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const rule_creator_1 = require("../../rule-creator");
|
|
29
|
+
const utils_1 = require("../../utils");
|
|
67
30
|
exports.avoidDuplicateActionsInReducer = 'avoidDuplicateActionsInReducer';
|
|
68
31
|
exports.avoidDuplicateActionsInReducerSuggest = 'avoidDuplicateActionsInReducerSuggest';
|
|
69
32
|
exports.default = (0, rule_creator_1.createRule)({
|
|
@@ -74,77 +37,46 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
74
37
|
ngrxModule: 'store',
|
|
75
38
|
docs: {
|
|
76
39
|
description: 'A `Reducer` should handle an `Action` once.',
|
|
77
|
-
recommended: 'warn',
|
|
78
|
-
suggestion: true,
|
|
79
40
|
},
|
|
80
41
|
schema: [],
|
|
81
|
-
messages:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
42
|
+
messages: {
|
|
43
|
+
[exports.avoidDuplicateActionsInReducer]: 'The `Reducer` handles a duplicate `Action` `{{ actionName }}`.',
|
|
44
|
+
[exports.avoidDuplicateActionsInReducerSuggest]: 'Remove this duplication.',
|
|
45
|
+
},
|
|
85
46
|
},
|
|
86
47
|
defaultOptions: [],
|
|
87
|
-
create:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var _c = __read(_a.arguments, 1), action = _c[0];
|
|
95
|
-
var actions = (_b = collectedActions.get(action.name)) !== null && _b !== void 0 ? _b : [];
|
|
96
|
-
collectedActions.set(action.name, __spreadArray(__spreadArray([], __read(actions), false), [action], false));
|
|
48
|
+
create: (context) => {
|
|
49
|
+
const sourceCode = context.getSourceCode();
|
|
50
|
+
const collectedActions = new Map();
|
|
51
|
+
return {
|
|
52
|
+
[`${utils_1.createReducer} > CallExpression[callee.name='on'][arguments.0.type='Identifier']`]({ arguments: [action], }) {
|
|
53
|
+
const actions = collectedActions.get(action.name) ?? [];
|
|
54
|
+
collectedActions.set(action.name, [...actions, action]);
|
|
97
55
|
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
var _c = __read(collectedActions_1_1.value, 2), actionName = _c[0], identifiers = _c[1];
|
|
103
|
-
if (identifiers.length <= 1) {
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
var _loop_1 = function (node) {
|
|
107
|
-
context.report({
|
|
108
|
-
node: node,
|
|
109
|
-
messageId: exports.avoidDuplicateActionsInReducer,
|
|
110
|
-
data: {
|
|
111
|
-
actionName: actionName,
|
|
112
|
-
},
|
|
113
|
-
suggest: [
|
|
114
|
-
{
|
|
115
|
-
messageId: exports.avoidDuplicateActionsInReducerSuggest,
|
|
116
|
-
fix: function (fixer) {
|
|
117
|
-
return (0, utils_1.getNodeToCommaRemoveFix)(sourceCode, fixer, node.parent);
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
try {
|
|
124
|
-
for (var identifiers_1 = (e_2 = void 0, __values(identifiers)), identifiers_1_1 = identifiers_1.next(); !identifiers_1_1.done; identifiers_1_1 = identifiers_1.next()) {
|
|
125
|
-
var node = identifiers_1_1.value;
|
|
126
|
-
_loop_1(node);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
130
|
-
finally {
|
|
131
|
-
try {
|
|
132
|
-
if (identifiers_1_1 && !identifiers_1_1.done && (_b = identifiers_1.return)) _b.call(identifiers_1);
|
|
133
|
-
}
|
|
134
|
-
finally { if (e_2) throw e_2.error; }
|
|
135
|
-
}
|
|
56
|
+
[`${utils_1.createReducer}:exit`]() {
|
|
57
|
+
for (const [actionName, identifiers] of collectedActions) {
|
|
58
|
+
if (identifiers.length <= 1) {
|
|
59
|
+
break;
|
|
136
60
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
61
|
+
for (const node of identifiers) {
|
|
62
|
+
context.report({
|
|
63
|
+
node,
|
|
64
|
+
messageId: exports.avoidDuplicateActionsInReducer,
|
|
65
|
+
data: {
|
|
66
|
+
actionName,
|
|
67
|
+
},
|
|
68
|
+
suggest: [
|
|
69
|
+
{
|
|
70
|
+
messageId: exports.avoidDuplicateActionsInReducerSuggest,
|
|
71
|
+
fix: (fixer) => (0, utils_1.getNodeToCommaRemoveFix)(sourceCode, fixer, node.parent),
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
142
75
|
}
|
|
143
|
-
finally { if (e_1) throw e_1.error; }
|
|
144
76
|
}
|
|
145
77
|
collectedActions.clear();
|
|
146
78
|
},
|
|
147
|
-
|
|
79
|
+
};
|
|
148
80
|
},
|
|
149
81
|
});
|
|
150
82
|
//# sourceMappingURL=avoid-duplicate-actions-in-reducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avoid-duplicate-actions-in-reducer.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-duplicate-actions-in-reducer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avoid-duplicate-actions-in-reducer.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-duplicate-actions-in-reducer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAAqE;AAExD,QAAA,8BAA8B,GAAG,gCAAgC,CAAC;AAClE,QAAA,qCAAqC,GAChD,uCAAuC,CAAC;AAQ1C,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,EAAE,6CAA6C;SAC3D;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,sCAA8B,CAAC,EAC9B,gEAAgE;YAClE,CAAC,6CAAqC,CAAC,EAAE,0BAA0B;SACpE;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAC3C,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAoB,CAAC;QAErD,OAAO;YACL,CAAC,GAAG,qBAAa,oEAAoE,CAAC,CAAC,EACrF,SAAS,EAAE,CAAC,MAAM,CAAC,GAGpB;gBACC,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACxD,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;YAC1D,CAAC;YACD,CAAC,GAAG,qBAAa,OAAO,CAAC;gBACvB,KAAK,MAAM,CAAC,UAAU,EAAE,WAAW,CAAC,IAAI,gBAAgB,EAAE,CAAC;oBACzD,IAAI,WAAW,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;wBAC5B,MAAM;oBACR,CAAC;oBAED,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;wBAC/B,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI;4BACJ,SAAS,EAAE,sCAA8B;4BACzC,IAAI,EAAE;gCACJ,UAAU;6BACX;4BACD,OAAO,EAAE;gCACP;oCACE,SAAS,EAAE,6CAAqC;oCAChD,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CACb,IAAA,+BAAuB,EAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;iCAC1D;6BACF;yBACF,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAED,gBAAgB,CAAC,KAAK,EAAE,CAAC;YAC3B,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 { createReducer, getNodeToCommaRemoveFix } from '../../utils';\n\nexport const avoidDuplicateActionsInReducer = 'avoidDuplicateActionsInReducer';\nexport const avoidDuplicateActionsInReducerSuggest =\n 'avoidDuplicateActionsInReducerSuggest';\n\ntype MessageIds =\n | typeof avoidDuplicateActionsInReducer\n | typeof avoidDuplicateActionsInReducerSuggest;\ntype Options = readonly [];\ntype Action = TSESTree.Identifier & { parent: TSESTree.CallExpression };\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n hasSuggestions: true,\n ngrxModule: 'store',\n docs: {\n description: 'A `Reducer` should handle an `Action` once.',\n },\n schema: [],\n messages: {\n [avoidDuplicateActionsInReducer]:\n 'The `Reducer` handles a duplicate `Action` `{{ actionName }}`.',\n [avoidDuplicateActionsInReducerSuggest]: 'Remove this duplication.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const sourceCode = context.getSourceCode();\n const collectedActions = new Map<string, Action[]>();\n\n return {\n [`${createReducer} > CallExpression[callee.name='on'][arguments.0.type='Identifier']`]({\n arguments: [action],\n }: TSESTree.CallExpression & {\n arguments: Action[];\n }) {\n const actions = collectedActions.get(action.name) ?? [];\n collectedActions.set(action.name, [...actions, action]);\n },\n [`${createReducer}:exit`]() {\n for (const [actionName, identifiers] of collectedActions) {\n if (identifiers.length <= 1) {\n break;\n }\n\n for (const node of identifiers) {\n context.report({\n node,\n messageId: avoidDuplicateActionsInReducer,\n data: {\n actionName,\n },\n suggest: [\n {\n messageId: avoidDuplicateActionsInReducerSuggest,\n fix: (fixer) =>\n getNodeToCommaRemoveFix(sourceCode, fixer, node.parent),\n },\n ],\n });\n }\n }\n\n collectedActions.clear();\n },\n };\n },\n});\n"]}
|
|
@@ -22,13 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var _a;
|
|
26
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
26
|
exports.messageId = void 0;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
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");
|
|
32
30
|
exports.messageId = 'avoidMapppingSelectors';
|
|
33
31
|
exports.default = (0, rule_creator_1.createRule)({
|
|
34
32
|
name: path.parse(__filename).name,
|
|
@@ -37,28 +35,26 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
37
35
|
ngrxModule: 'store',
|
|
38
36
|
docs: {
|
|
39
37
|
description: 'Avoid mapping logic outside the selector level.',
|
|
40
|
-
recommended: 'warn',
|
|
41
38
|
},
|
|
42
39
|
schema: [],
|
|
43
|
-
messages:
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
messages: {
|
|
41
|
+
[exports.messageId]: 'Map logic at the selector level instead.',
|
|
42
|
+
},
|
|
46
43
|
},
|
|
47
44
|
defaultOptions: [],
|
|
48
|
-
create:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
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;
|
|
52
48
|
if (!storeNames) {
|
|
53
49
|
return {};
|
|
54
50
|
}
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const pipeWithSelectAndMapSelector = `${(0, utils_1.pipeExpression)(storeNames)}:has(CallExpression[callee.name='select'] ~ CallExpression[callee.name='map'])`;
|
|
52
|
+
const selectSelector = `${(0, utils_1.namedCallableExpression)(storeNames)}[callee.object.callee.property.name='select']`;
|
|
57
53
|
function isInCreateEffect(node) {
|
|
58
|
-
|
|
54
|
+
let parent = node.parent;
|
|
59
55
|
while (parent) {
|
|
60
|
-
if ((0,
|
|
61
|
-
(0,
|
|
56
|
+
if ((0, utils_1.isCallExpression)(parent) &&
|
|
57
|
+
(0, utils_1.isIdentifier)(parent.callee) &&
|
|
62
58
|
parent.callee.name === 'createEffect') {
|
|
63
59
|
return true;
|
|
64
60
|
}
|
|
@@ -66,13 +62,13 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
66
62
|
}
|
|
67
63
|
return false;
|
|
68
64
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
|
|
65
|
+
let pipeHasThisExpression = false;
|
|
66
|
+
const selectorQuery = `:matches(${selectSelector}, ${pipeWithSelectAndMapSelector})`;
|
|
67
|
+
return {
|
|
68
|
+
[`${selectorQuery} > CallExpression:has(ThisExpression)`](_node) {
|
|
73
69
|
pipeHasThisExpression = true;
|
|
74
70
|
},
|
|
75
|
-
|
|
71
|
+
[`${selectorQuery}[callee.property.name=pipe]:exit`](node) {
|
|
76
72
|
if (pipeHasThisExpression) {
|
|
77
73
|
pipeHasThisExpression = false;
|
|
78
74
|
return;
|
|
@@ -80,12 +76,10 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
80
76
|
if (isInCreateEffect(node)) {
|
|
81
77
|
return;
|
|
82
78
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
operator.callee.name === 'map';
|
|
88
|
-
});
|
|
79
|
+
const operators = node.arguments;
|
|
80
|
+
const mapOperator = operators.find((operator) => (0, utils_1.isCallExpression)(operator) &&
|
|
81
|
+
(0, utils_1.isIdentifier)(operator.callee) &&
|
|
82
|
+
operator.callee.name === 'map');
|
|
89
83
|
if (mapOperator) {
|
|
90
84
|
context.report({
|
|
91
85
|
node: mapOperator,
|
|
@@ -93,7 +87,7 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
93
87
|
});
|
|
94
88
|
}
|
|
95
89
|
},
|
|
96
|
-
|
|
90
|
+
};
|
|
97
91
|
},
|
|
98
92
|
});
|
|
99
93
|
//# sourceMappingURL=avoid-mapping-selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avoid-mapping-selectors.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-mapping-selectors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avoid-mapping-selectors.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/avoid-mapping-selectors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAOqB;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,EAAE,iDAAiD;SAC/D;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iBAAS,CAAC,EAAE,0CAA0C;SACxD;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,MAAM,4BAA4B,GAAG,GAAG,IAAA,sBAAc,EACpD,UAAU,CACX,gFAAyF,CAAC;QAC3F,MAAM,cAAc,GAAG,GAAG,IAAA,+BAAuB,EAC/C,UAAU,CACX,+CAAwD,CAAC;QAE1D,SAAS,gBAAgB,CAAC,IAA6B;YACrD,IAAI,MAAM,GAA8B,IAAI,CAAC,MAAM,CAAC;YACpD,OAAO,MAAM,EAAE,CAAC;gBACd,IACE,IAAA,wBAAgB,EAAC,MAAM,CAAC;oBACxB,IAAA,oBAAY,EAAC,MAAM,CAAC,MAAM,CAAC;oBAC3B,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,cAAc,EACrC,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YACzB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,qBAAqB,GAAG,KAAK,CAAC;QAElC,MAAM,aAAa,GAAG,YAAY,cAAc,KAAK,4BAA4B,GAAG,CAAC;QACrF,OAAO;YACL,CAAC,GAAG,aAAa,uCAAuC,CAAC,CACvD,KAA8B;gBAE9B,qBAAqB,GAAG,IAAI,CAAC;YAC/B,CAAC;YACD,CAAC,GAAG,aAAa,kCAAkC,CAAC,CAClD,IAA6B;gBAE7B,IAAI,qBAAqB,EAAE,CAAC;oBAC1B,qBAAqB,GAAG,KAAK,CAAC;oBAC9B,OAAO;gBACT,CAAC;gBAED,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;oBAC3B,OAAO;gBACT,CAAC;gBAED,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;gBACjC,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAChC,CAAC,QAAQ,EAAE,EAAE,CACX,IAAA,wBAAgB,EAAC,QAAQ,CAAC;oBAC1B,IAAA,oBAAY,EAAC,QAAQ,CAAC,MAAM,CAAC;oBAC7B,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK,CACjC,CAAC;gBACF,IAAI,WAAW,EAAE,CAAC;oBAChB,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,WAAW;wBACjB,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 isCallExpression,\n isIdentifier,\n namedCallableExpression,\n pipeExpression,\n} from '../../utils';\n\nexport const messageId = 'avoidMapppingSelectors';\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: 'Avoid mapping logic outside the selector level.',\n },\n schema: [],\n messages: {\n [messageId]: 'Map logic at the selector level 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 const pipeWithSelectAndMapSelector = `${pipeExpression(\n storeNames\n )}:has(CallExpression[callee.name='select'] ~ CallExpression[callee.name='map'])` as const;\n const selectSelector = `${namedCallableExpression(\n storeNames\n )}[callee.object.callee.property.name='select']` as const;\n\n function isInCreateEffect(node: TSESTree.CallExpression) {\n let parent: TSESTree.Node | undefined = node.parent;\n while (parent) {\n if (\n isCallExpression(parent) &&\n isIdentifier(parent.callee) &&\n parent.callee.name === 'createEffect'\n ) {\n return true;\n }\n parent = parent.parent;\n }\n return false;\n }\n\n let pipeHasThisExpression = false;\n\n const selectorQuery = `:matches(${selectSelector}, ${pipeWithSelectAndMapSelector})`;\n return {\n [`${selectorQuery} > CallExpression:has(ThisExpression)`](\n _node: TSESTree.CallExpression\n ) {\n pipeHasThisExpression = true;\n },\n [`${selectorQuery}[callee.property.name=pipe]:exit`](\n node: TSESTree.CallExpression\n ) {\n if (pipeHasThisExpression) {\n pipeHasThisExpression = false;\n return;\n }\n\n if (isInCreateEffect(node)) {\n return;\n }\n\n const operators = node.arguments;\n const mapOperator = operators.find(\n (operator) =>\n isCallExpression(operator) &&\n isIdentifier(operator.callee) &&\n operator.callee.name === 'map'\n );\n if (mapOperator) {\n context.report({\n node: mapOperator,\n messageId,\n });\n }\n },\n };\n },\n});\n"]}
|