@ngrx/eslint-plugin 14.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.js +22 -0
- package/jest.config.js.map +1 -0
- package/migrations/migration.json +3 -0
- package/package.json +51 -0
- package/schematics/collection.json +10 -0
- package/schematics/ng-add/index.js +51 -0
- package/schematics/ng-add/index.js.map +1 -0
- package/schematics/ng-add/schema.js +3 -0
- package/schematics/ng-add/schema.js.map +1 -0
- package/schematics/ng-add/schema.json +87 -0
- package/scripts/generate-config.js +85 -0
- package/scripts/generate-config.js.map +1 -0
- package/scripts/generate-docs.js +90 -0
- package/scripts/generate-docs.js.map +1 -0
- package/scripts/generate-overview.js +98 -0
- package/scripts/generate-overview.js.map +1 -0
- package/spec/utils/index.js +22 -0
- package/spec/utils/index.js.map +1 -0
- package/src/configs/all-requiring-type-checking.js +46 -0
- package/src/configs/all-requiring-type-checking.js.map +1 -0
- package/src/configs/all.js +39 -0
- package/src/configs/all.js.map +1 -0
- package/src/configs/component-store-strict.js +11 -0
- package/src/configs/component-store-strict.js.map +1 -0
- package/src/configs/component-store.js +11 -0
- package/src/configs/component-store.js.map +1 -0
- package/src/configs/effects-requiring-type-checking.js +27 -0
- package/src/configs/effects-requiring-type-checking.js.map +1 -0
- package/src/configs/effects-strict-requiring-type-checking.js +27 -0
- package/src/configs/effects-strict-requiring-type-checking.js.map +1 -0
- package/src/configs/effects-strict.js +20 -0
- package/src/configs/effects-strict.js.map +1 -0
- package/src/configs/effects.js +20 -0
- package/src/configs/effects.js.map +1 -0
- package/src/configs/index.js +33 -0
- package/src/configs/index.js.map +1 -0
- package/src/configs/recommended-requiring-type-checking.js +46 -0
- package/src/configs/recommended-requiring-type-checking.js.map +1 -0
- package/src/configs/recommended.js +39 -0
- package/src/configs/recommended.js.map +1 -0
- package/src/configs/store-strict.js +30 -0
- package/src/configs/store-strict.js.map +1 -0
- package/src/configs/store.js +30 -0
- package/src/configs/store.js.map +1 -0
- package/src/configs/strict-requiring-type-checking.js +46 -0
- package/src/configs/strict-requiring-type-checking.js.map +1 -0
- package/src/configs/strict.js +39 -0
- package/src/configs/strict.js.map +1 -0
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/src/rule-creator.js +29 -0
- package/src/rule-creator.js.map +1 -0
- package/src/rules/component-store/updater-explicit-return-type.js +69 -0
- package/src/rules/component-store/updater-explicit-return-type.js.map +1 -0
- package/src/rules/effects/avoid-cyclic-effects.js +202 -0
- package/src/rules/effects/avoid-cyclic-effects.js.map +1 -0
- package/src/rules/effects/no-dispatch-in-effects.js +83 -0
- package/src/rules/effects/no-dispatch-in-effects.js.map +1 -0
- package/src/rules/effects/no-effect-decorator-and-creator.js +107 -0
- package/src/rules/effects/no-effect-decorator-and-creator.js.map +1 -0
- package/src/rules/effects/no-effect-decorator.js +124 -0
- package/src/rules/effects/no-effect-decorator.js.map +1 -0
- package/src/rules/effects/no-effects-in-providers.js +105 -0
- package/src/rules/effects/no-effects-in-providers.js.map +1 -0
- package/src/rules/effects/no-multiple-actions-in-effects.js +77 -0
- package/src/rules/effects/no-multiple-actions-in-effects.js.map +1 -0
- package/src/rules/effects/prefer-action-creator-in-of-type.js +58 -0
- package/src/rules/effects/prefer-action-creator-in-of-type.js.map +1 -0
- package/src/rules/effects/prefer-concat-latest-from.js +153 -0
- package/src/rules/effects/prefer-concat-latest-from.js.map +1 -0
- package/src/rules/effects/prefer-effect-callback-in-block-statement.js +99 -0
- package/src/rules/effects/prefer-effect-callback-in-block-statement.js.map +1 -0
- package/src/rules/effects/use-effects-lifecycle-interface.js +88 -0
- package/src/rules/effects/use-effects-lifecycle-interface.js.map +1 -0
- package/src/rules/index.js +59 -0
- package/src/rules/index.js.map +1 -0
- package/src/rules/store/avoid-combining-selectors.js +65 -0
- package/src/rules/store/avoid-combining-selectors.js.map +1 -0
- package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js +95 -0
- package/src/rules/store/avoid-dispatching-multiple-actions-sequentially.js.map +1 -0
- package/src/rules/store/avoid-duplicate-actions-in-reducer.js +150 -0
- package/src/rules/store/avoid-duplicate-actions-in-reducer.js.map +1 -0
- package/src/rules/store/avoid-mapping-selectors.js +82 -0
- package/src/rules/store/avoid-mapping-selectors.js.map +1 -0
- package/src/rules/store/good-action-hygiene.js +84 -0
- package/src/rules/store/good-action-hygiene.js.map +1 -0
- package/src/rules/store/no-multiple-global-stores.js +157 -0
- package/src/rules/store/no-multiple-global-stores.js.map +1 -0
- package/src/rules/store/no-reducer-in-key-names.js +76 -0
- package/src/rules/store/no-reducer-in-key-names.js.map +1 -0
- package/src/rules/store/no-store-subscription.js +64 -0
- package/src/rules/store/no-store-subscription.js.map +1 -0
- package/src/rules/store/no-typed-global-store.js +101 -0
- package/src/rules/store/no-typed-global-store.js.map +1 -0
- package/src/rules/store/on-function-explicit-return-type.js +106 -0
- package/src/rules/store/on-function-explicit-return-type.js.map +1 -0
- package/src/rules/store/prefer-action-creator-in-dispatch.js +70 -0
- package/src/rules/store/prefer-action-creator-in-dispatch.js.map +1 -0
- package/src/rules/store/prefer-action-creator.js +58 -0
- package/src/rules/store/prefer-action-creator.js.map +1 -0
- package/src/rules/store/prefer-inline-action-props.js +72 -0
- package/src/rules/store/prefer-inline-action-props.js.map +1 -0
- package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js +93 -0
- package/src/rules/store/prefer-one-generic-in-create-for-feature-selector.js.map +1 -0
- package/src/rules/store/prefer-selector-in-select.js +93 -0
- package/src/rules/store/prefer-selector-in-select.js.map +1 -0
- package/src/rules/store/prefix-selectors-with-select.js +107 -0
- package/src/rules/store/prefix-selectors-with-select.js.map +1 -0
- package/src/rules/store/select-style.js +196 -0
- package/src/rules/store/select-style.js.map +1 -0
- package/src/rules/store/use-consistent-global-store-name.js +139 -0
- package/src/rules/store/use-consistent-global-store-name.js.map +1 -0
- package/src/utils/helper-functions/docs.js +8 -0
- package/src/utils/helper-functions/docs.js.map +1 -0
- package/src/utils/helper-functions/folder.js +118 -0
- package/src/utils/helper-functions/folder.js.map +1 -0
- package/src/utils/helper-functions/guards.js +56 -0
- package/src/utils/helper-functions/guards.js.map +1 -0
- package/src/utils/helper-functions/index.js +23 -0
- package/src/utils/helper-functions/index.js.map +1 -0
- package/src/utils/helper-functions/ngrx-modules.js +10 -0
- package/src/utils/helper-functions/ngrx-modules.js.map +1 -0
- package/src/utils/helper-functions/utils.js +302 -0
- package/src/utils/helper-functions/utils.js.map +1 -0
- package/src/utils/helper-functions/versions.js +70 -0
- package/src/utils/helper-functions/versions.js.map +1 -0
- package/src/utils/index.js +19 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/selectors/index.js +58 -0
- package/src/utils/selectors/index.js.map +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
+
if (!m) return o;
|
|
28
|
+
var i = m.call(o), r, ar = [], e;
|
|
29
|
+
try {
|
|
30
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
+
}
|
|
32
|
+
catch (error) { e = { error: error }; }
|
|
33
|
+
finally {
|
|
34
|
+
try {
|
|
35
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
+
}
|
|
37
|
+
finally { if (e) throw e.error; }
|
|
38
|
+
}
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
var _a;
|
|
42
|
+
exports.__esModule = true;
|
|
43
|
+
exports.onFunctionExplicitReturnTypeSuggest = exports.onFunctionExplicitReturnType = void 0;
|
|
44
|
+
var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
|
45
|
+
var path = __importStar(require("path"));
|
|
46
|
+
var rule_creator_1 = require("../../rule-creator");
|
|
47
|
+
var utils_1 = require("../../utils");
|
|
48
|
+
exports.onFunctionExplicitReturnType = 'onFunctionExplicitReturnType';
|
|
49
|
+
exports.onFunctionExplicitReturnTypeSuggest = 'onFunctionExplicitReturnTypeSuggest';
|
|
50
|
+
exports["default"] = (0, rule_creator_1.createRule)({
|
|
51
|
+
name: path.parse(__filename).name,
|
|
52
|
+
meta: {
|
|
53
|
+
type: 'suggestion',
|
|
54
|
+
hasSuggestions: true,
|
|
55
|
+
ngrxModule: 'store',
|
|
56
|
+
docs: {
|
|
57
|
+
description: '`On` function should have an explicit return type.',
|
|
58
|
+
recommended: 'warn',
|
|
59
|
+
suggestion: true
|
|
60
|
+
},
|
|
61
|
+
schema: [],
|
|
62
|
+
messages: (_a = {},
|
|
63
|
+
_a[exports.onFunctionExplicitReturnType] = '`On` functions should have an explicit return type when using arrow functions: `on(action, (state): State => {}`.',
|
|
64
|
+
_a[exports.onFunctionExplicitReturnTypeSuggest] = 'Add the explicit return type `State` (if the interface/type is named differently you need to manually correct the return type).',
|
|
65
|
+
_a)
|
|
66
|
+
},
|
|
67
|
+
defaultOptions: [],
|
|
68
|
+
create: function (context) {
|
|
69
|
+
var _a;
|
|
70
|
+
var sourceCode = context.getSourceCode();
|
|
71
|
+
return _a = {},
|
|
72
|
+
_a[utils_1.onFunctionWithoutType] = function (node) {
|
|
73
|
+
context.report({
|
|
74
|
+
node: node,
|
|
75
|
+
messageId: exports.onFunctionExplicitReturnType,
|
|
76
|
+
suggest: [
|
|
77
|
+
{
|
|
78
|
+
messageId: exports.onFunctionExplicitReturnTypeSuggest,
|
|
79
|
+
fix: function (fixer) { return getFixes(node, sourceCode, fixer); }
|
|
80
|
+
},
|
|
81
|
+
]
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
_a;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
function getFixes(node, sourceCode, fixer) {
|
|
88
|
+
var params = node.params;
|
|
89
|
+
if (params.length === 0) {
|
|
90
|
+
var _a = __read(sourceCode.getTokens(node), 2), closingParen = _a[1];
|
|
91
|
+
return fixer.insertTextAfter(closingParen, ': State');
|
|
92
|
+
}
|
|
93
|
+
var _b = __read(params, 1), firstParam = _b[0];
|
|
94
|
+
var lastParam = (0, utils_1.getLast)(params);
|
|
95
|
+
var previousToken = sourceCode.getTokenBefore(firstParam);
|
|
96
|
+
var isParenthesized = previousToken && experimental_utils_1.ASTUtils.isOpeningParenToken(previousToken);
|
|
97
|
+
if (isParenthesized) {
|
|
98
|
+
var nextToken = sourceCode.getTokenAfter(lastParam);
|
|
99
|
+
return fixer.insertTextAfter(nextToken !== null && nextToken !== void 0 ? nextToken : lastParam, ': State');
|
|
100
|
+
}
|
|
101
|
+
return [
|
|
102
|
+
fixer.insertTextBefore(firstParam, '('),
|
|
103
|
+
fixer.insertTextAfter(lastParam, '): State'),
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=on-function-explicit-return-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"on-function-explicit-return-type.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/on-function-explicit-return-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAiE;AACjE,yCAA6B;AAC7B,mDAAgD;AAChD,qCAA6D;AAEhD,QAAA,4BAA4B,GAAG,8BAA8B,CAAC;AAC9D,QAAA,mCAAmC,GAC9C,qCAAqC,CAAC;AAOxC,qBAAe,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,oDAAoD;YACjE,WAAW,EAAE,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,oCAA4B,IAC3B,mHAAmH;YACrH,GAAC,2CAAmC,IAClC,iIAAiI;eACpI;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACd,IAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAE3C;YACE,GAAC,6BAAqB,IAAtB,UAAwB,IAAsC;gBAC5D,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,MAAA;oBACJ,SAAS,EAAE,oCAA4B;oBACvC,OAAO,EAAE;wBACP;4BACE,SAAS,EAAE,2CAAmC;4BAC9C,GAAG,EAAE,UAAC,KAAK,IAAK,OAAA,QAAQ,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,EAAjC,CAAiC;yBAClD;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,QAAQ,CACf,IAAsC,EACtC,UAAyC,EACzC,KAAyB;IAEjB,IAAA,MAAM,GAAK,IAAI,OAAT,CAAU;IAExB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACjB,IAAA,KAAA,OAAmB,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,IAAA,EAA1C,YAAY,QAA8B,CAAC;QACpD,OAAO,KAAK,CAAC,eAAe,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;KACvD;IAEK,IAAA,KAAA,OAAe,MAAM,IAAA,EAApB,UAAU,QAAU,CAAC;IAC5B,IAAM,SAAS,GAAG,IAAA,eAAO,EAAC,MAAM,CAAC,CAAC;IAClC,IAAM,aAAa,GAAG,UAAU,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;IAC5D,IAAM,eAAe,GACnB,aAAa,IAAI,6BAAQ,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAE/D,IAAI,eAAe,EAAE;QACnB,IAAM,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACtD,OAAO,KAAK,CAAC,eAAe,CAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,SAAS,EAAE,SAAS,CAAC,CAAC;KACjE;IAED,OAAO;QACL,KAAK,CAAC,gBAAgB,CAAC,UAAU,EAAE,GAAG,CAAC;QACvC,KAAK,CAAC,eAAe,CAAC,SAAS,EAAE,UAAU,CAAC;KACpC,CAAC;AACb,CAAC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ASTUtils } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { getLast, onFunctionWithoutType } from '../../utils';\n\nexport const onFunctionExplicitReturnType = 'onFunctionExplicitReturnType';\nexport const onFunctionExplicitReturnTypeSuggest =\n 'onFunctionExplicitReturnTypeSuggest';\n\ntype MessageIds =\n | typeof onFunctionExplicitReturnType\n | typeof onFunctionExplicitReturnTypeSuggest;\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: '`On` function should have an explicit return type.',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [],\n messages: {\n [onFunctionExplicitReturnType]:\n '`On` functions should have an explicit return type when using arrow functions: `on(action, (state): State => {}`.',\n [onFunctionExplicitReturnTypeSuggest]:\n 'Add the explicit return type `State` (if the interface/type is named differently you need to manually correct the return type).',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const sourceCode = context.getSourceCode();\n\n return {\n [onFunctionWithoutType](node: TSESTree.ArrowFunctionExpression) {\n context.report({\n node,\n messageId: onFunctionExplicitReturnType,\n suggest: [\n {\n messageId: onFunctionExplicitReturnTypeSuggest,\n fix: (fixer) => getFixes(node, sourceCode, fixer),\n },\n ],\n });\n },\n };\n },\n});\n\nfunction getFixes(\n node: TSESTree.ArrowFunctionExpression,\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer\n) {\n const { params } = node;\n\n if (params.length === 0) {\n const [, closingParen] = sourceCode.getTokens(node);\n return fixer.insertTextAfter(closingParen, ': State');\n }\n\n const [firstParam] = params;\n const lastParam = getLast(params);\n const previousToken = sourceCode.getTokenBefore(firstParam);\n const isParenthesized =\n previousToken && ASTUtils.isOpeningParenToken(previousToken);\n\n if (isParenthesized) {\n const nextToken = sourceCode.getTokenAfter(lastParam);\n return fixer.insertTextAfter(nextToken ?? lastParam, ': State');\n }\n\n return [\n fixer.insertTextBefore(firstParam, '('),\n fixer.insertTextAfter(lastParam, '): State'),\n ] as const;\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var _a;
|
|
26
|
+
exports.__esModule = true;
|
|
27
|
+
exports.messageId = void 0;
|
|
28
|
+
var path = __importStar(require("path"));
|
|
29
|
+
var rule_creator_1 = require("../../rule-creator");
|
|
30
|
+
var utils_1 = require("../../utils");
|
|
31
|
+
exports.messageId = 'preferActionCreatorInDispatch';
|
|
32
|
+
exports["default"] = (0, rule_creator_1.createRule)({
|
|
33
|
+
name: path.parse(__filename).name,
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'suggestion',
|
|
36
|
+
ngrxModule: 'store',
|
|
37
|
+
docs: {
|
|
38
|
+
description: 'Using `action creator` in `dispatch` is preferred over `object` or old `Action`.',
|
|
39
|
+
recommended: 'warn'
|
|
40
|
+
},
|
|
41
|
+
schema: [],
|
|
42
|
+
messages: (_a = {},
|
|
43
|
+
_a[exports.messageId] = 'Using `object` or old `Action` is forbidden. Use `action creator` instead.',
|
|
44
|
+
_a)
|
|
45
|
+
},
|
|
46
|
+
defaultOptions: [],
|
|
47
|
+
create: function (context) {
|
|
48
|
+
var _a;
|
|
49
|
+
var _b = (0, utils_1.getNgRxStores)(context).identifiers, identifiers = _b === void 0 ? [] : _b;
|
|
50
|
+
var storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
|
|
51
|
+
if (!storeNames) {
|
|
52
|
+
return {};
|
|
53
|
+
}
|
|
54
|
+
return _a = {},
|
|
55
|
+
_a["".concat((0, utils_1.dispatchExpression)(storeNames), " :matches(NewExpression, :not(NewExpression) > ObjectExpression)")] = function (node) {
|
|
56
|
+
var nearestUpperCallExpression = (0, utils_1.getNearestUpperNodeFrom)(node, utils_1.isCallExpression);
|
|
57
|
+
var isStoreDispatchImmediateParent = nearestUpperCallExpression !== undefined &&
|
|
58
|
+
(0, utils_1.isCallExpressionWith)(nearestUpperCallExpression, storeNames, 'dispatch');
|
|
59
|
+
if (!isStoreDispatchImmediateParent) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
context.report({
|
|
63
|
+
node: node,
|
|
64
|
+
messageId: exports.messageId
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
_a;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
//# sourceMappingURL=prefer-action-creator-in-dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-action-creator-in-dispatch.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-action-creator-in-dispatch.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAOqB;AAER,QAAA,SAAS,GAAG,+BAA+B,CAAC;AAKzD,qBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,kFAAkF;YACpF,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IACR,4EAA4E;eAC/E;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACN,IAAA,KAAqB,IAAA,qBAAa,EAAC,OAAO,CAAC,YAA3B,EAAhB,WAAW,mBAAG,EAAE,KAAA,CAA4B;QACpD,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,EAAE,CAAC;SACX;QAED;YACE,GAAC,UAAG,IAAA,0BAAkB,EACpB,UAAU,CACX,qEAAkE,IAFnE,UAGE,IAAwD;gBAExD,IAAM,0BAA0B,GAAG,IAAA,+BAAuB,EACxD,IAAI,EACJ,wBAAgB,CACjB,CAAC;gBACF,IAAM,8BAA8B,GAClC,0BAA0B,KAAK,SAAS;oBACxC,IAAA,4BAAoB,EAClB,0BAA0B,EAC1B,UAAU,EACV,UAAU,CACX,CAAC;gBAEJ,IAAI,CAAC,8BAA8B,EAAE;oBACnC,OAAO;iBACR;gBAED,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,MAAA;oBACJ,SAAS,mBAAA;iBACV,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n dispatchExpression,\n getNearestUpperNodeFrom,\n getNgRxStores,\n isCallExpression,\n isCallExpressionWith,\n} from '../../utils';\n\nexport const messageId = 'preferActionCreatorInDispatch';\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 `action creator` in `dispatch` is preferred over `object` or old `Action`.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Using `object` or old `Action` is forbidden. Use `action creator` 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 [`${dispatchExpression(\n storeNames\n )} :matches(NewExpression, :not(NewExpression) > ObjectExpression)`](\n node: TSESTree.NewExpression | TSESTree.ObjectExpression\n ) {\n const nearestUpperCallExpression = getNearestUpperNodeFrom(\n node,\n isCallExpression\n );\n const isStoreDispatchImmediateParent =\n nearestUpperCallExpression !== undefined &&\n isCallExpressionWith(\n nearestUpperCallExpression,\n storeNames,\n 'dispatch'\n );\n\n if (!isStoreDispatchImmediateParent) {\n return;\n }\n\n context.report({\n node,\n messageId,\n });\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var _a;
|
|
26
|
+
exports.__esModule = true;
|
|
27
|
+
exports.messageId = void 0;
|
|
28
|
+
var path = __importStar(require("path"));
|
|
29
|
+
var rule_creator_1 = require("../../rule-creator");
|
|
30
|
+
exports.messageId = 'preferActionCreator';
|
|
31
|
+
exports["default"] = (0, rule_creator_1.createRule)({
|
|
32
|
+
name: path.parse(__filename).name,
|
|
33
|
+
meta: {
|
|
34
|
+
type: 'suggestion',
|
|
35
|
+
ngrxModule: 'store',
|
|
36
|
+
docs: {
|
|
37
|
+
description: 'Using `action creator` is preferred over `Action class`.',
|
|
38
|
+
recommended: 'warn'
|
|
39
|
+
},
|
|
40
|
+
schema: [],
|
|
41
|
+
messages: (_a = {},
|
|
42
|
+
_a[exports.messageId] = 'Using `Action class` is forbidden. Use `action creator` instead.',
|
|
43
|
+
_a)
|
|
44
|
+
},
|
|
45
|
+
defaultOptions: [],
|
|
46
|
+
create: function (context) {
|
|
47
|
+
var _a;
|
|
48
|
+
return _a = {},
|
|
49
|
+
_a["ClassDeclaration:has(TSClassImplements:matches([expression.name='Action'], [expression.property.name='Action'])):has(PropertyDefinition[key.name='type'])"] = function (node) {
|
|
50
|
+
context.report({
|
|
51
|
+
node: node,
|
|
52
|
+
messageId: exports.messageId
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
_a;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=prefer-action-creator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-action-creator.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-action-creator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAEnC,QAAA,SAAS,GAAG,qBAAqB,CAAC;AAK/C,qBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EAAE,0DAA0D;YACvE,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IACR,kEAAkE;eACrE;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACd;YACE,GAAC,2JAA2J,IAA5J,UACE,IAA+B;gBAE/B,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,MAAA;oBACJ,SAAS,mBAAA;iBACV,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\n\nexport const messageId = 'preferActionCreator';\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: 'Using `action creator` is preferred over `Action class`.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Using `Action class` is forbidden. Use `action creator` instead.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n [`ClassDeclaration:has(TSClassImplements:matches([expression.name='Action'], [expression.property.name='Action'])):has(PropertyDefinition[key.name='type'])`](\n node: TSESTree.ClassDeclaration\n ) {\n context.report({\n node,\n messageId,\n });\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var _a;
|
|
26
|
+
exports.__esModule = true;
|
|
27
|
+
exports.preferInlineActionPropsSuggest = exports.preferInlineActionProps = void 0;
|
|
28
|
+
var path = __importStar(require("path"));
|
|
29
|
+
var rule_creator_1 = require("../../rule-creator");
|
|
30
|
+
var utils_1 = require("../../utils");
|
|
31
|
+
exports.preferInlineActionProps = 'preferInlineActionProps';
|
|
32
|
+
exports.preferInlineActionPropsSuggest = 'preferInlineActionPropsSuggest';
|
|
33
|
+
exports["default"] = (0, rule_creator_1.createRule)({
|
|
34
|
+
name: path.parse(__filename).name,
|
|
35
|
+
meta: {
|
|
36
|
+
type: 'suggestion',
|
|
37
|
+
hasSuggestions: true,
|
|
38
|
+
ngrxModule: 'store',
|
|
39
|
+
docs: {
|
|
40
|
+
description: 'Prefer using inline types instead of interfaces, types or classes.',
|
|
41
|
+
recommended: 'warn',
|
|
42
|
+
suggestion: true
|
|
43
|
+
},
|
|
44
|
+
schema: [],
|
|
45
|
+
messages: (_a = {},
|
|
46
|
+
_a[exports.preferInlineActionProps] = 'Use inline types instead of interfaces, types or classes.',
|
|
47
|
+
_a[exports.preferInlineActionPropsSuggest] = 'Change to inline types.',
|
|
48
|
+
_a)
|
|
49
|
+
},
|
|
50
|
+
defaultOptions: [],
|
|
51
|
+
create: function (context) {
|
|
52
|
+
var _a;
|
|
53
|
+
return _a = {},
|
|
54
|
+
_a[utils_1.actionCreatorPropsComputed] = function (node) {
|
|
55
|
+
context.report({
|
|
56
|
+
node: node,
|
|
57
|
+
messageId: exports.preferInlineActionProps,
|
|
58
|
+
suggest: [
|
|
59
|
+
{
|
|
60
|
+
messageId: exports.preferInlineActionPropsSuggest,
|
|
61
|
+
fix: function (fixer) { return [
|
|
62
|
+
fixer.insertTextBefore(node, '{name: '),
|
|
63
|
+
fixer.insertTextAfter(node, '}'),
|
|
64
|
+
]; }
|
|
65
|
+
},
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
_a;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=prefer-inline-action-props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-inline-action-props.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-inline-action-props.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAAyD;AAE5C,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AACpD,QAAA,8BAA8B,GAAG,gCAAgC,CAAC;AAO/E,qBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,oEAAoE;YACtE,WAAW,EAAE,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,+BAAuB,IACtB,2DAA2D;YAC7D,GAAC,sCAA8B,IAAG,yBAAyB;eAC5D;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACd;YACE,GAAC,kCAA0B,IAA3B,UAA6B,IAA8B;gBACzD,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,MAAA;oBACJ,SAAS,EAAE,+BAAuB;oBAClC,OAAO,EAAE;wBACP;4BACE,SAAS,EAAE,sCAA8B;4BACzC,GAAG,EAAE,UAAC,KAAK,IAAK,OAAA;gCACd,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,SAAS,CAAC;gCACvC,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC;6BACjC,EAHe,CAGf;yBACF;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { actionCreatorPropsComputed } from '../../utils';\n\nexport const preferInlineActionProps = 'preferInlineActionProps';\nexport const preferInlineActionPropsSuggest = 'preferInlineActionPropsSuggest';\n\ntype MessageIds =\n | typeof preferInlineActionProps\n | typeof preferInlineActionPropsSuggest;\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 'Prefer using inline types instead of interfaces, types or classes.',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [],\n messages: {\n [preferInlineActionProps]:\n 'Use inline types instead of interfaces, types or classes.',\n [preferInlineActionPropsSuggest]: 'Change to inline types.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n [actionCreatorPropsComputed](node: TSESTree.TSTypeReference) {\n context.report({\n node,\n messageId: preferInlineActionProps,\n suggest: [\n {\n messageId: preferInlineActionPropsSuggest,\n fix: (fixer) => [\n fixer.insertTextBefore(node, '{name: '),\n fixer.insertTextAfter(node, '}'),\n ],\n },\n ],\n });\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
26
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
27
|
+
if (!m) return o;
|
|
28
|
+
var i = m.call(o), r, ar = [], e;
|
|
29
|
+
try {
|
|
30
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
31
|
+
}
|
|
32
|
+
catch (error) { e = { error: error }; }
|
|
33
|
+
finally {
|
|
34
|
+
try {
|
|
35
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
36
|
+
}
|
|
37
|
+
finally { if (e) throw e.error; }
|
|
38
|
+
}
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
var _a;
|
|
42
|
+
exports.__esModule = true;
|
|
43
|
+
exports.preferOneGenericInCreateForFeatureSelectorSuggest = exports.preferOneGenericInCreateForFeatureSelector = void 0;
|
|
44
|
+
var path = __importStar(require("path"));
|
|
45
|
+
var rule_creator_1 = require("../../rule-creator");
|
|
46
|
+
exports.preferOneGenericInCreateForFeatureSelector = 'preferOneGenericInCreateForFeatureSelector';
|
|
47
|
+
exports.preferOneGenericInCreateForFeatureSelectorSuggest = 'preferOneGenericInCreateForFeatureSelectorSuggest';
|
|
48
|
+
exports["default"] = (0, rule_creator_1.createRule)({
|
|
49
|
+
name: path.parse(__filename).name,
|
|
50
|
+
meta: {
|
|
51
|
+
type: 'suggestion',
|
|
52
|
+
hasSuggestions: true,
|
|
53
|
+
ngrxModule: 'store',
|
|
54
|
+
docs: {
|
|
55
|
+
description: 'Prefer using a single generic to define the feature state.',
|
|
56
|
+
recommended: 'warn',
|
|
57
|
+
suggestion: true
|
|
58
|
+
},
|
|
59
|
+
schema: [],
|
|
60
|
+
messages: (_a = {},
|
|
61
|
+
_a[exports.preferOneGenericInCreateForFeatureSelector] = 'Use a single generic to define the feature state.',
|
|
62
|
+
_a[exports.preferOneGenericInCreateForFeatureSelectorSuggest] = 'Remove the global state generic.',
|
|
63
|
+
_a)
|
|
64
|
+
},
|
|
65
|
+
defaultOptions: [],
|
|
66
|
+
create: function (context) {
|
|
67
|
+
var _a;
|
|
68
|
+
var sourceCode = context.getSourceCode();
|
|
69
|
+
return _a = {},
|
|
70
|
+
_a["CallExpression[callee.name='createFeatureSelector'] > TSTypeParameterInstantiation[params.length>1]"] = function (node) {
|
|
71
|
+
context.report({
|
|
72
|
+
node: node,
|
|
73
|
+
messageId: exports.preferOneGenericInCreateForFeatureSelector,
|
|
74
|
+
suggest: [
|
|
75
|
+
{
|
|
76
|
+
messageId: exports.preferOneGenericInCreateForFeatureSelectorSuggest,
|
|
77
|
+
fix: function (fixer) {
|
|
78
|
+
var _a;
|
|
79
|
+
var _b = __read(node.params, 1), globalState = _b[0];
|
|
80
|
+
var nextToken = sourceCode.getTokenAfter(globalState);
|
|
81
|
+
return fixer.removeRange([
|
|
82
|
+
globalState.range[0],
|
|
83
|
+
(_a = nextToken === null || nextToken === void 0 ? void 0 : nextToken.range[1]) !== null && _a !== void 0 ? _a : globalState.range[1] + 1,
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
_a;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=prefer-one-generic-in-create-for-feature-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-one-generic-in-create-for-feature-selector.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-one-generic-in-create-for-feature-selector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAEnC,QAAA,0CAA0C,GACrD,4CAA4C,CAAC;AAClC,QAAA,iDAAiD,GAC5D,mDAAmD,CAAC;AAOtD,qBAAe,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,4DAA4D;YACzE,WAAW,EAAE,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,kDAA0C,IACzC,mDAAmD;YACrD,GAAC,yDAAiD,IAChD,kCAAkC;eACrC;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACd,IAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;QAE3C;YACE,GAAC,qGAAqG,IAAtG,UACE,IAA2C;gBAE3C,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI,MAAA;oBACJ,SAAS,EAAE,kDAA0C;oBACrD,OAAO,EAAE;wBACP;4BACE,SAAS,EAAE,yDAAiD;4BAC5D,GAAG,EAAE,UAAC,KAAK;;gCACH,IAAA,KAAA,OAAgB,IAAI,CAAC,MAAM,IAAA,EAA1B,WAAW,QAAe,CAAC;gCAClC,IAAM,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;gCACxD,OAAO,KAAK,CAAC,WAAW,CAAC;oCACvB,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;oCACpB,MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,KAAK,CAAC,CAAC,CAAC,mCAAI,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;iCAChD,CAAC,CAAC;4BACL,CAAC;yBACF;qBACF;iBACF,CAAC,CAAC;YACL,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\n\nexport const preferOneGenericInCreateForFeatureSelector =\n 'preferOneGenericInCreateForFeatureSelector';\nexport const preferOneGenericInCreateForFeatureSelectorSuggest =\n 'preferOneGenericInCreateForFeatureSelectorSuggest';\n\ntype MessageIds =\n | typeof preferOneGenericInCreateForFeatureSelector\n | typeof preferOneGenericInCreateForFeatureSelectorSuggest;\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: 'Prefer using a single generic to define the feature state.',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [],\n messages: {\n [preferOneGenericInCreateForFeatureSelector]:\n 'Use a single generic to define the feature state.',\n [preferOneGenericInCreateForFeatureSelectorSuggest]:\n 'Remove the global state generic.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const sourceCode = context.getSourceCode();\n\n return {\n [`CallExpression[callee.name='createFeatureSelector'] > TSTypeParameterInstantiation[params.length>1]`](\n node: TSESTree.TSTypeParameterInstantiation\n ) {\n context.report({\n node,\n messageId: preferOneGenericInCreateForFeatureSelector,\n suggest: [\n {\n messageId: preferOneGenericInCreateForFeatureSelectorSuggest,\n fix: (fixer) => {\n const [globalState] = node.params;\n const nextToken = sourceCode.getTokenAfter(globalState);\n return fixer.removeRange([\n globalState.range[0],\n nextToken?.range[1] ?? globalState.range[1] + 1,\n ]);\n },\n },\n ],\n });\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __values = (this && this.__values) || function(o) {
|
|
26
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
27
|
+
if (m) return m.call(o);
|
|
28
|
+
if (o && typeof o.length === "number") return {
|
|
29
|
+
next: function () {
|
|
30
|
+
if (o && i >= o.length) o = void 0;
|
|
31
|
+
return { value: o && o[i++], done: !o };
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
35
|
+
};
|
|
36
|
+
var _a;
|
|
37
|
+
exports.__esModule = true;
|
|
38
|
+
exports.messageId = void 0;
|
|
39
|
+
var path = __importStar(require("path"));
|
|
40
|
+
var rule_creator_1 = require("../../rule-creator");
|
|
41
|
+
var utils_1 = require("../../utils");
|
|
42
|
+
exports.messageId = 'preferSelectorInSelect';
|
|
43
|
+
exports["default"] = (0, rule_creator_1.createRule)({
|
|
44
|
+
name: path.parse(__filename).name,
|
|
45
|
+
meta: {
|
|
46
|
+
type: 'suggestion',
|
|
47
|
+
ngrxModule: 'store',
|
|
48
|
+
docs: {
|
|
49
|
+
description: 'Using a selector in the `select` is preferred over `string` or `props drilling`.',
|
|
50
|
+
recommended: 'warn'
|
|
51
|
+
},
|
|
52
|
+
schema: [],
|
|
53
|
+
messages: (_a = {},
|
|
54
|
+
_a[exports.messageId] = 'Using `string` or `props drilling` is forbidden. Use a selector instead.',
|
|
55
|
+
_a)
|
|
56
|
+
},
|
|
57
|
+
defaultOptions: [],
|
|
58
|
+
create: function (context) {
|
|
59
|
+
var _a;
|
|
60
|
+
var _b = (0, utils_1.getNgRxStores)(context).identifiers, identifiers = _b === void 0 ? [] : _b;
|
|
61
|
+
var storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
|
|
62
|
+
if (!storeNames) {
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
return _a = {},
|
|
66
|
+
_a["".concat((0, utils_1.pipeableSelect)(storeNames), ", ").concat((0, utils_1.selectExpression)(storeNames))] = function (node) {
|
|
67
|
+
var e_1, _a;
|
|
68
|
+
try {
|
|
69
|
+
for (var _b = __values(node.arguments), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
70
|
+
var argument = _c.value;
|
|
71
|
+
if (!(0, utils_1.isLiteral)(argument) &&
|
|
72
|
+
!(0, utils_1.isArrowFunctionExpression)(argument) &&
|
|
73
|
+
!(0, utils_1.isFunctionExpression)(argument)) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
context.report({
|
|
77
|
+
node: argument,
|
|
78
|
+
messageId: exports.messageId
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
83
|
+
finally {
|
|
84
|
+
try {
|
|
85
|
+
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
|
|
86
|
+
}
|
|
87
|
+
finally { if (e_1) throw e_1.error; }
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
_a;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=prefer-selector-in-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefer-selector-in-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefer-selector-in-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAQqB;AAER,QAAA,SAAS,GAAG,wBAAwB,CAAC;AAKlD,qBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,kFAAkF;YACpF,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IACR,0EAA0E;eAC7E;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACN,IAAA,KAAqB,IAAA,qBAAa,EAAC,OAAO,CAAC,YAA3B,EAAhB,WAAW,mBAAG,EAAE,KAAA,CAA4B;QACpD,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1E,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,EAAE,CAAC;SACX;QAED;YACE,GAAC,UAAG,IAAA,sBAAc,EAAC,UAAU,CAAC,eAAK,IAAA,wBAAgB,EAAC,UAAU,CAAC,CAAE,IAAjE,UACE,IAA6B;;;oBAE7B,KAAuB,IAAA,KAAA,SAAA,IAAI,CAAC,SAAS,CAAA,gBAAA,4BAAE;wBAAlC,IAAM,QAAQ,WAAA;wBACjB,IACE,CAAC,IAAA,iBAAS,EAAC,QAAQ,CAAC;4BACpB,CAAC,IAAA,iCAAyB,EAAC,QAAQ,CAAC;4BACpC,CAAC,IAAA,4BAAoB,EAAC,QAAQ,CAAC,EAC/B;4BACA,MAAM;yBACP;wBAED,OAAO,CAAC,MAAM,CAAC;4BACb,IAAI,EAAE,QAAQ;4BACd,SAAS,mBAAA;yBACV,CAAC,CAAC;qBACJ;;;;;;;;;YACH,CAAC;eACD;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n asPattern,\n getNgRxStores,\n isArrowFunctionExpression,\n isFunctionExpression,\n isLiteral,\n pipeableSelect,\n selectExpression,\n} from '../../utils';\n\nexport const messageId = 'preferSelectorInSelect';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n ngrxModule: 'store',\n docs: {\n description:\n 'Using a selector in the `select` is preferred over `string` or `props drilling`.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]:\n 'Using `string` or `props drilling` is forbidden. Use a selector instead.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n\n if (!storeNames) {\n return {};\n }\n\n return {\n [`${pipeableSelect(storeNames)}, ${selectExpression(storeNames)}`](\n node: TSESTree.CallExpression\n ) {\n for (const argument of node.arguments) {\n if (\n !isLiteral(argument) &&\n !isArrowFunctionExpression(argument) &&\n !isFunctionExpression(argument)\n ) {\n break;\n }\n\n context.report({\n node: argument,\n messageId,\n });\n }\n },\n };\n },\n});\n"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var _a;
|
|
37
|
+
exports.__esModule = true;
|
|
38
|
+
exports.prefixSelectorsWithSelectSuggest = exports.prefixSelectorsWithSelect = void 0;
|
|
39
|
+
var path = __importStar(require("path"));
|
|
40
|
+
var rule_creator_1 = require("../../rule-creator");
|
|
41
|
+
var utils_1 = require("../../utils");
|
|
42
|
+
exports.prefixSelectorsWithSelect = 'prefixSelectorsWithSelect';
|
|
43
|
+
exports.prefixSelectorsWithSelectSuggest = 'prefixSelectorsWithSelectSuggest';
|
|
44
|
+
exports["default"] = (0, rule_creator_1.createRule)({
|
|
45
|
+
name: path.parse(__filename).name,
|
|
46
|
+
meta: {
|
|
47
|
+
type: 'suggestion',
|
|
48
|
+
hasSuggestions: true,
|
|
49
|
+
ngrxModule: 'store',
|
|
50
|
+
docs: {
|
|
51
|
+
description: 'The selector should start with "select", for example "selectThing".',
|
|
52
|
+
recommended: 'warn',
|
|
53
|
+
suggestion: true
|
|
54
|
+
},
|
|
55
|
+
schema: [],
|
|
56
|
+
messages: (_a = {},
|
|
57
|
+
_a[exports.prefixSelectorsWithSelect] = 'The selector should start with "select".',
|
|
58
|
+
_a[exports.prefixSelectorsWithSelectSuggest] = 'Prefix the selector with "select": `{{ name }}`.',
|
|
59
|
+
_a)
|
|
60
|
+
},
|
|
61
|
+
defaultOptions: [],
|
|
62
|
+
create: function (context) {
|
|
63
|
+
return {
|
|
64
|
+
'VariableDeclarator[id.name!=/^select[^a-z].+$/]:matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))': function (_a) {
|
|
65
|
+
var _b, _c;
|
|
66
|
+
var id = _a.id;
|
|
67
|
+
var suggestedName = getSuggestedName(id.name);
|
|
68
|
+
context.report({
|
|
69
|
+
loc: __assign(__assign({}, id.loc), { end: __assign(__assign({}, id.loc.end), { column: ((_c = (_b = id.typeAnnotation) === null || _b === void 0 ? void 0 : _b.range[0]) !== null && _c !== void 0 ? _c : id.range[1]) - 1 }) }),
|
|
70
|
+
messageId: exports.prefixSelectorsWithSelect,
|
|
71
|
+
suggest: [
|
|
72
|
+
{
|
|
73
|
+
messageId: exports.prefixSelectorsWithSelectSuggest,
|
|
74
|
+
data: {
|
|
75
|
+
name: suggestedName
|
|
76
|
+
},
|
|
77
|
+
fix: function (fixer) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
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);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
function getSuggestedName(name) {
|
|
89
|
+
var selectWord = 'select';
|
|
90
|
+
// Ex: 'selectfeature' => 'selectFeature'
|
|
91
|
+
var possibleReplacedName = name.replace(new RegExp("^".concat(selectWord, "(.+)")), function (_, word) {
|
|
92
|
+
return "".concat(selectWord).concat((0, utils_1.capitalize)(word));
|
|
93
|
+
});
|
|
94
|
+
if (name !== possibleReplacedName) {
|
|
95
|
+
return possibleReplacedName;
|
|
96
|
+
}
|
|
97
|
+
// Ex: 'getCount' => 'selectCount'
|
|
98
|
+
possibleReplacedName = name.replace(/^get([^a-z].+)/, function (_, word) {
|
|
99
|
+
return "".concat(selectWord).concat((0, utils_1.capitalize)(word));
|
|
100
|
+
});
|
|
101
|
+
if (name !== possibleReplacedName) {
|
|
102
|
+
return possibleReplacedName;
|
|
103
|
+
}
|
|
104
|
+
// Ex: 'item' => 'selectItem'
|
|
105
|
+
return "".concat(selectWord).concat((0, utils_1.capitalize)(name));
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=prefix-selectors-with-select.js.map
|