@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.
- package/jest.config.d.ts +15 -0
- package/package.json +4 -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 +18 -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 +13 -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 +153 -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 +35 -0
- package/src/rules/index.js +74 -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 +10 -11
- 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
|
@@ -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 = 'preferSelectorInSelect';
|
|
43
31
|
exports.default = (0, rule_creator_1.createRule)({
|
|
44
32
|
name: path.parse(__filename).name,
|
|
@@ -47,47 +35,34 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
47
35
|
ngrxModule: 'store',
|
|
48
36
|
docs: {
|
|
49
37
|
description: 'Using a selector in the `select` is preferred over `string` or `props drilling`.',
|
|
50
|
-
recommended: 'warn',
|
|
51
38
|
},
|
|
52
39
|
schema: [],
|
|
53
|
-
messages:
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
messages: {
|
|
41
|
+
[exports.messageId]: 'Using `string` or `props drilling` is forbidden. Use a selector instead.',
|
|
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
|
-
return
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
!(0, utils_1.isArrowFunctionExpression)(argument) &&
|
|
73
|
-
!(0, utils_1.isFunctionExpression)(argument)) {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
context.report({
|
|
77
|
-
node: argument,
|
|
78
|
-
messageId: exports.messageId,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
-
finally {
|
|
84
|
-
try {
|
|
85
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
51
|
+
return {
|
|
52
|
+
[`${(0, utils_1.pipeableSelect)(storeNames)}, ${(0, utils_1.selectExpression)(storeNames)}`](node) {
|
|
53
|
+
for (const argument of node.arguments) {
|
|
54
|
+
if (!(0, utils_1.isLiteral)(argument) &&
|
|
55
|
+
!(0, utils_1.isArrowFunctionExpression)(argument) &&
|
|
56
|
+
!(0, utils_1.isFunctionExpression)(argument)) {
|
|
57
|
+
break;
|
|
86
58
|
}
|
|
87
|
-
|
|
59
|
+
context.report({
|
|
60
|
+
node: argument,
|
|
61
|
+
messageId: exports.messageId,
|
|
62
|
+
});
|
|
88
63
|
}
|
|
89
64
|
},
|
|
90
|
-
|
|
65
|
+
};
|
|
91
66
|
},
|
|
92
67
|
});
|
|
93
68
|
//# sourceMappingURL=prefer-selector-in-select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-selector-in-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-selector-in-select.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prefer-selector-in-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-selector-in-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAQqB;AAER,QAAA,SAAS,GAAG,wBAAwB,CAAC;AAKlD,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,kFAAkF;SACrF;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iBAAS,CAAC,EACT,0EAA0E;SAC7E;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,IAAA,qBAAa,EAAC,OAAO,CAAC,CAAC;QACpD,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1E,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,OAAO;YACL,CAAC,GAAG,IAAA,sBAAc,EAAC,UAAU,CAAC,KAAK,IAAA,wBAAgB,EAAC,UAAU,CAAC,EAAE,CAAC,CAChE,IAA6B;gBAE7B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;oBACtC,IACE,CAAC,IAAA,iBAAS,EAAC,QAAQ,CAAC;wBACpB,CAAC,IAAA,iCAAyB,EAAC,QAAQ,CAAC;wBACpC,CAAC,IAAA,4BAAoB,EAAC,QAAQ,CAAC,EAC/B,CAAC;wBACD,MAAM;oBACR,CAAC;oBAED,OAAO,CAAC,MAAM,CAAC;wBACb,IAAI,EAAE,QAAQ;wBACd,SAAS,EAAT,iBAAS;qBACV,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getNgRxStores,\n isArrowFunctionExpression,\n isFunctionExpression,\n isLiteral,\n pipeableSelect,\n selectExpression,\n} from '../../utils';\n\nexport const messageId = 'preferSelectorInSelect';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description:\n 'Using a selector in the `select` is preferred over `string` or `props drilling`.',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Using `string` or `props drilling` is forbidden. Use a selector instead.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n return {\n [`${pipeableSelect(storeNames)}, ${selectExpression(storeNames)}`](\n node: TSESTree.CallExpression\n ) {\n for (const argument of node.arguments) {\n if (\n !isLiteral(argument) &&\n !isArrowFunctionExpression(argument) &&\n !isFunctionExpression(argument)\n ) {\n break;\n }\n\n context.report({\n node: argument,\n messageId,\n });\n }\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const prefixSelectorsWithSelect = "prefixSelectorsWithSelect";
|
|
2
|
+
export declare const prefixSelectorsWithSelectSuggest = "prefixSelectorsWithSelectSuggest";
|
|
3
|
+
type MessageIds = typeof prefixSelectorsWithSelect | typeof prefixSelectorsWithSelectSuggest;
|
|
4
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, readonly [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
5
|
+
export default _default;
|
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -33,12 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
22
|
__setModuleDefault(result, mod);
|
|
34
23
|
return result;
|
|
35
24
|
};
|
|
36
|
-
var _a;
|
|
37
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
26
|
exports.prefixSelectorsWithSelectSuggest = exports.prefixSelectorsWithSelect = void 0;
|
|
39
|
-
|
|
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.prefixSelectorsWithSelect = 'prefixSelectorsWithSelect';
|
|
43
31
|
exports.prefixSelectorsWithSelectSuggest = 'prefixSelectorsWithSelectSuggest';
|
|
44
32
|
exports.default = (0, rule_creator_1.createRule)({
|
|
@@ -48,27 +36,29 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
48
36
|
hasSuggestions: true,
|
|
49
37
|
ngrxModule: 'store',
|
|
50
38
|
docs: {
|
|
51
|
-
description: 'The selector should start with "select", for example "
|
|
52
|
-
recommended: 'warn',
|
|
53
|
-
suggestion: true,
|
|
39
|
+
description: 'The selector should start with "select", for example "selectEntity".',
|
|
54
40
|
},
|
|
55
41
|
schema: [],
|
|
56
|
-
messages:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
messages: {
|
|
43
|
+
[exports.prefixSelectorsWithSelect]: 'The selector should start with "select".',
|
|
44
|
+
[exports.prefixSelectorsWithSelectSuggest]: 'Prefix the selector with "select": `{{ name }}`.',
|
|
45
|
+
},
|
|
60
46
|
},
|
|
61
47
|
defaultOptions: [],
|
|
62
|
-
create:
|
|
48
|
+
create: (context) => {
|
|
63
49
|
return {
|
|
64
|
-
'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name="createFeature"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))'
|
|
65
|
-
|
|
66
|
-
var id = _a.id;
|
|
67
|
-
var suggestedName = getSuggestedName(id.name);
|
|
50
|
+
'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name="createFeature"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))'({ id, }) {
|
|
51
|
+
const suggestedName = getSuggestedName(id.name);
|
|
68
52
|
context.report({
|
|
69
|
-
loc:
|
|
53
|
+
loc: {
|
|
54
|
+
...id.loc,
|
|
55
|
+
end: {
|
|
56
|
+
...id.loc.end,
|
|
57
|
+
column: id.typeAnnotation?.range[0]
|
|
70
58
|
? id.typeAnnotation.range[0] - 1
|
|
71
|
-
: id.loc.end.column
|
|
59
|
+
: id.loc.end.column,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
72
62
|
messageId: exports.prefixSelectorsWithSelect,
|
|
73
63
|
suggest: [
|
|
74
64
|
{
|
|
@@ -76,10 +66,7 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
76
66
|
data: {
|
|
77
67
|
name: suggestedName,
|
|
78
68
|
},
|
|
79
|
-
fix:
|
|
80
|
-
var _a, _b;
|
|
81
|
-
return fixer.replaceTextRange([id.range[0], (_b = (_a = id.typeAnnotation) === null || _a === void 0 ? void 0 : _a.range[0]) !== null && _b !== void 0 ? _b : id.range[1]], suggestedName);
|
|
82
|
-
},
|
|
69
|
+
fix: (fixer) => fixer.replaceTextRange([id.range[0], id.typeAnnotation?.range[0] ?? id.range[1]], suggestedName),
|
|
83
70
|
},
|
|
84
71
|
],
|
|
85
72
|
});
|
|
@@ -88,22 +75,22 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
88
75
|
},
|
|
89
76
|
});
|
|
90
77
|
function getSuggestedName(name) {
|
|
91
|
-
|
|
78
|
+
const selectWord = 'select';
|
|
92
79
|
// Ex: 'selectfeature' => 'selectFeature'
|
|
93
|
-
|
|
94
|
-
return
|
|
80
|
+
let possibleReplacedName = name.replace(new RegExp(`^${selectWord}(.+)`), (_, word) => {
|
|
81
|
+
return `${selectWord}${(0, utils_1.capitalize)(word)}`;
|
|
95
82
|
});
|
|
96
83
|
if (name !== possibleReplacedName) {
|
|
97
84
|
return possibleReplacedName;
|
|
98
85
|
}
|
|
99
86
|
// Ex: 'getCount' => 'selectCount'
|
|
100
|
-
possibleReplacedName = name.replace(/^get([^a-z].+)/,
|
|
101
|
-
return
|
|
87
|
+
possibleReplacedName = name.replace(/^get([^a-z].+)/, (_, word) => {
|
|
88
|
+
return `${selectWord}${(0, utils_1.capitalize)(word)}`;
|
|
102
89
|
});
|
|
103
90
|
if (name !== possibleReplacedName) {
|
|
104
91
|
return possibleReplacedName;
|
|
105
92
|
}
|
|
106
93
|
// Ex: 'item' => 'selectItem'
|
|
107
|
-
return
|
|
94
|
+
return `${selectWord}${(0, utils_1.capitalize)(name)}`;
|
|
108
95
|
}
|
|
109
96
|
//# sourceMappingURL=prefix-selectors-with-select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-selectors-with-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefix-selectors-with-select.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prefix-selectors-with-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefix-selectors-with-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAAyC;AAE5B,QAAA,yBAAyB,GAAG,2BAA2B,CAAC;AACxD,QAAA,gCAAgC,GAC3C,kCAAkC,CAAC;AAOrC,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,OA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AAG,QAAQ,CAAC;IAC5B,yCAAyC;IACzC,IAAI,oBAAoB,GAAG,IAAI,CAAC,OAAO,CACrC,IAAI,MAAM,CAAC,IAAI,UAAU,MAAM,CAAC,EAChC,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE;QAClB,OAAO,GAAG,UAAU,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;IAC5C,CAAC,CACF,CAAC;IAEF,IAAI,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAClC,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED,kCAAkC;IAClC,oBAAoB,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,IAAY,EAAE,EAAE;QACxE,OAAO,GAAG,UAAU,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,IAAI,IAAI,KAAK,oBAAoB,EAAE,CAAC;QAClC,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAED,6BAA6B;IAC7B,OAAO,GAAG,UAAU,GAAG,IAAA,kBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;AAC5C,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { capitalize } from '../../utils';\n\nexport const prefixSelectorsWithSelect = 'prefixSelectorsWithSelect';\nexport const prefixSelectorsWithSelectSuggest =\n 'prefixSelectorsWithSelectSuggest';\n\ntype MessageIds =\n | typeof prefixSelectorsWithSelect\n | typeof prefixSelectorsWithSelectSuggest;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n hasSuggestions: true,\n ngrxModule: 'store',\n docs: {\n description:\n 'The selector should start with \"select\", for example \"selectEntity\".',\n },\n schema: [],\n messages: {\n [prefixSelectorsWithSelect]: 'The selector should start with \"select\".',\n [prefixSelectorsWithSelectSuggest]:\n 'Prefix the selector with \"select\": `{{ name }}`.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n 'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name=\"createFeature\"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))'({\n id,\n }: TSESTree.VariableDeclarator & { id: TSESTree.Identifier }) {\n const suggestedName = getSuggestedName(id.name);\n context.report({\n loc: {\n ...id.loc,\n end: {\n ...id.loc.end,\n column: id.typeAnnotation?.range[0]\n ? id.typeAnnotation.range[0] - 1\n : id.loc.end.column,\n },\n },\n messageId: prefixSelectorsWithSelect,\n suggest: [\n {\n messageId: prefixSelectorsWithSelectSuggest,\n data: {\n name: suggestedName,\n },\n fix: (fixer) =>\n fixer.replaceTextRange(\n [id.range[0], id.typeAnnotation?.range[0] ?? id.range[1]],\n suggestedName\n ),\n },\n ],\n });\n },\n };\n },\n});\n\nfunction getSuggestedName(name: string) {\n const selectWord = 'select';\n // Ex: 'selectfeature' => 'selectFeature'\n let possibleReplacedName = name.replace(\n new RegExp(`^${selectWord}(.+)`),\n (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n }\n );\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'getCount' => 'selectCount'\n possibleReplacedName = name.replace(/^get([^a-z].+)/, (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n });\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'item' => 'selectItem'\n return `${selectWord}${capitalize(name)}`;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
|
+
export declare const selectMethod = "selectMethod";
|
|
3
|
+
export declare const selectOperator = "selectOperator";
|
|
4
|
+
export declare const enum SelectStyle {
|
|
5
|
+
Method = "method",
|
|
6
|
+
Operator = "operator"
|
|
7
|
+
}
|
|
8
|
+
type MessageIds = `${SelectStyle}`;
|
|
9
|
+
type Options = readonly [MessageIds];
|
|
10
|
+
declare const _default: TSESLint.RuleModule<"operator" | "method", Options, unknown, TSESLint.RuleListener>;
|
|
11
|
+
export default _default;
|
|
@@ -22,50 +22,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
-
if (!m) return o;
|
|
28
|
-
var i = m.call(o), r, ar = [], e;
|
|
29
|
-
try {
|
|
30
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
-
}
|
|
32
|
-
catch (error) { e = { error: error }; }
|
|
33
|
-
finally {
|
|
34
|
-
try {
|
|
35
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
-
}
|
|
37
|
-
finally { if (e) throw e.error; }
|
|
38
|
-
}
|
|
39
|
-
return ar;
|
|
40
|
-
};
|
|
41
|
-
var __values = (this && this.__values) || function(o) {
|
|
42
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
43
|
-
if (m) return m.call(o);
|
|
44
|
-
if (o && typeof o.length === "number") return {
|
|
45
|
-
next: function () {
|
|
46
|
-
if (o && i >= o.length) o = void 0;
|
|
47
|
-
return { value: o && o[i++], done: !o };
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
51
|
-
};
|
|
52
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
53
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
54
|
-
if (ar || !(i in from)) {
|
|
55
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
56
|
-
ar[i] = from[i];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
60
|
-
};
|
|
61
|
-
var _a;
|
|
62
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
-
exports.selectOperator = exports.selectMethod = void 0;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
26
|
+
exports.SelectStyle = exports.selectOperator = exports.selectMethod = void 0;
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const rule_creator_1 = require("../../rule-creator");
|
|
29
|
+
const utils_1 = require("../../utils");
|
|
67
30
|
exports.selectMethod = 'selectMethod';
|
|
68
31
|
exports.selectOperator = 'selectOperator';
|
|
32
|
+
var SelectStyle;
|
|
33
|
+
(function (SelectStyle) {
|
|
34
|
+
SelectStyle["Method"] = "method";
|
|
35
|
+
SelectStyle["Operator"] = "operator";
|
|
36
|
+
})(SelectStyle || (exports.SelectStyle = SelectStyle = {}));
|
|
69
37
|
exports.default = (0, rule_creator_1.createRule)({
|
|
70
38
|
name: path.parse(__filename).name,
|
|
71
39
|
meta: {
|
|
@@ -73,80 +41,58 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
73
41
|
ngrxModule: 'store',
|
|
74
42
|
docs: {
|
|
75
43
|
description: 'Selector can be used either with `select` as a pipeable operator or as a method.',
|
|
76
|
-
recommended: 'warn',
|
|
77
44
|
},
|
|
78
45
|
fixable: 'code',
|
|
79
46
|
schema: [
|
|
80
47
|
{
|
|
81
48
|
type: 'string',
|
|
82
|
-
enum: [
|
|
83
|
-
additionalProperties: false,
|
|
49
|
+
enum: [SelectStyle.Method, SelectStyle.Operator],
|
|
84
50
|
},
|
|
85
51
|
],
|
|
86
|
-
messages:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
52
|
+
messages: {
|
|
53
|
+
[SelectStyle.Method]: 'Selector should be used with select method: `this.store.select(selector)`.',
|
|
54
|
+
[SelectStyle.Operator]: 'Selector should be used with the pipeable operator: `this.store.pipe(select(selector))`.',
|
|
55
|
+
},
|
|
90
56
|
},
|
|
91
|
-
defaultOptions: [
|
|
92
|
-
create:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var _e = (0, utils_1.getNgRxStores)(context), _f = _e.identifiers, identifiers = _f === void 0 ? [] : _f, sourceCode = _e.sourceCode;
|
|
96
|
-
var storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
|
|
57
|
+
defaultOptions: [SelectStyle.Method],
|
|
58
|
+
create: (context, [mode]) => {
|
|
59
|
+
const { identifiers = [], sourceCode } = (0, utils_1.getNgRxStores)(context);
|
|
60
|
+
const storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
|
|
97
61
|
if (!storeNames) {
|
|
98
62
|
return {};
|
|
99
63
|
}
|
|
100
|
-
if (mode ===
|
|
101
|
-
return
|
|
102
|
-
|
|
64
|
+
if (mode === SelectStyle.Operator) {
|
|
65
|
+
return {
|
|
66
|
+
[(0, utils_1.selectExpression)(storeNames)](node) {
|
|
103
67
|
context.report({
|
|
104
68
|
node: node.callee.property,
|
|
105
|
-
messageId:
|
|
106
|
-
fix:
|
|
69
|
+
messageId: SelectStyle.Operator,
|
|
70
|
+
fix: (fixer) => getMethodToOperatorFixes(node, fixer),
|
|
107
71
|
});
|
|
108
72
|
},
|
|
109
|
-
|
|
73
|
+
};
|
|
110
74
|
}
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
var e_1, _a;
|
|
75
|
+
return {
|
|
76
|
+
[`Program:has(${(0, utils_1.pipeableSelect)(storeNames)}) ImportDeclaration[source.value='${utils_1.NGRX_MODULE_PATHS.store}'] > ImportSpecifier[imported.name='select']`](node) {
|
|
114
77
|
context.report({
|
|
115
|
-
node
|
|
116
|
-
messageId:
|
|
117
|
-
fix:
|
|
118
|
-
return (0, utils_1.getImportRemoveFix)(sourceCode, [node.parent], 'select', fixer);
|
|
119
|
-
},
|
|
78
|
+
node,
|
|
79
|
+
messageId: SelectStyle.Method,
|
|
80
|
+
fix: (fixer) => (0, utils_1.getImportRemoveFix)(sourceCode, [node.parent], 'select', fixer),
|
|
120
81
|
});
|
|
121
|
-
|
|
122
|
-
|
|
82
|
+
const [{ references }] = sourceCode.getDeclaredVariables(node);
|
|
83
|
+
for (const { identifier } of references) {
|
|
123
84
|
context.report({
|
|
124
85
|
node: identifier,
|
|
125
|
-
messageId:
|
|
126
|
-
fix:
|
|
127
|
-
return getOperatorToMethodFixes(identifier, sourceCode, fixer);
|
|
128
|
-
},
|
|
86
|
+
messageId: SelectStyle.Method,
|
|
87
|
+
fix: (fixer) => getOperatorToMethodFixes(identifier, sourceCode, fixer),
|
|
129
88
|
});
|
|
130
|
-
};
|
|
131
|
-
try {
|
|
132
|
-
for (var references_1 = __values(references), references_1_1 = references_1.next(); !references_1_1.done; references_1_1 = references_1.next()) {
|
|
133
|
-
var identifier = references_1_1.value.identifier;
|
|
134
|
-
_loop_1(identifier);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
138
|
-
finally {
|
|
139
|
-
try {
|
|
140
|
-
if (references_1_1 && !references_1_1.done && (_a = references_1.return)) _a.call(references_1);
|
|
141
|
-
}
|
|
142
|
-
finally { if (e_1) throw e_1.error; }
|
|
143
89
|
}
|
|
144
90
|
},
|
|
145
|
-
|
|
91
|
+
};
|
|
146
92
|
},
|
|
147
93
|
});
|
|
148
94
|
function getMethodToOperatorFixes(node, fixer) {
|
|
149
|
-
|
|
95
|
+
const classDeclaration = (0, utils_1.getNearestUpperNodeFrom)(node, utils_1.isClassDeclaration);
|
|
150
96
|
if (!classDeclaration) {
|
|
151
97
|
return [];
|
|
152
98
|
}
|
|
@@ -154,40 +100,39 @@ function getMethodToOperatorFixes(node, fixer) {
|
|
|
154
100
|
fixer.insertTextBefore(node.callee.property, 'pipe('),
|
|
155
101
|
fixer.insertTextAfter(node, ')'),
|
|
156
102
|
].concat((0, utils_1.getImportAddFix)({
|
|
157
|
-
fixer
|
|
103
|
+
fixer,
|
|
158
104
|
importName: 'select',
|
|
159
105
|
moduleName: utils_1.NGRX_MODULE_PATHS.store,
|
|
160
106
|
node: classDeclaration,
|
|
161
107
|
}));
|
|
162
108
|
}
|
|
163
109
|
function getOperatorToMethodFixes(identifier, sourceCode, fixer) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
var storePipe = select === null || select === void 0 ? void 0 : select.parent;
|
|
110
|
+
const select = identifier.parent;
|
|
111
|
+
const storePipe = select?.parent;
|
|
167
112
|
if (!storePipe ||
|
|
168
113
|
!(0, utils_1.isCallExpression)(storePipe) ||
|
|
169
114
|
!(0, utils_1.isMemberExpression)(storePipe.callee)) {
|
|
170
115
|
return [];
|
|
171
116
|
}
|
|
172
|
-
|
|
117
|
+
const pipeContainsOnlySelect = storePipe.arguments.length === 1;
|
|
173
118
|
if (!pipeContainsOnlySelect) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return
|
|
178
|
-
fixer.remove(select)
|
|
179
|
-
|
|
180
|
-
fixer.insertTextAfter(store,
|
|
181
|
-
]
|
|
119
|
+
const selectContent = sourceCode.getText(select);
|
|
120
|
+
const nextTokenAfterSelect = sourceCode.getTokenAfter(select);
|
|
121
|
+
const store = storePipe.callee.object;
|
|
122
|
+
return [
|
|
123
|
+
fixer.remove(select),
|
|
124
|
+
...(nextTokenAfterSelect ? [fixer.remove(nextTokenAfterSelect)] : []),
|
|
125
|
+
fixer.insertTextAfter(store, `.${selectContent}`),
|
|
126
|
+
];
|
|
182
127
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
128
|
+
const { property } = storePipe.callee;
|
|
129
|
+
const nextTokenAfterPipe = sourceCode.getTokenAfter(property);
|
|
130
|
+
const [pipeInitialRange, pipeEndRange] = property.range;
|
|
131
|
+
const pipeRange = [
|
|
187
132
|
pipeInitialRange,
|
|
188
|
-
|
|
133
|
+
nextTokenAfterPipe?.range[1] ?? pipeEndRange,
|
|
189
134
|
];
|
|
190
|
-
|
|
135
|
+
const [, selectEndRange] = identifier.range;
|
|
191
136
|
return [
|
|
192
137
|
fixer.removeRange(pipeRange),
|
|
193
138
|
fixer.insertTextAfterRange([selectEndRange, selectEndRange + 1], '('),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-style.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/select-style.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"select-style.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/select-style.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAA6B;AAC7B,qDAAgD;AAChD,uCAYqB;AAER,QAAA,YAAY,GAAG,cAAc,CAAC;AAC9B,QAAA,cAAc,GAAG,gBAAgB,CAAC;AAE/C,IAAkB,WAGjB;AAHD,WAAkB,WAAW;IAC3B,gCAAiB,CAAA;IACjB,oCAAqB,CAAA;AACvB,CAAC,EAHiB,WAAW,2BAAX,WAAW,QAG5B;AAmBD,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,kFAAkF;SACrF;QACD,OAAO,EAAE,MAAM;QACf,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC;aACjD;SACF;QACD,QAAQ,EAAE;YACR,CAAC,WAAW,CAAC,MAAM,CAAC,EAClB,4EAA4E;YAC9E,CAAC,WAAW,CAAC,QAAQ,CAAC,EACpB,0FAA0F;SAC7F;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,MAAM,sBAAsB,GAAG,SAAS,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,CAAC;IAEhE,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACjD,MAAM,oBAAoB,GAAG,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;QACtC,OAAO;YACL,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC;YACpB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,KAAK,CAAC,eAAe,CAAC,KAAK,EAAE,IAAI,aAAa,EAAE,CAAC;SAClD,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC;IACtC,MAAM,kBAAkB,GAAG,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC9D,MAAM,CAAC,gBAAgB,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC;IACxD,MAAM,SAAS,GAAmB;QAChC,gBAAgB;QAChB,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,YAAY;KAC7C,CAAC;IACF,MAAM,CAAC,EAAE,cAAc,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;IAC5C,OAAO;QACL,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC;QAC5B,KAAK,CAAC,oBAAoB,CAAC,CAAC,cAAc,EAAE,cAAc,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC;KACtE,CAAC;AACJ,CAAC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getImportAddFix,\n getImportRemoveFix,\n getNearestUpperNodeFrom,\n getNgRxStores,\n isCallExpression,\n isClassDeclaration,\n isMemberExpression,\n NGRX_MODULE_PATHS,\n pipeableSelect,\n selectExpression,\n} from '../../utils';\n\nexport const selectMethod = 'selectMethod';\nexport const selectOperator = 'selectOperator';\n\nexport const enum SelectStyle {\n Method = 'method',\n Operator = 'operator',\n}\n\ntype MessageIds = `${SelectStyle}`;\ntype Options = readonly [MessageIds];\ntype MemberExpressionWithProperty = Omit<\n TSESTree.MemberExpression,\n 'property'\n> & {\n property: TSESTree.Identifier;\n};\ntype CallExpression = Omit<TSESTree.CallExpression, 'parent'> & {\n callee: MemberExpressionWithProperty;\n parent: TSESTree.CallExpression & {\n callee: Omit<TSESTree.MemberExpression, 'object'> & {\n object: MemberExpressionWithProperty;\n };\n };\n};\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description:\n 'Selector can be used either with `select` as a pipeable operator or as a method.',\n },\n fixable: 'code',\n schema: [\n {\n type: 'string',\n enum: [SelectStyle.Method, SelectStyle.Operator],\n },\n ],\n messages: {\n [SelectStyle.Method]:\n 'Selector should be used with select method: `this.store.select(selector)`.',\n [SelectStyle.Operator]:\n 'Selector should be used with the pipeable operator: `this.store.pipe(select(selector))`.',\n },\n },\n defaultOptions: [SelectStyle.Method],\n create: (context, [mode]) => {\n const { identifiers = [], sourceCode } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n if (mode === SelectStyle.Operator) {\n return {\n [selectExpression(storeNames)](node: CallExpression) {\n context.report({\n node: node.callee.property,\n messageId: SelectStyle.Operator,\n fix: (fixer) => getMethodToOperatorFixes(node, fixer),\n });\n },\n };\n }\n\n return {\n [`Program:has(${pipeableSelect(\n storeNames\n )}) ImportDeclaration[source.value='${\n NGRX_MODULE_PATHS.store\n }'] > ImportSpecifier[imported.name='select']`](\n node: TSESTree.ImportSpecifier & {\n parent: TSESTree.ImportDeclaration;\n }\n ) {\n context.report({\n node,\n messageId: SelectStyle.Method,\n fix: (fixer) =>\n getImportRemoveFix(sourceCode, [node.parent], 'select', fixer),\n });\n\n const [{ references }] = sourceCode.getDeclaredVariables(node);\n\n for (const { identifier } of references) {\n context.report({\n node: identifier,\n messageId: SelectStyle.Method,\n fix: (fixer) =>\n getOperatorToMethodFixes(identifier, sourceCode, fixer),\n });\n }\n },\n };\n },\n});\n\nfunction getMethodToOperatorFixes(\n node: CallExpression,\n fixer: TSESLint.RuleFixer\n): readonly TSESLint.RuleFix[] {\n const classDeclaration = getNearestUpperNodeFrom(node, isClassDeclaration);\n\n if (!classDeclaration) {\n return [];\n }\n\n return [\n fixer.insertTextBefore(node.callee.property, 'pipe('),\n fixer.insertTextAfter(node, ')'),\n ].concat(\n getImportAddFix({\n fixer,\n importName: 'select',\n moduleName: NGRX_MODULE_PATHS.store,\n node: classDeclaration,\n })\n );\n}\n\nfunction getOperatorToMethodFixes(\n identifier: TSESTree.Node,\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer\n): readonly TSESLint.RuleFix[] {\n const select = identifier.parent;\n const storePipe = select?.parent;\n\n if (\n !storePipe ||\n !isCallExpression(storePipe) ||\n !isMemberExpression(storePipe.callee)\n ) {\n return [];\n }\n\n const pipeContainsOnlySelect = storePipe.arguments.length === 1;\n\n if (!pipeContainsOnlySelect) {\n const selectContent = sourceCode.getText(select);\n const nextTokenAfterSelect = sourceCode.getTokenAfter(select);\n const store = storePipe.callee.object;\n return [\n fixer.remove(select),\n ...(nextTokenAfterSelect ? [fixer.remove(nextTokenAfterSelect)] : []),\n fixer.insertTextAfter(store, `.${selectContent}`),\n ];\n }\n\n const { property } = storePipe.callee;\n const nextTokenAfterPipe = sourceCode.getTokenAfter(property);\n const [pipeInitialRange, pipeEndRange] = property.range;\n const pipeRange: TSESTree.Range = [\n pipeInitialRange,\n nextTokenAfterPipe?.range[1] ?? pipeEndRange,\n ];\n const [, selectEndRange] = identifier.range;\n return [\n fixer.removeRange(pipeRange),\n fixer.insertTextAfterRange([selectEndRange, selectEndRange + 1], '('),\n ];\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const useConsistentGlobalStoreName = "useConsistentGlobalStoreName";
|
|
2
|
+
export declare const useConsistentGlobalStoreNameSuggest = "useConsistentGlobalStoreNameSuggest";
|
|
3
|
+
type MessageIds = typeof useConsistentGlobalStoreName | typeof useConsistentGlobalStoreNameSuggest;
|
|
4
|
+
type Options = readonly [string];
|
|
5
|
+
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
|
6
|
+
export default _default;
|