@ngrx/eslint-plugin 16.0.0 → 16.1.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/LICENSE +25 -0
- package/package.json +1 -1
- package/scripts/generate-overview.js +1 -1
- package/scripts/generate-overview.js.map +1 -1
- package/src/rules/component-store/updater-explicit-return-type.js +1 -1
- package/src/rules/component-store/updater-explicit-return-type.js.map +1 -1
- package/src/utils/helper-functions/utils.js +15 -13
- package/src/utils/helper-functions/utils.js.map +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-2023 Brandon Roberts, Mike Ryan, Victor Savkin, Rob Wormald
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
This repository includes a file "debounceSync.ts" originially copied from
|
|
24
|
+
https://github.com/cartant/rxjs-etc by Nicholas Jamieson, MIT licensed. See the
|
|
25
|
+
file header for details.
|
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ var rules_1 = require("../src/rules");
|
|
|
43
43
|
var configs_1 = require("../src/configs");
|
|
44
44
|
var prettierConfig = prettier_1.resolveConfig.sync(__dirname);
|
|
45
45
|
var OVERVIEW = './projects/ngrx.io/content/guide/eslint-plugin/index.md';
|
|
46
|
-
var GH_CONFIGS = 'https://github.com/ngrx/platform/blob/
|
|
46
|
+
var GH_CONFIGS = 'https://github.com/ngrx/platform/blob/main/modules/eslint-plugin/src/configs';
|
|
47
47
|
generateRules();
|
|
48
48
|
generateConfigurations();
|
|
49
49
|
function generateRules() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-overview.js","sourceRoot":"","sources":["../../../../modules/eslint-plugin/scripts/generate-overview.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAiD;AACjD,yBAAyB;AACzB,qCAAiD;AACjD,sCAAqC;AACrC,0CAAyC;AAEzC,IAAM,cAAc,GAAG,wBAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACrD,IAAM,QAAQ,GAAG,yDAAyD,CAAC;AAC3E,IAAM,UAAU,GACd,
|
|
1
|
+
{"version":3,"file":"generate-overview.js","sourceRoot":"","sources":["../../../../modules/eslint-plugin/scripts/generate-overview.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yBAAiD;AACjD,yBAAyB;AACzB,qCAAiD;AACjD,sCAAqC;AACrC,0CAAyC;AAEzC,IAAM,cAAc,GAAG,wBAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACrD,IAAM,QAAQ,GAA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AAI,CAAC,iBAAO,CAAC,CAAC;IAEpC,IAAM,QAAQ,GAAG,IAAA,iBAAY,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACjD,IAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC;IACvE,IAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,oCAAoC,CAAC,CAAC;IAEnE,IAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAC5B,UAAC,UAAU,IAAK,OAAA,aAAM,UAAU,eAAK,UAAU,cAAI,UAAU,WAAQ,EAArD,CAAqD,CACtE,CAAC;IACF,IAAM,WAAW,GAAG,IAAA,iBAAM,EACxB,UAAG,QAAQ,CAAC,SAAS,CACnB,CAAC,EACD,KAAK,GAAG,sCAAsC,CAAC,MAAM,CACtD,iBACD,eAAC,WAAW,UAAK,WAAW,UAAE,IAAI,CAAC,QAAG,CAAC,iBACvC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAE,aAEvB,MAAM,EAAE,UAAU,IACf,cAAc,EAEpB,CAAC;IAEF,IAAA,kBAAa,EAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import { readFileSync, writeFileSync } from 'fs';\nimport { EOL } from 'os';\nimport { format, resolveConfig } from 'prettier';\nimport { rules } from '../src/rules';\nimport { configs } from '../src/configs';\n\nconst prettierConfig = resolveConfig.sync(__dirname);\nconst OVERVIEW = './projects/ngrx.io/content/guide/eslint-plugin/index.md';\nconst GH_CONFIGS =\n 'https://github.com/ngrx/platform/blob/main/modules/eslint-plugin/src/configs';\n\ngenerateRules();\ngenerateConfigurations();\n\nfunction generateRules() {\n const moduleRules = Object.entries(rules).reduce<Record<string, string[][]>>(\n (all, [ruleName, { meta }]) => {\n all[meta.ngrxModule] = (all[meta.ngrxModule] ?? []).concat([\n [\n `[@ngrx/${ruleName}]${\n meta.docs?.url\n ? '(' +\n meta.docs.url\n .replace('https://ngrx.io', '')\n .replace('.md', '') +\n ')'\n : ''\n }`,\n meta.docs?.description ?? 'TODO',\n meta.type,\n `${meta.docs?.recommended}`,\n meta.fixable ? 'Yes' : 'No',\n meta.hasSuggestions ? 'Yes' : 'No',\n meta.schema.length ? 'Yes' : 'No',\n meta.docs?.requiresTypeChecking ? 'Yes' : 'No',\n ],\n ]);\n return all;\n },\n {}\n );\n\n const tableHeader = `| Name | Description | Recommended | Category | Fixable | Has suggestions | Configurable | Requires type information\n| --- | --- | --- | --- | --- | --- | --- | --- |`;\n\n const configTable = Object.entries(moduleRules).map(\n ([ngrxModule, pluginRules]) => {\n const tableBody = pluginRules\n .map((rule) => `|${rule.join('|')}|`)\n .join(EOL);\n const table = [tableHeader, tableBody].join(EOL);\n\n return [`### ${ngrxModule}`, table].join(EOL);\n }\n );\n\n const overview = readFileSync(OVERVIEW, 'utf-8');\n const start = overview.indexOf('<!-- RULES-CONFIG:START -->');\n const end = overview.indexOf('<!-- RULES-CONFIG:END -->');\n\n const newOverview = format(\n `${overview.substring(0, start + '<!-- RULES-CONFIG:START -->'.length)}\n${configTable.join(EOL)}\n${overview.substring(end)}`,\n {\n parser: 'markdown',\n ...prettierConfig,\n }\n );\n\n writeFileSync(OVERVIEW, newOverview);\n}\n\nfunction generateConfigurations() {\n const tableHeader = `| Name |\n | --- |`;\n\n const config = Object.keys(configs);\n\n const overview = readFileSync(OVERVIEW, 'utf-8');\n const start = overview.indexOf('<!-- CONFIGURATIONS-CONFIG:START -->');\n const end = overview.indexOf('<!-- CONFIGURATIONS-CONFIG:END -->');\n\n const configTable = config.map(\n (configName) => `| [${configName}](${GH_CONFIGS}/${configName}.ts) |`\n );\n const newOverview = format(\n `${overview.substring(\n 0,\n start + '<!-- CONFIGURATIONS-CONFIG:START -->'.length\n )}\n ${[tableHeader, ...configTable].join(EOL)}\n ${overview.substring(end)}`,\n {\n parser: 'markdown',\n ...prettierConfig,\n }\n );\n\n writeFileSync(OVERVIEW, newOverview);\n}\n"]}
|
|
@@ -50,7 +50,7 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
50
50
|
var storeNames = identifiers.length > 0 ? (0, utils_1.asPattern)(identifiers) : null;
|
|
51
51
|
var withoutTypeAnnotation = "ArrowFunctionExpression:not([returnType.typeAnnotation])";
|
|
52
52
|
var selectors = [
|
|
53
|
-
"ClassDeclaration[superClass.name
|
|
53
|
+
"ClassDeclaration[superClass.name=/Store/] CallExpression[callee.object.type='ThisExpression'][callee.property.name='updater'] > ".concat(withoutTypeAnnotation),
|
|
54
54
|
storeNames &&
|
|
55
55
|
"".concat((0, utils_1.namedExpression)(storeNames), "[callee.property.name='updater'] > ").concat(withoutTypeAnnotation),
|
|
56
56
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updater-explicit-return-type.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/component-store/updater-explicit-return-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAIqB;AAER,QAAA,SAAS,GAAG,2BAA2B,CAAC;AAKrD,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,iBAAiB;QAC7B,IAAI,EAAE;YACJ,WAAW,EAAE,gDAAgD;YAC7D,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IACR,6HAA6H;eAChI;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACN,IAAA,KAAqB,IAAA,8BAAsB,EAAC,OAAO,CAAC,YAApC,EAAhB,WAAW,mBAAG,EAAE,KAAA,CAAqC;QAC7D,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1E,IAAM,qBAAqB,GAAG,0DAA0D,CAAC;QACzF,IAAM,SAAS,GAAG;YAChB,
|
|
1
|
+
{"version":3,"file":"updater-explicit-return-type.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/component-store/updater-explicit-return-type.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAIqB;AAER,QAAA,SAAS,GAAG,2BAA2B,CAAC;AAKrD,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,iBAAiB;QAC7B,IAAI,EAAE;YACJ,WAAW,EAAE,gDAAgD;YAC7D,WAAW,EAAE,MAAM;SACpB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iBAAS,IACR,6HAA6H;eAChI;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;;QACN,IAAA,KAAqB,IAAA,8BAAsB,EAAC,OAAO,CAAC,YAApC,EAAhB,WAAW,mBAAG,EAAE,KAAA,CAAqC;QAC7D,IAAM,UAAU,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1E,IAAM,qBAAqB,GAAG,0DAA0D,CAAC;QACzF,IAAM,SAAS,GAAG;YAChB,0IAAmI,qBAAqB,CAAE;YAC1J,UAAU;gBACR,UAAG,IAAA,uBAAe,EAChB,UAAU,CACX,gDAAsC,qBAAqB,CAAE;SACjE;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAC;QAEb;YACE,GAAC,SAAS,IAAV,UAAY,IAAsC;gBAChD,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 getNgRxComponentStores,\n namedExpression,\n} from '../../utils';\n\nexport const messageId = 'updaterExplicitReturnType';\n\ntype MessageIds = typeof messageId;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'problem',\n ngrxModule: 'component-store',\n docs: {\n description: '`Updater` should have an explicit return type.',\n recommended: 'warn',\n },\n schema: [],\n messages: {\n [messageId]:\n '`Updater` should have an explicit return type when using arrow functions: `this.store.updater((state, value): State => {}`.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n const { identifiers = [] } = getNgRxComponentStores(context);\n const storeNames = identifiers.length > 0 ? asPattern(identifiers) : null;\n const withoutTypeAnnotation = `ArrowFunctionExpression:not([returnType.typeAnnotation])`;\n const selectors = [\n `ClassDeclaration[superClass.name=/Store/] CallExpression[callee.object.type='ThisExpression'][callee.property.name='updater'] > ${withoutTypeAnnotation}`,\n storeNames &&\n `${namedExpression(\n storeNames\n )}[callee.property.name='updater'] > ${withoutTypeAnnotation}`,\n ]\n .filter(Boolean)\n .join(',');\n\n return {\n [selectors](node: TSESTree.ArrowFunctionExpression) {\n context.report({\n node,\n messageId,\n });\n },\n };\n },\n});\n"]}
|
|
@@ -36,7 +36,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
36
36
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.asPattern = exports.escapeText = exports.getNgRxStores = exports.getNgRxComponentStores = exports.getNgRxEffectActions = exports.capitalize = exports.getRawText = exports.
|
|
39
|
+
exports.asPattern = exports.escapeText = exports.getNgRxStores = exports.getNgRxComponentStores = exports.getNgRxEffectActions = exports.capitalize = exports.getRawText = exports.getDecoratorName = exports.getLast = exports.getImplementsSchemaFixer = exports.getInterface = exports.getInterfaces = exports.getInterfaceName = exports.getNodeToCommaRemoveFix = exports.getImportRemoveFix = exports.getImportAddFix = exports.getImportDeclarations = exports.getImportDeclarationSpecifier = exports.getNearestUpperNodeFrom = void 0;
|
|
40
40
|
var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
|
41
41
|
var guards_1 = require("./guards");
|
|
42
42
|
var ngrx_modules_1 = require("./ngrx-modules");
|
|
@@ -202,11 +202,6 @@ function getLast(items) {
|
|
|
202
202
|
return items.slice(-1)[0];
|
|
203
203
|
}
|
|
204
204
|
exports.getLast = getLast;
|
|
205
|
-
function getDecoratorArguments(_a) {
|
|
206
|
-
var expression = _a.expression;
|
|
207
|
-
return (0, guards_1.isCallExpression)(expression) ? expression.arguments : [];
|
|
208
|
-
}
|
|
209
|
-
exports.getDecoratorArguments = getDecoratorArguments;
|
|
210
205
|
function getDecoratorName(_a) {
|
|
211
206
|
var expression = _a.expression;
|
|
212
207
|
if ((0, guards_1.isIdentifier)(expression)) {
|
|
@@ -217,11 +212,6 @@ function getDecoratorName(_a) {
|
|
|
217
212
|
: undefined;
|
|
218
213
|
}
|
|
219
214
|
exports.getDecoratorName = getDecoratorName;
|
|
220
|
-
function getDecorator(_a, decoratorName) {
|
|
221
|
-
var decorators = _a.decorators;
|
|
222
|
-
return decorators === null || decorators === void 0 ? void 0 : decorators.find(function (decorator) { return getDecoratorName(decorator) === decoratorName; });
|
|
223
|
-
}
|
|
224
|
-
exports.getDecorator = getDecorator;
|
|
225
215
|
function getRawText(node) {
|
|
226
216
|
if ((0, guards_1.isIdentifier)(node)) {
|
|
227
217
|
return node.name;
|
|
@@ -248,10 +238,12 @@ function capitalize(text) {
|
|
|
248
238
|
}
|
|
249
239
|
exports.capitalize = capitalize;
|
|
250
240
|
function getInjectedParametersWithSourceCode(context, moduleName, importName) {
|
|
251
|
-
var _a, _b, _c;
|
|
241
|
+
var _a, _b, _c, _d, _e;
|
|
252
242
|
var sourceCode = context.getSourceCode();
|
|
253
243
|
var importDeclarations = (_a = getImportDeclarations(sourceCode.ast, moduleName)) !== null && _a !== void 0 ? _a : [];
|
|
254
244
|
var importSpecifier = ((_b = getImportDeclarationSpecifier(importDeclarations, importName)) !== null && _b !== void 0 ? _b : {}).importSpecifier;
|
|
245
|
+
var injectImportDeclarations = (_c = getImportDeclarations(sourceCode.ast, '@angular/core')) !== null && _c !== void 0 ? _c : [];
|
|
246
|
+
var injectImportSpecifier = ((_d = getImportDeclarationSpecifier(injectImportDeclarations, 'inject')) !== null && _d !== void 0 ? _d : {}).importSpecifier;
|
|
255
247
|
if (!importSpecifier) {
|
|
256
248
|
return { sourceCode: sourceCode };
|
|
257
249
|
}
|
|
@@ -260,7 +252,7 @@ function getInjectedParametersWithSourceCode(context, moduleName, importName) {
|
|
|
260
252
|
var name = _a.name;
|
|
261
253
|
return name === importName;
|
|
262
254
|
});
|
|
263
|
-
var identifiers = (
|
|
255
|
+
var identifiers = (_e = typedVariable === null || typedVariable === void 0 ? void 0 : typedVariable.references) === null || _e === void 0 ? void 0 : _e.reduce(function (identifiers, _a) {
|
|
264
256
|
var parent = _a.identifier.parent;
|
|
265
257
|
if (parent &&
|
|
266
258
|
(0, guards_1.isTSTypeReference)(parent) &&
|
|
@@ -270,6 +262,16 @@ function getInjectedParametersWithSourceCode(context, moduleName, importName) {
|
|
|
270
262
|
(0, guards_1.isIdentifier)(parent.parent.parent)) {
|
|
271
263
|
return identifiers.concat(parent.parent.parent);
|
|
272
264
|
}
|
|
265
|
+
if (parent &&
|
|
266
|
+
(0, guards_1.isCallExpression)(parent) &&
|
|
267
|
+
(0, guards_1.isIdentifier)(parent.callee) &&
|
|
268
|
+
parent.callee.name == 'inject' &&
|
|
269
|
+
parent.parent &&
|
|
270
|
+
(0, guards_1.isPropertyDefinition)(parent.parent) &&
|
|
271
|
+
(0, guards_1.isIdentifier)(parent.parent.key) &&
|
|
272
|
+
injectImportSpecifier) {
|
|
273
|
+
return identifiers.concat(parent.parent.key);
|
|
274
|
+
}
|
|
273
275
|
return identifiers;
|
|
274
276
|
}, []);
|
|
275
277
|
return { identifiers: identifiers, sourceCode: sourceCode };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAiE;AACjE,mCAiBkB;AAClB,+CAAmD;AAmBnD,SAAgB,uBAAuB,CACrC,EAAyB,EACzB,SAAiD;QAD/C,MAAM,YAAA;IAGR,OAAO,MAAM,IAAI,CAAC,IAAA,kBAAS,EAAC,MAAM,CAAC,EAAE;QACnC,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE;YACrB,OAAO,MAAM,CAAC;SACf;QAED,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;KACxB;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAbD,0DAaC;AAED,SAAgB,6BAA6B,CAC3C,kBAAyD,EACzD,UAAkB;;;QAElB,KAAgC,IAAA,uBAAA,SAAA,kBAAkB,CAAA,sDAAA,sFAAE;YAA/C,IAAM,iBAAiB,+BAAA;YAC1B,IAAM,eAAe,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,CACvD,UAAC,YAAY;gBACX,OAAO,CACL,IAAA,0BAAiB,EAAC,YAAY,CAAC;oBAC/B,YAAY,CAAC,QAAQ,CAAC,IAAI,KAAK,UAAU,CAC1C,CAAC;YACJ,CAAC,CACF,CAAC;YAEF,IAAI,eAAe,EAAE;gBACnB,OAAO,EAAE,iBAAiB,mBAAA,EAAE,eAAe,iBAAA,EAAW,CAAC;aACxD;SACF;;;;;;;;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ent":["import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ASTUtils } from '@typescript-eslint/experimental-utils';\nimport {\n isCallExpression,\n isIdentifier,\n isIdentifierOrMemberExpression,\n isImportDeclaration,\n isImportDefaultSpecifier,\n isImportNamespaceSpecifier,\n isImportSpecifier,\n isLiteral,\n isMethodDefinition,\n isProgram,\n isProperty,\n isPropertyDefinition,\n isTemplateElement,\n isTemplateLiteral,\n isTSTypeAnnotation,\n isTSTypeReference,\n} from './guards';\nimport { NGRX_MODULE_PATHS } from './ngrx-modules';\n\ntype ConstructorFunctionExpression = TSESTree.FunctionExpression & {\n parent: TSESTree.MethodDefinition & { kind: 'constructor' };\n};\ntype InjectedParameter =\n | TSESTree.Identifier & {\n typeAnnotation: TSESTree.TSTypeAnnotation;\n parent:\n | ConstructorFunctionExpression\n | (TSESTree.TSParameterProperty & {\n parent: ConstructorFunctionExpression;\n });\n };\ntype InjectedParameterWithSourceCode = Readonly<{\n identifiers?: readonly InjectedParameter[];\n sourceCode: Readonly<TSESLint.SourceCode>;\n}>;\n\nexport function getNearestUpperNodeFrom<T extends TSESTree.Node>(\n { parent }: TSESTree.Node,\n predicate: (parent: TSESTree.Node) => parent is T\n): T | undefined {\n while (parent && !isProgram(parent)) {\n if (predicate(parent)) {\n return parent;\n }\n\n parent = parent.parent;\n }\n\n return undefined;\n}\n\nexport function getImportDeclarationSpecifier(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importName: string\n) {\n for (const importDeclaration of importDeclarations) {\n const importSpecifier = importDeclaration.specifiers.find(\n (importClause): importClause is TSESTree.ImportSpecifier => {\n return (\n isImportSpecifier(importClause) &&\n importClause.imported.name === importName\n );\n }\n );\n\n if (importSpecifier) {\n return { importDeclaration, importSpecifier } as const;\n }\n }\n\n return undefined;\n}\n\nexport function getImportDeclarations(\n node: TSESTree.Node,\n moduleName: string\n): readonly TSESTree.ImportDeclaration[] | undefined {\n let parentNode: TSESTree.Node | undefined = node;\n\n while (parentNode && !isProgram(parentNode)) {\n parentNode = parentNode.parent;\n }\n\n return parentNode?.body.filter((node): node is TSESTree.ImportDeclaration => {\n return isImportDeclaration(node) && node.source.value === moduleName;\n });\n}\n\nfunction getCorrespondentImportClause(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n compatibleWithTypeOnlyImport = false\n) {\n let importClause: TSESTree.ImportClause | undefined;\n\n for (const { importKind, specifiers } of importDeclarations) {\n const lastImportSpecifier = getLast(specifiers);\n\n if (\n (!compatibleWithTypeOnlyImport && importKind === 'type') ||\n isImportNamespaceSpecifier(lastImportSpecifier)\n ) {\n continue;\n }\n\n importClause = lastImportSpecifier;\n }\n\n return importClause;\n}\n\nexport function getImportAddFix({\n compatibleWithTypeOnlyImport = false,\n fixer,\n importName,\n moduleName,\n node,\n}: {\n compatibleWithTypeOnlyImport?: boolean;\n fixer: TSESLint.RuleFixer;\n importName: string;\n moduleName: string;\n node: TSESTree.Node;\n}): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const fullImport = `import { ${importName} } from '${moduleName}';\\n`;\n const importDeclarations = getImportDeclarations(node, moduleName);\n\n if (!importDeclarations?.length) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const importDeclarationSpecifier = getImportDeclarationSpecifier(\n importDeclarations,\n importName\n );\n\n if (importDeclarationSpecifier) {\n return [];\n }\n\n const importClause = getCorrespondentImportClause(\n importDeclarations,\n compatibleWithTypeOnlyImport\n );\n\n if (!importClause) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const replacementText = isImportDefaultSpecifier(importClause)\n ? `, { ${importName} }`\n : `, ${importName}`;\n return fixer.insertTextAfter(importClause, replacementText);\n}\n\nexport function getImportRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importedName: string,\n fixer: TSESLint.RuleFixer\n): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const { importDeclaration, importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importedName) ?? {};\n\n if (!importDeclaration || !importSpecifier) {\n return [];\n }\n\n const isFirstImportSpecifier =\n importDeclaration.specifiers[0] === importSpecifier;\n const isLastImportSpecifier =\n getLast(importDeclaration.specifiers) === importSpecifier;\n const isSingleImportSpecifier =\n isFirstImportSpecifier && isLastImportSpecifier;\n\n if (isSingleImportSpecifier) {\n return fixer.remove(importDeclaration);\n }\n\n const tokenAfterImportSpecifier = sourceCode.getTokenAfter(importSpecifier);\n\n if (isFirstImportSpecifier && tokenAfterImportSpecifier) {\n return fixer.removeRange([\n importSpecifier.range[0],\n tokenAfterImportSpecifier.range[1],\n ]);\n }\n\n const tokenBeforeImportSpecifier = sourceCode.getTokenBefore(importSpecifier);\n\n if (!tokenBeforeImportSpecifier) {\n return [];\n }\n\n return fixer.removeRange([\n tokenBeforeImportSpecifier.range[0],\n importSpecifier.range[1],\n ]);\n}\n\nexport function getNodeToCommaRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer,\n node: TSESTree.Node\n) {\n const nextToken = sourceCode.getTokenAfter(node);\n const isNextTokenComma = nextToken && ASTUtils.isCommaToken(nextToken);\n return [\n fixer.remove(node),\n ...(isNextTokenComma ? [fixer.remove(nextToken)] : []),\n ] as const;\n}\n\nexport function getInterfaceName(\n interfaceMember: TSESTree.Identifier | TSESTree.MemberExpression\n): string | undefined {\n if (isIdentifier(interfaceMember)) {\n return interfaceMember.name;\n }\n\n return isIdentifier(interfaceMember.property)\n ? interfaceMember.property.name\n : undefined;\n}\n\nexport function getInterfaces({\n implements: classImplements,\n}: TSESTree.ClassDeclaration): readonly (\n | TSESTree.Identifier\n | TSESTree.MemberExpression\n)[] {\n return (classImplements ?? [])\n .map(({ expression }) => expression)\n .filter(isIdentifierOrMemberExpression);\n}\n\nexport function getInterface(\n node: TSESTree.ClassDeclaration,\n interfaceName: string\n): TSESTree.Identifier | TSESTree.MemberExpression | undefined {\n return getInterfaces(node).find(\n (interfaceMember) => getInterfaceName(interfaceMember) === interfaceName\n );\n}\n\nexport function getImplementsSchemaFixer(\n { id, implements: classImplements }: TSESTree.ClassDeclaration,\n interfaceName: string\n) {\n const [implementsNodeReplace, implementsTextReplace] = classImplements\n ? [getLast(classImplements), `, ${interfaceName}`]\n : [id as TSESTree.Identifier, ` implements ${interfaceName}`];\n\n return { implementsNodeReplace, implementsTextReplace } as const;\n}\n\nexport function getLast<T extends readonly unknown[]>(items: T): T[number] {\n return items.slice(-1)[0];\n}\n\nexport function getDecoratorArguments({ expression }: TSESTree.Decorator) {\n return isCallExpression(expression) ? expression.arguments : [];\n}\n\nexport function getDecoratorName({\n expression,\n}: TSESTree.Decorator): string | undefined {\n if (isIdentifier(expression)) {\n return expression.name;\n }\n\n return isCallExpression(expression) && isIdentifier(expression.callee)\n ? expression.callee.name\n : undefined;\n}\n\nexport function getDecorator(\n {\n decorators,\n }:\n | TSESTree.PropertyDefinition\n | TSESTree.ClassDeclaration\n | TSESTree.MethodDefinition,\n decoratorName: string\n): TSESTree.Decorator | undefined {\n return decorators?.find(\n (decorator) => getDecoratorName(decorator) === decoratorName\n );\n}\n\nexport function getRawText(node: TSESTree.Node): string | null {\n if (isIdentifier(node)) {\n return node.name;\n }\n\n if (\n isPropertyDefinition(node) ||\n isMethodDefinition(node) ||\n isProperty(node)\n ) {\n return getRawText(node.key);\n }\n\n if (isLiteral(node)) {\n return node.raw;\n }\n\n if (isTemplateElement(node)) {\n return `\\`${node.value.raw}\\``;\n }\n\n if (isTemplateLiteral(node)) {\n return `\\`${node.quasis[0].value.raw}\\``;\n }\n\n return null;\n}\n\nexport function capitalize<T extends string>(text: T): Capitalize<T> {\n return `${text[0].toUpperCase()}${text.slice(1)}` as Capitalize<T>;\n}\n\nfunction getInjectedParametersWithSourceCode(\n context: TSESLint.RuleContext<string, readonly unknown[]>,\n moduleName: string,\n importName: string\n): InjectedParameterWithSourceCode {\n const sourceCode = context.getSourceCode();\n const importDeclarations =\n getImportDeclarations(sourceCode.ast, moduleName) ?? [];\n const { importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importName) ?? {};\n\n if (!importSpecifier) {\n return { sourceCode };\n }\n\n const variables = context.getDeclaredVariables(importSpecifier);\n const typedVariable = variables.find(({ name }) => name === importName);\n const identifiers = typedVariable?.references?.reduce<\n readonly InjectedParameter[]\n >((identifiers, { identifier: { parent } }) => {\n if (\n parent &&\n isTSTypeReference(parent) &&\n parent.parent &&\n isTSTypeAnnotation(parent.parent) &&\n parent.parent.parent &&\n isIdentifier(parent.parent.parent)\n ) {\n return identifiers.concat(parent.parent.parent as InjectedParameter);\n }\n\n return identifiers;\n }, []);\n return { identifiers, sourceCode };\n}\n\nexport function getNgRxEffectActions(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.effects,\n 'Actions'\n );\n}\n\nexport function getNgRxComponentStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS['component-store'],\n 'ComponentStore'\n );\n}\n\nexport function getNgRxStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.store,\n 'Store'\n );\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nexport function escapeText(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function asPattern(identifiers: readonly InjectedParameter[]): RegExp {\n const escapedNames = identifiers.map(({ name }) => escapeText(name));\n return new RegExp(`^(${escapedNames.join('|')})$`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;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wB,CAAC,CAAC;SACnE;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,EAAE,WAAW,aAAA,EAAE,UAAU,YAAA,EAAE,CAAC;AACrC,CAAC;AAED,SAAgB,oBAAoB,CAClC,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,OAAO,EACzB,SAAS,CACV,CAAC;AACJ,CAAC;AARD,oDAQC;AAED,SAAgB,sBAAsB,CACpC,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,iBAAiB,CAAC,EACpC,gBAAgB,CACjB,CAAC;AACJ,CAAC;AARD,wDAQC;AAED,SAAgB,aAAa,CAC3B,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,KAAK,EACvB,OAAO,CACR,CAAC;AACJ,CAAC;AARD,sCAQC;AAED,6FAA6F;AAC7F,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAFD,gCAEC;AAED,SAAgB,SAAS,CAAC,WAAyC;IACjE,IAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,EAAQ;YAAN,IAAI,UAAA;QAAO,OAAA,UAAU,CAAC,IAAI,CAAC;IAAhB,CAAgB,CAAC,CAAC;IACrE,OAAO,IAAI,MAAM,CAAC,YAAK,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,OAAI,CAAC,CAAC;AACrD,CAAC;AAHD,8BAGC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ASTUtils } from '@typescript-eslint/experimental-utils';\nimport {\n isCallExpression,\n isIdentifier,\n isIdentifierOrMemberExpression,\n isImportDeclaration,\n isImportDefaultSpecifier,\n isImportNamespaceSpecifier,\n isImportSpecifier,\n isLiteral,\n isMethodDefinition,\n isProgram,\n isProperty,\n isPropertyDefinition,\n isTSTypeAnnotation,\n isTSTypeReference,\n isTemplateElement,\n isTemplateLiteral,\n} from './guards';\nimport { NGRX_MODULE_PATHS } from './ngrx-modules';\n\ntype ConstructorFunctionExpression = TSESTree.FunctionExpression & {\n parent: TSESTree.MethodDefinition & { kind: 'constructor' };\n};\ntype InjectedParameter =\n | TSESTree.Identifier & {\n typeAnnotation: TSESTree.TSTypeAnnotation;\n parent:\n | ConstructorFunctionExpression\n | (TSESTree.TSParameterProperty & {\n parent: ConstructorFunctionExpression;\n })\n | TSESTree.PropertyDefinition;\n };\ntype InjectedParameterWithSourceCode = Readonly<{\n identifiers?: readonly InjectedParameter[];\n sourceCode: Readonly<TSESLint.SourceCode>;\n}>;\n\nexport function getNearestUpperNodeFrom<T extends TSESTree.Node>(\n { parent }: TSESTree.Node,\n predicate: (parent: TSESTree.Node) => parent is T\n): T | undefined {\n while (parent && !isProgram(parent)) {\n if (predicate(parent)) {\n return parent;\n }\n\n parent = parent.parent;\n }\n\n return undefined;\n}\n\nexport function getImportDeclarationSpecifier(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importName: string\n) {\n for (const importDeclaration of importDeclarations) {\n const importSpecifier = importDeclaration.specifiers.find(\n (importClause): importClause is TSESTree.ImportSpecifier => {\n return (\n isImportSpecifier(importClause) &&\n importClause.imported.name === importName\n );\n }\n );\n\n if (importSpecifier) {\n return { importDeclaration, importSpecifier } as const;\n }\n }\n\n return undefined;\n}\n\nexport function getImportDeclarations(\n node: TSESTree.Node,\n moduleName: string\n): readonly TSESTree.ImportDeclaration[] | undefined {\n let parentNode: TSESTree.Node | undefined = node;\n\n while (parentNode && !isProgram(parentNode)) {\n parentNode = parentNode.parent;\n }\n\n return parentNode?.body.filter((node): node is TSESTree.ImportDeclaration => {\n return isImportDeclaration(node) && node.source.value === moduleName;\n });\n}\n\nfunction getCorrespondentImportClause(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n compatibleWithTypeOnlyImport = false\n) {\n let importClause: TSESTree.ImportClause | undefined;\n\n for (const { importKind, specifiers } of importDeclarations) {\n const lastImportSpecifier = getLast(specifiers);\n\n if (\n (!compatibleWithTypeOnlyImport && importKind === 'type') ||\n isImportNamespaceSpecifier(lastImportSpecifier)\n ) {\n continue;\n }\n\n importClause = lastImportSpecifier;\n }\n\n return importClause;\n}\n\nexport function getImportAddFix({\n compatibleWithTypeOnlyImport = false,\n fixer,\n importName,\n moduleName,\n node,\n}: {\n compatibleWithTypeOnlyImport?: boolean;\n fixer: TSESLint.RuleFixer;\n importName: string;\n moduleName: string;\n node: TSESTree.Node;\n}): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const fullImport = `import { ${importName} } from '${moduleName}';\\n`;\n const importDeclarations = getImportDeclarations(node, moduleName);\n\n if (!importDeclarations?.length) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const importDeclarationSpecifier = getImportDeclarationSpecifier(\n importDeclarations,\n importName\n );\n\n if (importDeclarationSpecifier) {\n return [];\n }\n\n const importClause = getCorrespondentImportClause(\n importDeclarations,\n compatibleWithTypeOnlyImport\n );\n\n if (!importClause) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const replacementText = isImportDefaultSpecifier(importClause)\n ? `, { ${importName} }`\n : `, ${importName}`;\n return fixer.insertTextAfter(importClause, replacementText);\n}\n\nexport function getImportRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importedName: string,\n fixer: TSESLint.RuleFixer\n): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const { importDeclaration, importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importedName) ?? {};\n\n if (!importDeclaration || !importSpecifier) {\n return [];\n }\n\n const isFirstImportSpecifier =\n importDeclaration.specifiers[0] === importSpecifier;\n const isLastImportSpecifier =\n getLast(importDeclaration.specifiers) === importSpecifier;\n const isSingleImportSpecifier =\n isFirstImportSpecifier && isLastImportSpecifier;\n\n if (isSingleImportSpecifier) {\n return fixer.remove(importDeclaration);\n }\n\n const tokenAfterImportSpecifier = sourceCode.getTokenAfter(importSpecifier);\n\n if (isFirstImportSpecifier && tokenAfterImportSpecifier) {\n return fixer.removeRange([\n importSpecifier.range[0],\n tokenAfterImportSpecifier.range[1],\n ]);\n }\n\n const tokenBeforeImportSpecifier = sourceCode.getTokenBefore(importSpecifier);\n\n if (!tokenBeforeImportSpecifier) {\n return [];\n }\n\n return fixer.removeRange([\n tokenBeforeImportSpecifier.range[0],\n importSpecifier.range[1],\n ]);\n}\n\nexport function getNodeToCommaRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer,\n node: TSESTree.Node\n) {\n const nextToken = sourceCode.getTokenAfter(node);\n const isNextTokenComma = nextToken && ASTUtils.isCommaToken(nextToken);\n return [\n fixer.remove(node),\n ...(isNextTokenComma ? [fixer.remove(nextToken)] : []),\n ] as const;\n}\n\nexport function getInterfaceName(\n interfaceMember: TSESTree.Identifier | TSESTree.MemberExpression\n): string | undefined {\n if (isIdentifier(interfaceMember)) {\n return interfaceMember.name;\n }\n\n return isIdentifier(interfaceMember.property)\n ? interfaceMember.property.name\n : undefined;\n}\n\nexport function getInterfaces({\n implements: classImplements,\n}: TSESTree.ClassDeclaration): readonly (\n | TSESTree.Identifier\n | TSESTree.MemberExpression\n)[] {\n return (classImplements ?? [])\n .map(({ expression }) => expression)\n .filter(isIdentifierOrMemberExpression);\n}\n\nexport function getInterface(\n node: TSESTree.ClassDeclaration,\n interfaceName: string\n): TSESTree.Identifier | TSESTree.MemberExpression | undefined {\n return getInterfaces(node).find(\n (interfaceMember) => getInterfaceName(interfaceMember) === interfaceName\n );\n}\n\nexport function getImplementsSchemaFixer(\n { id, implements: classImplements }: TSESTree.ClassDeclaration,\n interfaceName: string\n) {\n const [implementsNodeReplace, implementsTextReplace] = classImplements\n ? [getLast(classImplements), `, ${interfaceName}`]\n : [id as TSESTree.Identifier, ` implements ${interfaceName}`];\n\n return { implementsNodeReplace, implementsTextReplace } as const;\n}\n\nexport function getLast<T extends readonly unknown[]>(items: T): T[number] {\n return items.slice(-1)[0];\n}\n\nexport function getDecoratorName({\n expression,\n}: TSESTree.Decorator): string | undefined {\n if (isIdentifier(expression)) {\n return expression.name;\n }\n\n return isCallExpression(expression) && isIdentifier(expression.callee)\n ? expression.callee.name\n : undefined;\n}\n\nexport function getRawText(node: TSESTree.Node): string | null {\n if (isIdentifier(node)) {\n return node.name;\n }\n\n if (\n isPropertyDefinition(node) ||\n isMethodDefinition(node) ||\n isProperty(node)\n ) {\n return getRawText(node.key);\n }\n\n if (isLiteral(node)) {\n return node.raw;\n }\n\n if (isTemplateElement(node)) {\n return `\\`${node.value.raw}\\``;\n }\n\n if (isTemplateLiteral(node)) {\n return `\\`${node.quasis[0].value.raw}\\``;\n }\n\n return null;\n}\n\nexport function capitalize<T extends string>(text: T): Capitalize<T> {\n return `${text[0].toUpperCase()}${text.slice(1)}` as Capitalize<T>;\n}\n\nfunction getInjectedParametersWithSourceCode(\n context: TSESLint.RuleContext<string, readonly unknown[]>,\n moduleName: string,\n importName: string\n): InjectedParameterWithSourceCode {\n const sourceCode = context.getSourceCode();\n const importDeclarations =\n getImportDeclarations(sourceCode.ast, moduleName) ?? [];\n const { importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importName) ?? {};\n\n const injectImportDeclarations =\n getImportDeclarations(sourceCode.ast, '@angular/core') ?? [];\n\n const { importSpecifier: injectImportSpecifier } =\n getImportDeclarationSpecifier(injectImportDeclarations, 'inject') ?? {};\n\n if (!importSpecifier) {\n return { sourceCode };\n }\n\n const variables = context.getDeclaredVariables(importSpecifier);\n const typedVariable = variables.find(({ name }) => name === importName);\n const identifiers = typedVariable?.references?.reduce<\n readonly InjectedParameter[]\n >((identifiers, { identifier: { parent } }) => {\n if (\n parent &&\n isTSTypeReference(parent) &&\n parent.parent &&\n isTSTypeAnnotation(parent.parent) &&\n parent.parent.parent &&\n isIdentifier(parent.parent.parent)\n ) {\n return identifiers.concat(parent.parent.parent as InjectedParameter);\n }\n\n if (\n parent &&\n isCallExpression(parent) &&\n isIdentifier(parent.callee) &&\n parent.callee.name == 'inject' &&\n parent.parent &&\n isPropertyDefinition(parent.parent) &&\n isIdentifier(parent.parent.key) &&\n injectImportSpecifier\n ) {\n return identifiers.concat(parent.parent.key as InjectedParameter);\n }\n\n return identifiers;\n }, []);\n return { identifiers, sourceCode };\n}\n\nexport function getNgRxEffectActions(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.effects,\n 'Actions'\n );\n}\n\nexport function getNgRxComponentStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS['component-store'],\n 'ComponentStore'\n );\n}\n\nexport function getNgRxStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.store,\n 'Store'\n );\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nexport function escapeText(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function asPattern(identifiers: readonly InjectedParameter[]): RegExp {\n const escapedNames = identifiers.map(({ name }) => escapeText(name));\n return new RegExp(`^(${escapedNames.join('|')})$`);\n}\n"]}
|