@ngrx/eslint-plugin 16.1.0 → 16.2.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/package.json +1 -1
- package/src/rule-creator.js +41 -0
- package/src/rule-creator.js.map +1 -1
- package/src/rules/store/no-typed-global-store.js +48 -19
- package/src/rules/store/no-typed-global-store.js.map +1 -1
- package/src/rules/store/prefix-selectors-with-select.js +4 -2
- package/src/rules/store/prefix-selectors-with-select.js.map +1 -1
- package/src/rules/store/use-consistent-global-store-name.js +2 -1
- package/src/rules/store/use-consistent-global-store-name.js.map +1 -1
- package/src/utils/helper-functions/guards.js +2 -1
- package/src/utils/helper-functions/guards.js.map +1 -1
- package/src/utils/helper-functions/utils.js +15 -10
- package/src/utils/helper-functions/utils.js.map +1 -1
package/package.json
CHANGED
package/src/rule-creator.js
CHANGED
|
@@ -10,11 +10,39 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __values = (this && this.__values) || function(o) {
|
|
14
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
|
+
if (m) return m.call(o);
|
|
16
|
+
if (o && typeof o.length === "number") return {
|
|
17
|
+
next: function () {
|
|
18
|
+
if (o && i >= o.length) o = void 0;
|
|
19
|
+
return { value: o && o[i++], done: !o };
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
23
|
+
};
|
|
24
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
25
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
26
|
+
if (!m) return o;
|
|
27
|
+
var i = m.call(o), r, ar = [], e;
|
|
28
|
+
try {
|
|
29
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
30
|
+
}
|
|
31
|
+
catch (error) { e = { error: error }; }
|
|
32
|
+
finally {
|
|
33
|
+
try {
|
|
34
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
35
|
+
}
|
|
36
|
+
finally { if (e) throw e.error; }
|
|
37
|
+
}
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
13
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
41
|
exports.createRule = void 0;
|
|
15
42
|
var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
|
16
43
|
var utils_1 = require("./utils");
|
|
17
44
|
function createRule(config) {
|
|
45
|
+
var e_1, _a;
|
|
18
46
|
var configOverwrite = __assign(__assign({}, config), { create: function (context, optionsWithDefault) {
|
|
19
47
|
var _a = config.meta, ngrxModule = _a.ngrxModule, version = _a.version;
|
|
20
48
|
if (version !== undefined &&
|
|
@@ -23,6 +51,19 @@ function createRule(config) {
|
|
|
23
51
|
}
|
|
24
52
|
return config.create(context, optionsWithDefault);
|
|
25
53
|
} });
|
|
54
|
+
try {
|
|
55
|
+
for (var _b = __values(Object.entries(configOverwrite.meta.messages)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
56
|
+
var _d = __read(_c.value, 2), key = _d[0], message = _d[1];
|
|
57
|
+
configOverwrite.meta.messages[key] = "".concat(message, " (").concat((0, utils_1.docsUrl)(config.name), ")");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
61
|
+
finally {
|
|
62
|
+
try {
|
|
63
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
64
|
+
}
|
|
65
|
+
finally { if (e_1) throw e_1.error; }
|
|
66
|
+
}
|
|
26
67
|
return experimental_utils_1.ESLintUtils.RuleCreator(utils_1.docsUrl)(configOverwrite);
|
|
27
68
|
}
|
|
28
69
|
exports.createRule = createRule;
|
package/src/rule-creator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-creator.js","sourceRoot":"","sources":["../../../../modules/eslint-plugin/src/rule-creator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rule-creator.js","sourceRoot":"","sources":["../../../../modules/eslint-plugin/src/rule-creator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAoE;AAEpE,iCAA2E;AAiB3E,SAAgB,UAAU,CAIxB,MAQE;;IAEF,IAAM,eAAe,yBAChB,MAAM,KACT,MAAM,EAAE,UACN,OAA8D,EAC9D,kBAAsC;YAGpC,IAAA,KACE,MAAM,KADqB,EAArB,UAAU,gBAAA,EAAE,OAAO,aAAE,CACpB;YACX,IACE,OAAO,KAAK,SAAS;gBACrB,CAAC,IAAA,4BAAoB,EAAC,yBAAiB,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,EAC7D;gBACA,OAAO,EAAE,CAAC;aACX;YAED,OAAO,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;QACpD,CAAC,GACF,CAAC;;QAEF,KAA6B,IAAA,KAAA,SAAA,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA,gBAAA,4BAAE;YAAjE,IAAA,KAAA,mBAAc,EAAb,GAAG,QAAA,EAAE,OAAO,QAAA;YACrB,eAAe,CAAC,IAAI,CAAC,QAAgB,CAAC,GAAG,CAAC,GAAG,UAAG,OAAO,eAAK,IAAA,eAAO,EAClE,MAAM,CAAC,IAAI,CACZ,MAAG,CAAC;SACN;;;;;;;;;IAED,OAAO,gCAAW,CAAC,WAAW,CAAC,eAAO,CAAC,CAAC,eAAe,CAAC,CAAC;AAC3D,CAAC;AAzCD,gCAyCC","sourcesContent":["import type { TSESLint } from '@typescript-eslint/experimental-utils';\nimport { ESLintUtils } from '@typescript-eslint/experimental-utils';\nimport type { NGRX_MODULE } from './utils';\nimport { docsUrl, ngrxVersionSatisfies, NGRX_MODULE_PATHS } from './utils';\n\ntype Meta<TMessageIds extends string> =\n | TSESLint.RuleMetaData<TMessageIds> & {\n ngrxModule: NGRX_MODULE;\n version?: string;\n };\ntype CreateRuleMeta<TMessageIds extends string> = {\n docs: Omit<TSESLint.RuleMetaDataDocs, 'url'>;\n} & Omit<Meta<TMessageIds>, 'docs'>;\nexport type NgRxRuleModule<\n TOptions extends readonly unknown[],\n TMessageIds extends string\n> = Omit<TSESLint.RuleModule<TMessageIds, TOptions>, 'meta'> & {\n meta: Meta<TMessageIds>;\n};\n\nexport function createRule<\n TOptions extends readonly unknown[],\n TMessageIds extends string\n>(\n config: Readonly<{\n name: string;\n meta: CreateRuleMeta<TMessageIds>;\n defaultOptions: Readonly<TOptions>;\n create: (\n context: Readonly<TSESLint.RuleContext<TMessageIds, TOptions>>,\n optionsWithDefault: Readonly<TOptions>\n ) => TSESLint.RuleListener;\n }>\n): TSESLint.RuleModule<TMessageIds, TOptions> {\n const configOverwrite = {\n ...config,\n create: (\n context: Readonly<TSESLint.RuleContext<TMessageIds, TOptions>>,\n optionsWithDefault: Readonly<TOptions>\n ) => {\n const {\n meta: { ngrxModule, version },\n } = config;\n if (\n version !== undefined &&\n !ngrxVersionSatisfies(NGRX_MODULE_PATHS[ngrxModule], version)\n ) {\n return {};\n }\n\n return config.create(context, optionsWithDefault);\n },\n };\n\n for (const [key, message] of Object.entries(configOverwrite.meta.messages)) {\n (configOverwrite.meta.messages as any)[key] = `${message} (${docsUrl(\n config.name\n )})`;\n }\n\n return ESLintUtils.RuleCreator(docsUrl)(configOverwrite);\n}\n"]}
|
|
@@ -33,6 +33,22 @@ var __values = (this && this.__values) || function(o) {
|
|
|
33
33
|
};
|
|
34
34
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
35
35
|
};
|
|
36
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
37
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
38
|
+
if (!m) return o;
|
|
39
|
+
var i = m.call(o), r, ar = [], e;
|
|
40
|
+
try {
|
|
41
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
42
|
+
}
|
|
43
|
+
catch (error) { e = { error: error }; }
|
|
44
|
+
finally {
|
|
45
|
+
try {
|
|
46
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
47
|
+
}
|
|
48
|
+
finally { if (e) throw e.error; }
|
|
49
|
+
}
|
|
50
|
+
return ar;
|
|
51
|
+
};
|
|
36
52
|
var _a;
|
|
37
53
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
54
|
exports.noTypedStoreSuggest = exports.noTypedStore = void 0;
|
|
@@ -64,27 +80,28 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
64
80
|
Program: function () {
|
|
65
81
|
var e_1, _a;
|
|
66
82
|
var _b = (0, utils_1.getNgRxStores)(context).identifiers, identifiers = _b === void 0 ? [] : _b;
|
|
67
|
-
var _loop_1 = function (typeAnnotation) {
|
|
68
|
-
if (!(0, utils_1.isTSTypeReference)(typeAnnotation) ||
|
|
69
|
-
!typeAnnotation.typeParameters) {
|
|
70
|
-
return "continue";
|
|
71
|
-
}
|
|
72
|
-
var typeParameters = typeAnnotation.typeParameters;
|
|
73
|
-
context.report({
|
|
74
|
-
node: typeParameters,
|
|
75
|
-
messageId: exports.noTypedStore,
|
|
76
|
-
suggest: [
|
|
77
|
-
{
|
|
78
|
-
messageId: exports.noTypedStoreSuggest,
|
|
79
|
-
fix: function (fixer) { return fixer.remove(typeParameters); },
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
83
|
try {
|
|
85
84
|
for (var identifiers_1 = __values(identifiers), identifiers_1_1 = identifiers_1.next(); !identifiers_1_1.done; identifiers_1_1 = identifiers_1.next()) {
|
|
86
|
-
var
|
|
87
|
-
|
|
85
|
+
var identifier = identifiers_1_1.value;
|
|
86
|
+
// using inject()
|
|
87
|
+
if (!identifier.typeAnnotation) {
|
|
88
|
+
var parent_1 = identifier.parent;
|
|
89
|
+
if ((0, utils_1.isPropertyDefinition)(parent_1) &&
|
|
90
|
+
parent_1.value &&
|
|
91
|
+
(0, utils_1.isCallExpression)(parent_1.value) &&
|
|
92
|
+
parent_1.value.arguments.length) {
|
|
93
|
+
var _c = __read(parent_1.value.arguments, 1), storeArgument = _c[0];
|
|
94
|
+
if ((0, utils_1.isTSInstantiationExpression)(storeArgument)) {
|
|
95
|
+
report(storeArgument.typeParameters);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (!(0, utils_1.isTSTypeReference)(identifier.typeAnnotation.typeAnnotation) ||
|
|
101
|
+
!identifier.typeAnnotation.typeAnnotation.typeParameters) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
report(identifier.typeAnnotation.typeAnnotation.typeParameters);
|
|
88
105
|
}
|
|
89
106
|
}
|
|
90
107
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -96,6 +113,18 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
96
113
|
}
|
|
97
114
|
},
|
|
98
115
|
};
|
|
116
|
+
function report(typeParameters) {
|
|
117
|
+
context.report({
|
|
118
|
+
node: typeParameters,
|
|
119
|
+
messageId: exports.noTypedStore,
|
|
120
|
+
suggest: [
|
|
121
|
+
{
|
|
122
|
+
messageId: exports.noTypedStoreSuggest,
|
|
123
|
+
fix: function (fixer) { return fixer.remove(typeParameters); },
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
99
128
|
},
|
|
100
129
|
});
|
|
101
130
|
//# sourceMappingURL=no-typed-global-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-typed-global-store.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/no-typed-global-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-typed-global-store.js","source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,QAAM,CAAC,KAAK,CAAC,SAAS,IAAA,EAAvC,aAAa,QAA0B,CAAC;gCAC/C,IAAI,IAAA,mCAA2B,EAAC,aAAa,CAAC,EAAE;oCAC9C,MAAM,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;iCACtC;6BACF;4BAED,SAAS;yBACV;wBAED,IACE,CAAC,IAAA,yBAAiB,EAAC,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC;4BAC5D,CAAC,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,cAAc,EACxD;4BACA,SAAS;yBACV;wBAED,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;qBACjE;;;;;;;;;YACH,CAAC;SACF,CAAC;QAEF,SAAS,MAAM,CAAC,cAAqD;YACnE,OAAO,CAAC,MAAM,CAAC;gBACb,IAAI,EAAE,cAAc;gBACpB,SAAS,EAAE,oBAAY;gBACvB,OAAO,EAAE;oBACP;wBACE,SAAS,EAAE,2BAAmB;wBAC9B,GAAG,EAAE,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,EAA5B,CAA4B;qBAC7C;iBACF;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAC,CAAC","sourcesContent":["import * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport {\n getNgRxStores,\n isPropertyDefinition,\n isTSTypeReference,\n isCallExpression,\n isTSInstantiationExpression,\n} from '../../utils';\nimport type { TSESTree } from '@typescript-eslint/experimental-utils';\n\nexport const noTypedStore = 'noTypedStore';\nexport const noTypedStoreSuggest = 'noTypedStoreSuggest';\n\ntype MessageIds = typeof noTypedStore | typeof noTypedStoreSuggest;\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: 'The global store should not be typed.',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [],\n messages: {\n [noTypedStore]:\n '`Store` should not be typed, use `Store` (without generic) instead.',\n [noTypedStoreSuggest]: 'Remove generic from `Store`.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n Program() {\n const { identifiers = [] } = getNgRxStores(context);\n\n for (const identifier of identifiers) {\n // using inject()\n if (!identifier.typeAnnotation) {\n const { parent } = identifier;\n if (\n isPropertyDefinition(parent) &&\n parent.value &&\n isCallExpression(parent.value) &&\n parent.value.arguments.length\n ) {\n const [storeArgument] = parent.value.arguments;\n if (isTSInstantiationExpression(storeArgument)) {\n report(storeArgument.typeParameters);\n }\n }\n\n continue;\n }\n\n if (\n !isTSTypeReference(identifier.typeAnnotation.typeAnnotation) ||\n !identifier.typeAnnotation.typeAnnotation.typeParameters\n ) {\n continue;\n }\n\n report(identifier.typeAnnotation.typeAnnotation.typeParameters);\n }\n },\n };\n\n function report(typeParameters: TSESTree.TSTypeParameterInstantiation) {\n context.report({\n node: typeParameters,\n messageId: noTypedStore,\n suggest: [\n {\n messageId: noTypedStoreSuggest,\n fix: (fixer) => fixer.remove(typeParameters),\n },\n ],\n });\n }\n },\n});\n"]}
|
|
@@ -62,11 +62,13 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
62
62
|
create: function (context) {
|
|
63
63
|
return {
|
|
64
64
|
'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name="createFeature"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))': function (_a) {
|
|
65
|
-
var _b
|
|
65
|
+
var _b;
|
|
66
66
|
var id = _a.id;
|
|
67
67
|
var suggestedName = getSuggestedName(id.name);
|
|
68
68
|
context.report({
|
|
69
|
-
loc: __assign(__assign({}, id.loc), { end: __assign(__assign({}, id.loc.end), { column: ((
|
|
69
|
+
loc: __assign(__assign({}, id.loc), { end: __assign(__assign({}, id.loc.end), { column: ((_b = id.typeAnnotation) === null || _b === void 0 ? void 0 : _b.range[0])
|
|
70
|
+
? id.typeAnnotation.range[0] - 1
|
|
71
|
+
: id.loc.end.column }) }),
|
|
70
72
|
messageId: exports.prefixSelectorsWithSelect,
|
|
71
73
|
suggest: [
|
|
72
74
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefix-selectors-with-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefix-selectors-with-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAAyC;AAE5B,QAAA,yBAAyB,GAAG,2BAA2B,CAAC;AACxD,QAAA,gCAAgC,GAC3C,kCAAkC,CAAC;AAOrC,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,qEAAqE;YACvE,WAAW,EAAE,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iCAAyB,IAAG,0CAA0C;YACvE,GAAC,wCAAgC,IAC/B,kDAAkD;eACrD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;QACd,OAAO;YACL,gRAAgR,YAAC,EAErN;;oBAD1D,EAAE,QAAA;gBAEF,IAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;gBAChD,OAAO,CAAC,MAAM,CAAC;oBACb,GAAG,wBACE,EAAE,CAAC,GAAG,KACT,GAAG,wBACE,EAAE,CAAC,GAAG,CAAC,GAAG,KACb,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"prefix-selectors-with-select.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/prefix-selectors-with-select.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAAyC;AAE5B,QAAA,yBAAyB,GAAG,2BAA2B,CAAC;AACxD,QAAA,gCAAgC,GAC3C,kCAAkC,CAAC;AAOrC,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EACT,qEAAqE;YACvE,WAAW,EAAE,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB;QACD,MAAM,EAAE,EAAE;QACV,QAAQ;YACN,GAAC,iCAAyB,IAAG,0CAA0C;YACvE,GAAC,wCAAgC,IAC/B,kDAAkD;eACrD;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,UAAC,OAAO;QACd,OAAO;YACL,gRAAgR,YAAC,EAErN;;oBAD1D,EAAE,QAAA;gBAEF,IAAM,aAAa,GAAG,gBAAgB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;gBAChD,OAAO,CAAC,MAAM,CAAC;oBACb,GAAG,wBACE,EAAE,CAAC,GAAG,KACT,GAAG,wBACE,EAAE,CAAC,GAAG,CAAC,GAAG,KACb,MAAM,EAAE,CAAA,MAAA,EAAE,CAAC,cAAc,0CAAE,KAAK,CAAC,CAAC,CAAC;gCACjC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;gCAChC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,MAExB;oBACD,SAAS,EAAE,iCAAyB;oBACpC,OAAO,EA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nimport { createRule } from '../../rule-creator';\nimport { capitalize } from '../../utils';\n\nexport const prefixSelectorsWithSelect = 'prefixSelectorsWithSelect';\nexport const prefixSelectorsWithSelectSuggest =\n 'prefixSelectorsWithSelectSuggest';\n\ntype MessageIds =\n | typeof prefixSelectorsWithSelect\n | typeof prefixSelectorsWithSelectSuggest;\ntype Options = readonly [];\n\nexport default createRule<Options, MessageIds>({\n name: path.parse(__filename).name,\n meta: {\n type: 'suggestion',\n hasSuggestions: true,\n ngrxModule: 'store',\n docs: {\n description:\n 'The selector should start with \"select\", for example \"selectThing\".',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [],\n messages: {\n [prefixSelectorsWithSelect]: 'The selector should start with \"select\".',\n [prefixSelectorsWithSelectSuggest]:\n 'Prefix the selector with \"select\": `{{ name }}`.',\n },\n },\n defaultOptions: [],\n create: (context) => {\n return {\n 'VariableDeclarator[id.name!=/^select[^a-z].+$/]:not(:has(Identifier[name=\"createFeature\"])):matches([id.typeAnnotation.typeAnnotation.typeName.name=/^MemoizedSelector(WithProps)?$/], :has(CallExpression[callee.name=/^(create(Feature)?Selector|createSelectorFactory)$/]))'({\n id,\n }: TSESTree.VariableDeclarator & { id: TSESTree.Identifier }) {\n const suggestedName = getSuggestedName(id.name);\n context.report({\n loc: {\n ...id.loc,\n end: {\n ...id.loc.end,\n column: id.typeAnnotation?.range[0]\n ? id.typeAnnotation.range[0] - 1\n : id.loc.end.column,\n },\n },\n messageId: prefixSelectorsWithSelect,\n suggest: [\n {\n messageId: prefixSelectorsWithSelectSuggest,\n data: {\n name: suggestedName,\n },\n fix: (fixer) =>\n fixer.replaceTextRange(\n [id.range[0], id.typeAnnotation?.range[0] ?? id.range[1]],\n suggestedName\n ),\n },\n ],\n });\n },\n };\n },\n});\n\nfunction getSuggestedName(name: string) {\n const selectWord = 'select';\n // Ex: 'selectfeature' => 'selectFeature'\n let possibleReplacedName = name.replace(\n new RegExp(`^${selectWord}(.+)`),\n (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n }\n );\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'getCount' => 'selectCount'\n possibleReplacedName = name.replace(/^get([^a-z].+)/, (_, word: string) => {\n return `${selectWord}${capitalize(word)}`;\n });\n\n if (name !== possibleReplacedName) {\n return possibleReplacedName;\n }\n\n // Ex: 'item' => 'selectItem'\n return `${selectWord}${capitalize(name)}`;\n}\n"]}
|
|
@@ -111,7 +111,8 @@ exports.default = (0, rule_creator_1.createRule)({
|
|
|
111
111
|
messageId: exports.useConsistentGlobalStoreNameSuggest,
|
|
112
112
|
data: data,
|
|
113
113
|
fix: function (fixer) {
|
|
114
|
-
|
|
114
|
+
var _a;
|
|
115
|
+
return fixer.replaceTextRange([range[0], (_a = typeAnnotation === null || typeAnnotation === void 0 ? void 0 : typeAnnotation.range[0]) !== null && _a !== void 0 ? _a : range[1]], storeName);
|
|
115
116
|
},
|
|
116
117
|
},
|
|
117
118
|
],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-consistent-global-store-name.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/use-consistent-global-store-name.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAA4C;AAE/B,QAAA,4BAA4B,GAAG,8BAA8B,CAAC;AAC9D,QAAA,mCAAmC,GAC9C,qCAAqC,CAAC;AAOxC,kBAAe,IAAA,yBAAU,EAAsB;IAC7C,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI;IACjC,IAAI,EAAE;QACJ,IAAI,EAAE,YAAY;QAClB,cAAc,EAAE,IAAI;QACpB,UAAU,EAAE,OAAO;QACnB,IAAI,EAAE;YACJ,WAAW,EAAE,6CAA6C;YAC1D,WAAW,EAAE,MAAM;YACnB,UAAU,EAAE,IAAI;SACjB;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,QAAQ;YACN,GAAC,oCAA4B,IAC3B,oDAAoD;YACtD,GAAC,2CAAmC,IAAG,iCAAiC;eACzE;KACF;IACD,cAAc,EAAE,CAAC,OAAO,CAAC;IACzB,MAAM,EAAE,UAAC,OAAO,EAAE,EAAW;YAAX,KAAA,aAAW,EAAV,SAAS,QAAA;QAC1B,OAAO;YACL,OAAO;;gBACG,IAAA,KAAqB,IAAA,qBAAa,EAAC,OAAO,CAAC,YAA3B,EAAhB,WAAW,mBAAG,EAAE,KAAA,CAA4B;wCAEvC,GAAG,EAAE,MAAI,EAAE,KAAK,EAAE,cAAc;oBAC3C,IAAI,MAAI,KAAK,SAAS,EAAE;;qBAEvB;oBAED,IAAM,IAAI,GAAG,EAAE,SAAS,WAAA,EAAE,CAAC;oBAC3B,OAAO,CAAC,MAAM,CAAC;wBACb,GAAG,wBACE,GAAG,KACN,GAAG,wBACE,GAAG,CAAC,KAAK,KACZ,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,GAAG,MAAI,CAAC,MAAM,MAEzC;wBACD,SAAS,EAAE,oCAA4B;wBACvC,IAAI,MAAA;wBACJ,OAAO,EAAE;4BACP;gCACE,SAAS,EAAE,2CAAmC;gCAC9C,IAAI,MAAA;gCACJ,GAAG,EAAE,UAAC,KAAK
|
|
1
|
+
{"version":3,"file":"use-consistent-global-store-name.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/store/use-consistent-global-store-name.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA6B;AAC7B,mDAAgD;AAChD,qCAA4C;AAE/B,QAAA,4BAA4B,GAAG,8BAA8B,CAAC;AAC9D,QAAA,mCAAmC,GAC9C,qCAAqC,CAAC;AAOxC,kBAA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AAC,EAAE,MAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,KAAK,CAAC,CAAC,CAAC,mCAAI,KAAK,CAAC,CAAC,CAAC,CAAC,EAChD,SAAS,CACV,CAAA;iCAAA;6BACJ;yBACF;qBACF,CAAC,CAAC;;;oBA3BL,KAAmD,IAAA,gBAAA,SAAA,WAAW,CAAA,wCAAA;wBAAnD,IAAA,0BAAoC,EAAlC,GAAG,SAAA,EAAE,MAAI,UAAA,EAAE,KAAK,WAAA,EAAE,cAAc,oBAAA;8CAAhC,GAAG,EAAE,MAAI,EAAE,KAAK,EAAE,cAAc;;;qBA4B5C;;;;;;;;;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { getNgRxStores } from '../../utils';\n\nexport const useConsistentGlobalStoreName = 'useConsistentGlobalStoreName';\nexport const useConsistentGlobalStoreNameSuggest =\n 'useConsistentGlobalStoreNameSuggest';\n\ntype MessageIds =\n | typeof useConsistentGlobalStoreName\n | typeof useConsistentGlobalStoreNameSuggest;\ntype Options = readonly [string];\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: 'Use a consistent name for the global store.',\n recommended: 'warn',\n suggestion: true,\n },\n schema: [\n {\n type: 'string',\n additionalProperties: false,\n },\n ],\n messages: {\n [useConsistentGlobalStoreName]:\n 'Global store should be named as `{{ storeName }}`.',\n [useConsistentGlobalStoreNameSuggest]: 'Rename it to `{{ storeName }}`.',\n },\n },\n defaultOptions: ['store'],\n create: (context, [storeName]) => {\n return {\n Program() {\n const { identifiers = [] } = getNgRxStores(context);\n\n for (const { loc, name, range, typeAnnotation } of identifiers) {\n if (name === storeName) {\n return;\n }\n\n const data = { storeName };\n context.report({\n loc: {\n ...loc,\n end: {\n ...loc.start,\n column: loc.start.column + name.length,\n },\n },\n messageId: useConsistentGlobalStoreName,\n data,\n suggest: [\n {\n messageId: useConsistentGlobalStoreNameSuggest,\n data,\n fix: (fixer) =>\n fixer.replaceTextRange(\n [range[0], typeAnnotation?.range[0] ?? range[1]],\n storeName\n ),\n },\n ],\n });\n }\n },\n };\n },\n});\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCallExpressionWith = exports.isTypeReference = exports.isIdentifierOrMemberExpression = exports.isProperty = exports.isObjectExpression = exports.isTSTypeReference = exports.isTSTypeAnnotation = exports.isTSParameterProperty = exports.isThisExpression = exports.isProgram = exports.isMemberExpression = exports.isTemplateLiteral = exports.isTemplateElement = exports.isLiteral = exports.isImportSpecifier = exports.isImportNamespaceSpecifier = exports.isImportDefaultSpecifier = exports.isImportDeclaration = exports.isIdentifier = exports.isFunctionExpression = exports.isPropertyDefinition = exports.isClassDeclaration = exports.isCallExpression = exports.isMethodDefinition = exports.isReturnStatement = exports.isArrowFunctionExpression = void 0;
|
|
3
|
+
exports.isCallExpressionWith = exports.isTypeReference = exports.isIdentifierOrMemberExpression = exports.isProperty = exports.isObjectExpression = exports.isTSInstantiationExpression = exports.isTSTypeReference = exports.isTSTypeAnnotation = exports.isTSParameterProperty = exports.isThisExpression = exports.isProgram = exports.isMemberExpression = exports.isTemplateLiteral = exports.isTemplateElement = exports.isLiteral = exports.isImportSpecifier = exports.isImportNamespaceSpecifier = exports.isImportDefaultSpecifier = exports.isImportDeclaration = exports.isIdentifier = exports.isFunctionExpression = exports.isPropertyDefinition = exports.isClassDeclaration = exports.isCallExpression = exports.isMethodDefinition = exports.isReturnStatement = exports.isArrowFunctionExpression = void 0;
|
|
4
4
|
var experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
|
5
5
|
var isNodeOfType = function (nodeType) {
|
|
6
6
|
return function (node) {
|
|
@@ -28,6 +28,7 @@ exports.isThisExpression = isNodeOfType(experimental_utils_1.AST_NODE_TYPES.This
|
|
|
28
28
|
exports.isTSParameterProperty = isNodeOfType(experimental_utils_1.AST_NODE_TYPES.TSParameterProperty);
|
|
29
29
|
exports.isTSTypeAnnotation = isNodeOfType(experimental_utils_1.AST_NODE_TYPES.TSTypeAnnotation);
|
|
30
30
|
exports.isTSTypeReference = isNodeOfType(experimental_utils_1.AST_NODE_TYPES.TSTypeReference);
|
|
31
|
+
exports.isTSInstantiationExpression = isNodeOfType(experimental_utils_1.AST_NODE_TYPES.TSInstantiationExpression);
|
|
31
32
|
exports.isObjectExpression = isNodeOfType(experimental_utils_1.AST_NODE_TYPES.ObjectExpression);
|
|
32
33
|
exports.isProperty = isNodeOfType(experimental_utils_1.AST_NODE_TYPES.Property);
|
|
33
34
|
function isIdentifierOrMemberExpression(node) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/guards.ts"],"names":[],"mappings":";;;AACA,4EAAuE;AAGvE,IAAM,YAAY,GAChB,UAAkC,QAAkB;IACpD,OAAA,UAAC,IAAmB;QAClB,OAAA,IAAI,CAAC,IAAI,KAAK,QAAQ;IAAtB,CAAsB;AADxB,CACwB,CAAC;AAEd,QAAA,yBAAyB,GAAG,YAAY,CACnD,mCAAc,CAAC,uBAAuB,CACvC,CAAC;AACW,QAAA,iBAAiB,GAAG,YAAY,CAAC,mCAAc,CAAC,eAAe,CAAC,CAAC;AACjE,QAAA,kBAAkB,GAAG,YAAY,CAAC,mCAAc,CAAC,gBAAgB,CAAC,CAAC;AACnE,QAAA,gBAAgB,GAAG,YAAY,CAAC,mCAAc,CAAC,cAAc,CAAC,CAAC;AAC/D,QAAA,kBAAkB,GAAG,YAAY,CAAC,mCAAc,CAAC,gBAAgB,CAAC,CAAC;AACnE,QAAA,oBAAoB,GAAG,YAAY,CAC9C,mCAAc,CAAC,kBAAkB,CAClC,CAAC;AACW,QAAA,oBAAoB,GAAG,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nimport type * as ts from 'typescript';\n\nconst isNodeOfType =\n <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) =>\n (node: TSESTree.Node): node is TSESTree.Node & { type: NodeType } =>\n node.type === nodeType;\n\nexport const isArrowFunctionExpression = isNodeOfType(\n AST_NODE_TYPES.ArrowFunctionExpression\n);\nexport const isReturnStatement = isNodeOfType(AST_NODE_TYPES.ReturnStatement);\nexport const isMethodDefinition = isNodeOfType(AST_NODE_TYPES.MethodDefinition);\nexport const isCallExpression = isNodeOfType(AST_NODE_TYPES.CallExpression);\nexport const isClassDeclaration = isNodeOfType(AST_NODE_TYPES.ClassDeclaration);\nexport const isPropertyDefinition = isNodeOfType(\n AST_NODE_TYPES.PropertyDefinition\n);\nexport const isFunctionExpression = isNodeOfType(\n AST_NODE_TYPES.FunctionExpression\n);\nexport const isIdentifier = isNodeOfType(AST_NODE_TYPES.Identifier);\nexport const isImportDeclaration = isNodeOfType(\n AST_NODE_TYPES.ImportDeclaration\n);\nexport const isImportDefaultSpecifier = isNodeOfType(\n AST_NODE_TYPES.ImportDefaultSpecifier\n);\nexport const isImportNamespaceSpecifier = isNodeOfType(\n AST_NODE_TYPES.ImportNamespaceSpecifier\n);\nexport const isImportSpecifier = isNodeOfType(AST_NODE_TYPES.ImportSpecifier);\nexport const isLiteral = isNodeOfType(AST_NODE_TYPES.Literal);\nexport const isTemplateElement = isNodeOfType(AST_NODE_TYPES.TemplateElement);\nexport const isTemplateLiteral = isNodeOfType(AST_NODE_TYPES.TemplateLiteral);\nexport const isMemberExpression = isNodeOfType(AST_NODE_TYPES.MemberExpression);\nexport const isProgram = isNodeOfType(AST_NODE_TYPES.Program);\nexport const isThisExpression = isNodeOfType(AST_NODE_TYPES.ThisExpression);\nexport const isTSParameterProperty = isNodeOfType(\n AST_NODE_TYPES.TSParameterProperty\n);\nexport const isTSTypeAnnotation = isNodeOfType(AST_NODE_TYPES.TSTypeAnnotation);\nexport const isTSTypeReference = isNodeOfType(AST_NODE_TYPES.TSTypeReference);\nexport const isObjectExpression = isNodeOfType(AST_NODE_TYPES.ObjectExpression);\nexport const isProperty = isNodeOfType(AST_NODE_TYPES.Property);\n\nexport function isIdentifierOrMemberExpression(\n node: TSESTree.Node\n): node is TSESTree.Identifier | TSESTree.MemberExpression {\n return isIdentifier(node) || isMemberExpression(node);\n}\n\nexport function isTypeReference(type: ts.Type): type is ts.TypeReference {\n return type.hasOwnProperty('target');\n}\n\nfunction equalTo(one: RegExp | string, other: string) {\n return typeof one === 'string' ? one === other : one.test(other);\n}\n\nexport function isCallExpressionWith(\n node: TSESTree.CallExpression,\n objectName: RegExp | string,\n propertyName: string\n) {\n return (\n isMemberExpression(node.callee) &&\n !node.callee.computed &&\n node.callee.property.name === propertyName &&\n ((isIdentifier(node.callee.object) &&\n equalTo(objectName, node.callee.object.name)) ||\n (isMemberExpression(node.callee.object) &&\n isThisExpression(node.callee.object.object) &&\n isIdentifier(node.callee.object.property) &&\n equalTo(objectName, node.callee.object.property.name)))\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/guards.ts"],"names":[],"mappings":";;;AACA,4EAAuE;AAGvE,IAAM,YAAY,GAChB,UAAkC,QAAkB;IACpD,OAAA,UAAC,IAAmB;QAClB,OAAA,IAAI,CAAC,IAAI,KAAK,QAAQ;IAAtB,CAAsB;AADxB,CACwB,CAAC;AAEd,QAAA,yBAAyB,GAAG,YAAY,CACnD,mCAAc,CAAC,uBAAuB,CACvC,CAAC;AACW,QAAA,iBAAiB,GAAG,YAAY,CAAC,mCAAc,CAAC,eAAe,CAAC,CAAC;AACjE,QAAA,kBAAkB,GAAG,YAAY,CAAC,mCAAc,CAAC,gBAAgB,CAAC,CAAC;AACnE,QAAA,gBAAgB,GAAG,YAAY,CAAC,mCAAc,CAAC,cAAc,CAAC,CAAC;AAC/D,QAAA,kBAAkB,GAAG,YAAY,CAAC,mCAAc,CAAC,gBAAgB,CAAC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,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAC5D,CAAC;AACJ,CAAC;AAhBD,oDAgBC","sourcesContent":["import type { TSESTree } from '@typescript-eslint/experimental-utils';\nimport { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';\nimport type * as ts from 'typescript';\n\nconst isNodeOfType =\n <NodeType extends AST_NODE_TYPES>(nodeType: NodeType) =>\n (node: TSESTree.Node): node is TSESTree.Node & { type: NodeType } =>\n node.type === nodeType;\n\nexport const isArrowFunctionExpression = isNodeOfType(\n AST_NODE_TYPES.ArrowFunctionExpression\n);\nexport const isReturnStatement = isNodeOfType(AST_NODE_TYPES.ReturnStatement);\nexport const isMethodDefinition = isNodeOfType(AST_NODE_TYPES.MethodDefinition);\nexport const isCallExpression = isNodeOfType(AST_NODE_TYPES.CallExpression);\nexport const isClassDeclaration = isNodeOfType(AST_NODE_TYPES.ClassDeclaration);\nexport const isPropertyDefinition = isNodeOfType(\n AST_NODE_TYPES.PropertyDefinition\n);\nexport const isFunctionExpression = isNodeOfType(\n AST_NODE_TYPES.FunctionExpression\n);\nexport const isIdentifier = isNodeOfType(AST_NODE_TYPES.Identifier);\nexport const isImportDeclaration = isNodeOfType(\n AST_NODE_TYPES.ImportDeclaration\n);\nexport const isImportDefaultSpecifier = isNodeOfType(\n AST_NODE_TYPES.ImportDefaultSpecifier\n);\nexport const isImportNamespaceSpecifier = isNodeOfType(\n AST_NODE_TYPES.ImportNamespaceSpecifier\n);\nexport const isImportSpecifier = isNodeOfType(AST_NODE_TYPES.ImportSpecifier);\nexport const isLiteral = isNodeOfType(AST_NODE_TYPES.Literal);\nexport const isTemplateElement = isNodeOfType(AST_NODE_TYPES.TemplateElement);\nexport const isTemplateLiteral = isNodeOfType(AST_NODE_TYPES.TemplateLiteral);\nexport const isMemberExpression = isNodeOfType(AST_NODE_TYPES.MemberExpression);\nexport const isProgram = isNodeOfType(AST_NODE_TYPES.Program);\nexport const isThisExpression = isNodeOfType(AST_NODE_TYPES.ThisExpression);\nexport const isTSParameterProperty = isNodeOfType(\n AST_NODE_TYPES.TSParameterProperty\n);\nexport const isTSTypeAnnotation = isNodeOfType(AST_NODE_TYPES.TSTypeAnnotation);\nexport const isTSTypeReference = isNodeOfType(AST_NODE_TYPES.TSTypeReference);\nexport const isTSInstantiationExpression = isNodeOfType(\n AST_NODE_TYPES.TSInstantiationExpression\n);\nexport const isObjectExpression = isNodeOfType(AST_NODE_TYPES.ObjectExpression);\nexport const isProperty = isNodeOfType(AST_NODE_TYPES.Property);\n\nexport function isIdentifierOrMemberExpression(\n node: TSESTree.Node\n): node is TSESTree.Identifier | TSESTree.MemberExpression {\n return isIdentifier(node) || isMemberExpression(node);\n}\n\nexport function isTypeReference(type: ts.Type): type is ts.TypeReference {\n return type.hasOwnProperty('target');\n}\n\nfunction equalTo(one: RegExp | string, other: string) {\n return typeof one === 'string' ? one === other : one.test(other);\n}\n\nexport function isCallExpressionWith(\n node: TSESTree.CallExpression,\n objectName: RegExp | string,\n propertyName: string\n) {\n return (\n isMemberExpression(node.callee) &&\n !node.callee.computed &&\n node.callee.property.name === propertyName &&\n ((isIdentifier(node.callee.object) &&\n equalTo(objectName, node.callee.object.name)) ||\n (isMemberExpression(node.callee.object) &&\n isThisExpression(node.callee.object.object) &&\n isIdentifier(node.callee.object.property) &&\n equalTo(objectName, node.callee.object.property.name)))\n );\n}\n"]}
|
|
@@ -254,23 +254,28 @@ function getInjectedParametersWithSourceCode(context, moduleName, importName) {
|
|
|
254
254
|
});
|
|
255
255
|
var identifiers = (_e = typedVariable === null || typedVariable === void 0 ? void 0 : typedVariable.references) === null || _e === void 0 ? void 0 : _e.reduce(function (identifiers, _a) {
|
|
256
256
|
var parent = _a.identifier.parent;
|
|
257
|
-
if (parent
|
|
258
|
-
|
|
257
|
+
if (!parent) {
|
|
258
|
+
return identifiers;
|
|
259
|
+
}
|
|
260
|
+
if ((0, guards_1.isTSTypeReference)(parent) &&
|
|
259
261
|
parent.parent &&
|
|
260
262
|
(0, guards_1.isTSTypeAnnotation)(parent.parent) &&
|
|
261
263
|
parent.parent.parent &&
|
|
262
264
|
(0, guards_1.isIdentifier)(parent.parent.parent)) {
|
|
263
265
|
return identifiers.concat(parent.parent.parent);
|
|
264
266
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
(0, guards_1.
|
|
271
|
-
|
|
267
|
+
var parentToCheck = (0, guards_1.isTSInstantiationExpression)(parent)
|
|
268
|
+
? parent.parent
|
|
269
|
+
: parent;
|
|
270
|
+
if (parentToCheck &&
|
|
271
|
+
(0, guards_1.isCallExpression)(parentToCheck) &&
|
|
272
|
+
(0, guards_1.isIdentifier)(parentToCheck.callee) &&
|
|
273
|
+
parentToCheck.callee.name == 'inject' &&
|
|
274
|
+
parentToCheck.parent &&
|
|
275
|
+
(0, guards_1.isPropertyDefinition)(parentToCheck.parent) &&
|
|
276
|
+
(0, guards_1.isIdentifier)(parentToCheck.parent.key) &&
|
|
272
277
|
injectImportSpecifier) {
|
|
273
|
-
return identifiers.concat(
|
|
278
|
+
return identifiers.concat(parentToCheck.parent.key);
|
|
274
279
|
}
|
|
275
280
|
return identifiers;
|
|
276
281
|
}, []);
|
|
@@ -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;AAoBnD,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;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ACpC,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"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/utils/helper-functions/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4EAAiE;AACjE,mCAkBkB;AAClB,+CAAmD;AAoBnD,SAAgB,uBAAuB,CACrC,EAAyB,EACzB,SAAiD;QAD/C,MAAM,YAAA;IAGR,OAAO,MAAM,IAAI,CAAC,IAAA,kBAAS,EAAC,MAAM,CAAC,EAAE;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,uBAA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CAAC;AARD,oDAQC;AAED,SAAgB,sBAAsB,CACpC,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,iBAAiB,CAAC,EACpC,gBAAgB,CACjB,CAAC;AACJ,CAAC;AARD,wDAQC;AAED,SAAgB,aAAa,CAC3B,OAAyD;IAEzD,OAAO,mCAAmC,CACxC,OAAO,EACP,gCAAiB,CAAC,KAAK,EACvB,OAAO,CACR,CAAC;AACJ,CAAC;AARD,sCAQC;AAED,6FAA6F;AAC7F,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC;AAFD,gCAEC;AAED,SAAgB,SAAS,CAAC,WAAyC;IACjE,IAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,EAAQ;YAAN,IAAI,UAAA;QAAO,OAAA,UAAU,CAAC,IAAI,CAAC;IAAhB,CAAgB,CAAC,CAAC;IACrE,OAAO,IAAI,MAAM,CAAC,YAAK,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,OAAI,CAAC,CAAC;AACrD,CAAC;AAHD,8BAGC","sourcesContent":["import type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ASTUtils } from '@typescript-eslint/experimental-utils';\nimport {\n isCallExpression,\n isIdentifier,\n isIdentifierOrMemberExpression,\n isImportDeclaration,\n isImportDefaultSpecifier,\n isImportNamespaceSpecifier,\n isImportSpecifier,\n isLiteral,\n isMethodDefinition,\n isProgram,\n isProperty,\n isPropertyDefinition,\n isTSTypeAnnotation,\n isTSTypeReference,\n isTemplateElement,\n isTemplateLiteral,\n isTSInstantiationExpression,\n} from './guards';\nimport { NGRX_MODULE_PATHS } from './ngrx-modules';\n\ntype ConstructorFunctionExpression = TSESTree.FunctionExpression & {\n parent: TSESTree.MethodDefinition & { kind: 'constructor' };\n};\ntype InjectedParameter =\n | TSESTree.Identifier & {\n typeAnnotation: TSESTree.TSTypeAnnotation;\n parent:\n | ConstructorFunctionExpression\n | (TSESTree.TSParameterProperty & {\n parent: ConstructorFunctionExpression;\n })\n | TSESTree.PropertyDefinition;\n };\ntype InjectedParameterWithSourceCode = Readonly<{\n identifiers?: readonly InjectedParameter[];\n sourceCode: Readonly<TSESLint.SourceCode>;\n}>;\n\nexport function getNearestUpperNodeFrom<T extends TSESTree.Node>(\n { parent }: TSESTree.Node,\n predicate: (parent: TSESTree.Node) => parent is T\n): T | undefined {\n while (parent && !isProgram(parent)) {\n if (predicate(parent)) {\n return parent;\n }\n\n parent = parent.parent;\n }\n\n return undefined;\n}\n\nexport function getImportDeclarationSpecifier(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importName: string\n) {\n for (const importDeclaration of importDeclarations) {\n const importSpecifier = importDeclaration.specifiers.find(\n (importClause): importClause is TSESTree.ImportSpecifier => {\n return (\n isImportSpecifier(importClause) &&\n importClause.imported.name === importName\n );\n }\n );\n\n if (importSpecifier) {\n return { importDeclaration, importSpecifier } as const;\n }\n }\n\n return undefined;\n}\n\nexport function getImportDeclarations(\n node: TSESTree.Node,\n moduleName: string\n): readonly TSESTree.ImportDeclaration[] | undefined {\n let parentNode: TSESTree.Node | undefined = node;\n\n while (parentNode && !isProgram(parentNode)) {\n parentNode = parentNode.parent;\n }\n\n return parentNode?.body.filter((node): node is TSESTree.ImportDeclaration => {\n return isImportDeclaration(node) && node.source.value === moduleName;\n });\n}\n\nfunction getCorrespondentImportClause(\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n compatibleWithTypeOnlyImport = false\n) {\n let importClause: TSESTree.ImportClause | undefined;\n\n for (const { importKind, specifiers } of importDeclarations) {\n const lastImportSpecifier = getLast(specifiers);\n\n if (\n (!compatibleWithTypeOnlyImport && importKind === 'type') ||\n isImportNamespaceSpecifier(lastImportSpecifier)\n ) {\n continue;\n }\n\n importClause = lastImportSpecifier;\n }\n\n return importClause;\n}\n\nexport function getImportAddFix({\n compatibleWithTypeOnlyImport = false,\n fixer,\n importName,\n moduleName,\n node,\n}: {\n compatibleWithTypeOnlyImport?: boolean;\n fixer: TSESLint.RuleFixer;\n importName: string;\n moduleName: string;\n node: TSESTree.Node;\n}): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const fullImport = `import { ${importName} } from '${moduleName}';\\n`;\n const importDeclarations = getImportDeclarations(node, moduleName);\n\n if (!importDeclarations?.length) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const importDeclarationSpecifier = getImportDeclarationSpecifier(\n importDeclarations,\n importName\n );\n\n if (importDeclarationSpecifier) {\n return [];\n }\n\n const importClause = getCorrespondentImportClause(\n importDeclarations,\n compatibleWithTypeOnlyImport\n );\n\n if (!importClause) {\n return fixer.insertTextAfterRange([0, 0], fullImport);\n }\n\n const replacementText = isImportDefaultSpecifier(importClause)\n ? `, { ${importName} }`\n : `, ${importName}`;\n return fixer.insertTextAfter(importClause, replacementText);\n}\n\nexport function getImportRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n importDeclarations: readonly TSESTree.ImportDeclaration[],\n importedName: string,\n fixer: TSESLint.RuleFixer\n): TSESLint.RuleFix | TSESLint.RuleFix[] {\n const { importDeclaration, importSpecifier } =\n getImportDeclarationSpecifier(importDeclarations, importedName) ?? {};\n\n if (!importDeclaration || !importSpecifier) {\n return [];\n }\n\n const isFirstImportSpecifier =\n importDeclaration.specifiers[0] === importSpecifier;\n const isLastImportSpecifier =\n getLast(importDeclaration.specifiers) === importSpecifier;\n const isSingleImportSpecifier =\n isFirstImportSpecifier && isLastImportSpecifier;\n\n if (isSingleImportSpecifier) {\n return fixer.remove(importDeclaration);\n }\n\n const tokenAfterImportSpecifier = sourceCode.getTokenAfter(importSpecifier);\n\n if (isFirstImportSpecifier && tokenAfterImportSpecifier) {\n return fixer.removeRange([\n importSpecifier.range[0],\n tokenAfterImportSpecifier.range[1],\n ]);\n }\n\n const tokenBeforeImportSpecifier = sourceCode.getTokenBefore(importSpecifier);\n\n if (!tokenBeforeImportSpecifier) {\n return [];\n }\n\n return fixer.removeRange([\n tokenBeforeImportSpecifier.range[0],\n importSpecifier.range[1],\n ]);\n}\n\nexport function getNodeToCommaRemoveFix(\n sourceCode: Readonly<TSESLint.SourceCode>,\n fixer: TSESLint.RuleFixer,\n node: TSESTree.Node\n) {\n const nextToken = sourceCode.getTokenAfter(node);\n const isNextTokenComma = nextToken && ASTUtils.isCommaToken(nextToken);\n return [\n fixer.remove(node),\n ...(isNextTokenComma ? [fixer.remove(nextToken)] : []),\n ] as const;\n}\n\nexport function getInterfaceName(\n interfaceMember: TSESTree.Identifier | TSESTree.MemberExpression\n): string | undefined {\n if (isIdentifier(interfaceMember)) {\n return interfaceMember.name;\n }\n\n return isIdentifier(interfaceMember.property)\n ? interfaceMember.property.name\n : undefined;\n}\n\nexport function getInterfaces({\n implements: classImplements,\n}: TSESTree.ClassDeclaration): readonly (\n | TSESTree.Identifier\n | TSESTree.MemberExpression\n)[] {\n return (classImplements ?? [])\n .map(({ expression }) => expression)\n .filter(isIdentifierOrMemberExpression);\n}\n\nexport function getInterface(\n node: TSESTree.ClassDeclaration,\n interfaceName: string\n): TSESTree.Identifier | TSESTree.MemberExpression | undefined {\n return getInterfaces(node).find(\n (interfaceMember) => getInterfaceName(interfaceMember) === interfaceName\n );\n}\n\nexport function getImplementsSchemaFixer(\n { id, implements: classImplements }: TSESTree.ClassDeclaration,\n interfaceName: string\n) {\n const [implementsNodeReplace, implementsTextReplace] = 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 (!parent) {\n return identifiers;\n }\n\n if (\n isTSTypeReference(parent) &&\n parent.parent &&\n isTSTypeAnnotation(parent.parent) &&\n parent.parent.parent &&\n isIdentifier(parent.parent.parent)\n ) {\n return identifiers.concat(parent.parent.parent as InjectedParameter);\n }\n\n const parentToCheck = isTSInstantiationExpression(parent)\n ? parent.parent\n : parent;\n\n if (\n parentToCheck &&\n isCallExpression(parentToCheck) &&\n isIdentifier(parentToCheck.callee) &&\n parentToCheck.callee.name == 'inject' &&\n parentToCheck.parent &&\n isPropertyDefinition(parentToCheck.parent) &&\n isIdentifier(parentToCheck.parent.key) &&\n injectImportSpecifier\n ) {\n return identifiers.concat(parentToCheck.parent.key as InjectedParameter);\n }\n\n return identifiers;\n }, []);\n return { identifiers, sourceCode };\n}\n\nexport function getNgRxEffectActions(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.effects,\n 'Actions'\n );\n}\n\nexport function getNgRxComponentStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS['component-store'],\n 'ComponentStore'\n );\n}\n\nexport function getNgRxStores(\n context: TSESLint.RuleContext<string, readonly unknown[]>\n): InjectedParameterWithSourceCode {\n return getInjectedParametersWithSourceCode(\n context,\n NGRX_MODULE_PATHS.store,\n 'Store'\n );\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#escaping\nexport function escapeText(text: string): string {\n return text.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n}\n\nexport function asPattern(identifiers: readonly InjectedParameter[]): RegExp {\n const escapedNames = identifiers.map(({ name }) => escapeText(name));\n return new RegExp(`^(${escapedNames.join('|')})$`);\n}\n"]}
|