@ngrx/eslint-plugin 19.1.0 → 19.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Rule } from '@angular-devkit/schematics';
|
|
2
2
|
import type { Schema } from './schema';
|
|
3
|
-
export
|
|
3
|
+
export declare const possibleFlatConfigPaths: string[];
|
|
4
|
+
export default function (schema: Schema): Rule;
|
|
@@ -1,63 +1,194 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
39
|
+
exports.possibleFlatConfigPaths = void 0;
|
|
40
|
+
exports.default = default_1;
|
|
7
41
|
const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
|
|
8
|
-
|
|
42
|
+
const ts = __importStar(require("typescript"));
|
|
43
|
+
exports.possibleFlatConfigPaths = [
|
|
44
|
+
'eslint.config.js',
|
|
45
|
+
'eslint.config.mjs',
|
|
46
|
+
'eslint.config.cjs',
|
|
47
|
+
];
|
|
48
|
+
function default_1(schema) {
|
|
9
49
|
return (host, context) => {
|
|
10
|
-
const
|
|
50
|
+
const jsonConfigPath = '.eslintrc.json';
|
|
51
|
+
const flatConfigPath = exports.possibleFlatConfigPaths.find((path) => host.exists(path));
|
|
11
52
|
const docs = 'https://ngrx.io/guide/eslint-plugin';
|
|
12
|
-
|
|
13
|
-
|
|
53
|
+
if (flatConfigPath) {
|
|
54
|
+
updateFlatConfig(host, context, flatConfigPath, schema, docs);
|
|
55
|
+
return host;
|
|
56
|
+
}
|
|
57
|
+
if (!host.exists(jsonConfigPath)) {
|
|
14
58
|
context.logger.warn(`
|
|
15
|
-
Could not find
|
|
59
|
+
Could not find an ESLint config at any of ${exports.possibleFlatConfigPaths.join(', ')} or \`${jsonConfigPath}\`.
|
|
16
60
|
The NgRx ESLint Plugin is installed but not configured.
|
|
17
|
-
|
|
18
61
|
Please see ${docs} to configure the NgRx ESLint Plugin.
|
|
19
|
-
`);
|
|
62
|
+
`);
|
|
20
63
|
return host;
|
|
21
64
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
65
|
+
updateJsonConfig(host, context, jsonConfigPath, schema, docs);
|
|
66
|
+
return host;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function updateFlatConfig(host, context, flatConfigPath, schema, docs) {
|
|
70
|
+
const ngrxPlugin = '@ngrx/eslint-plugin/v9';
|
|
71
|
+
const content = host.read(flatConfigPath)?.toString('utf-8');
|
|
72
|
+
if (!content) {
|
|
73
|
+
context.logger.error(`Could not read the ESLint flat config at \`${flatConfigPath}\`.`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (content.includes(ngrxPlugin)) {
|
|
77
|
+
context.logger.info(`Skipping installation, the NgRx ESLint Plugin is already installed in your flat config.`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!content.includes('tseslint.config')) {
|
|
81
|
+
context.logger.warn(`No tseslint found, skipping the installation of the NgRx ESLint Plugin in your flat config.`);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const source = ts.createSourceFile(flatConfigPath, content, ts.ScriptTarget.Latest, true);
|
|
85
|
+
const recorder = host.beginUpdate(flatConfigPath);
|
|
86
|
+
addImport();
|
|
87
|
+
addNgRxPlugin();
|
|
88
|
+
host.commitUpdate(recorder);
|
|
89
|
+
context.logger.info(`
|
|
90
|
+
The NgRx ESLint Plugin is installed and configured using the '${schema.config}' configuration in your flat config.
|
|
91
|
+
See ${docs} for more details.
|
|
92
|
+
`);
|
|
93
|
+
function addImport() {
|
|
94
|
+
const isESM = content.includes('export default');
|
|
95
|
+
if (isESM) {
|
|
96
|
+
const lastImport = source.statements
|
|
97
|
+
.filter((statement) => ts.isImportDeclaration(statement))
|
|
98
|
+
.reverse()[0];
|
|
99
|
+
recorder.insertRight(lastImport?.end ?? 0, `\nimport ngrx from '${ngrxPlugin}';`);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const lastRequireVariableDeclaration = source.statements
|
|
103
|
+
.filter((statement) => {
|
|
104
|
+
if (!ts.isVariableStatement(statement))
|
|
105
|
+
return false;
|
|
106
|
+
const decl = statement.declarationList.declarations[0];
|
|
107
|
+
if (!decl.initializer)
|
|
108
|
+
return false;
|
|
109
|
+
return (ts.isCallExpression(decl.initializer) &&
|
|
110
|
+
decl.initializer.expression.getText() === 'require');
|
|
111
|
+
})
|
|
112
|
+
.reverse()[0];
|
|
113
|
+
recorder.insertRight(lastRequireVariableDeclaration?.end ?? 0, `\nconst ngrx = require('${ngrxPlugin}');`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function addNgRxPlugin() {
|
|
117
|
+
let tseslintConfigCall = null;
|
|
118
|
+
function findTsEslintConfigCalls(node) {
|
|
119
|
+
if (tseslintConfigCall) {
|
|
120
|
+
return;
|
|
28
121
|
}
|
|
29
|
-
|
|
30
|
-
|
|
122
|
+
if (ts.isCallExpression(node) &&
|
|
123
|
+
node.expression.getText() === 'tseslint.config') {
|
|
124
|
+
tseslintConfigCall = node;
|
|
31
125
|
}
|
|
32
|
-
|
|
33
|
-
context.logger.info(`
|
|
34
|
-
The NgRx ESLint Plugin is installed and configured with the '${schema.config}' config.
|
|
35
|
-
|
|
36
|
-
Take a look at the docs at ${docs} if you want to change the default configuration.
|
|
37
|
-
`);
|
|
38
|
-
return host;
|
|
126
|
+
ts.forEachChild(node, findTsEslintConfigCalls);
|
|
39
127
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
128
|
+
findTsEslintConfigCalls(source);
|
|
129
|
+
if (tseslintConfigCall) {
|
|
130
|
+
tseslintConfigCall = tseslintConfigCall;
|
|
131
|
+
const lastArgument = tseslintConfigCall.arguments[tseslintConfigCall.arguments.length - 1];
|
|
132
|
+
const plugin = ` {
|
|
133
|
+
files: ['**/*.ts'],
|
|
134
|
+
extends: [
|
|
135
|
+
...ngrx.configs.${schema.config},
|
|
136
|
+
],
|
|
137
|
+
rules: {},
|
|
138
|
+
}`;
|
|
139
|
+
if (lastArgument) {
|
|
140
|
+
recorder.remove(lastArgument.pos, lastArgument.end - lastArgument.pos);
|
|
141
|
+
recorder.insertRight(lastArgument.pos, `${lastArgument.getFullText()},\n${plugin}`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
recorder.insertRight(tseslintConfigCall.end - 1, `\n${plugin}\n`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function updateJsonConfig(host, context, jsonConfigPath, schema, docs) {
|
|
150
|
+
const eslint = host.read(jsonConfigPath)?.toString('utf-8');
|
|
151
|
+
if (!eslint) {
|
|
152
|
+
context.logger.error(`
|
|
153
|
+
Could not find the ESLint config at \`${jsonConfigPath}\`.
|
|
154
|
+
The NgRx ESLint Plugin is installed but not configured.
|
|
155
|
+
Please see ${docs} to configure the NgRx ESLint Plugin.
|
|
156
|
+
`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const json = JSON.parse((0, strip_json_comments_1.default)(eslint));
|
|
161
|
+
const plugin = {
|
|
162
|
+
files: ['*.ts'],
|
|
163
|
+
extends: [`plugin:@ngrx/${schema.config}`],
|
|
164
|
+
};
|
|
165
|
+
if (json.overrides) {
|
|
166
|
+
if (!json.overrides.some((override) => override.extends?.some((extend) => extend.startsWith('plugin:@ngrx')))) {
|
|
167
|
+
json.overrides.push(plugin);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (!json.extends?.some((extend) => extend.startsWith('plugin:@ngrx'))) {
|
|
171
|
+
json.overrides = [plugin];
|
|
172
|
+
}
|
|
173
|
+
host.overwrite(jsonConfigPath, JSON.stringify(json, null, 2));
|
|
174
|
+
context.logger.info(`
|
|
175
|
+
The NgRx ESLint Plugin is installed and configured with the '${schema.config}' config.
|
|
176
|
+
Take a look at the docs at ${docs} if you want to change the default configuration.
|
|
177
|
+
`);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
const detailsContent = err instanceof Error
|
|
181
|
+
? `
|
|
43
182
|
Details:
|
|
44
183
|
${err.message}
|
|
45
184
|
`
|
|
46
|
-
|
|
47
|
-
|
|
185
|
+
: '';
|
|
186
|
+
context.logger.warn(`
|
|
48
187
|
Something went wrong while adding the NgRx ESLint Plugin.
|
|
49
188
|
The NgRx ESLint Plugin is installed but not configured.
|
|
50
|
-
|
|
51
189
|
Please see ${docs} to configure the NgRx ESLint Plugin.
|
|
52
190
|
${detailsContent}
|
|
53
191
|
`);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
function configurePlugin(config) {
|
|
57
|
-
return {
|
|
58
|
-
files: ['*.ts'],
|
|
59
|
-
extends: [`plugin:@ngrx/${config}`],
|
|
60
|
-
};
|
|
61
192
|
}
|
|
62
193
|
}
|
|
63
194
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/eslint-plugin/schematics/ng-add/index.ts"],"names":[],"mappings":";;;;;AAIA,sCAiEC;AApED,8EAAoD;AAGpD,SAAwB,mBAAmB,CAAC,MAAc;IACxD,OAAO,CAAC,IAAU,EAAE,OAAyB,EAAE,EAAE;QAC/C,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;QAC1C,MAAM,IAAI,GAAG,qCAAqC,CAAC;QAEnD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9D,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;wCACc,gBAAgB;;;aAG3C,IAAI;CAChB,CAAC,CAAC;YACG,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CA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AM,CAAC;YACf,OAAO,EAAE,CAAC,gBAAgB,MAAM,EAAE,CAAC;SACpC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport stripJsonComments from 'strip-json-comments';\nimport type { Schema } from './schema';\n\nexport default function addNgRxESLintPlugin(schema: Schema): Rule {\n return (host: Tree, context: SchematicContext) => {\n const eslintConfigPath = '.eslintrc.json';\n const docs = 'https://ngrx.io/guide/eslint-plugin';\n\n const eslint = host.read(eslintConfigPath)?.toString('utf-8');\n if (!eslint) {\n context.logger.warn(`\nCould not find the ESLint config at \\`${eslintConfigPath}\\`.\nThe NgRx ESLint Plugin is installed but not configured.\n\nPlease see ${docs} to configure the NgRx ESLint Plugin.\n`);\n return host;\n }\n\n try {\n const json = JSON.parse(stripJsonComments(eslint));\n if (json.overrides) {\n if (\n !json.overrides.some((override: any) =>\n override.extends?.some((extend: any) =>\n extend.startsWith('plugin:@ngrx')\n )\n )\n ) {\n json.overrides.push(configurePlugin(schema.config));\n }\n } else if (\n !json.extends?.some((extend: any) => extend.startsWith('plugin:@ngrx'))\n ) {\n json.overrides = [configurePlugin(schema.config)];\n }\n\n host.overwrite(eslintConfigPath, JSON.stringify(json, null, 2));\n\n context.logger.info(`\n The NgRx ESLint Plugin is installed and configured with the '${schema.config}' config.\n\n Take a look at the docs at ${docs} if you want to change the default configuration.\n `);\n return host;\n } catch (err) {\n const detailsContent =\n err instanceof Error\n ? `\nDetails:\n${err.message}\n`\n : '';\n context.logger.warn(`\nSomething went wrong while adding the NgRx ESLint Plugin.\nThe NgRx ESLint Plugin is installed but not configured.\n\nPlease see ${docs} to configure the NgRx ESLint Plugin.\n${detailsContent}\n`);\n }\n };\n function configurePlugin(config: Schema['config']): Record<string, unknown> {\n return {\n files: ['*.ts'],\n extends: [`plugin:@ngrx/${config}`],\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../modules/esl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AAI,CAAC,CAAC,MAAW,EAAE,EAAE,CACrC,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAClC,CACF,EACD,CAAC;gBACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;aAAM,IACL,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,MAAW,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,EACvE,CAAC;YACD,IAAI,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAE9D,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;+DACuC,MAAM,CAAC,MAAM;6BAC/C,IAAI;CAChC,CAAC,CAAC;IACD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,cAAc,GAClB,GAAG,YAAY,KAAK;YAClB,CAAC,CAAC;;EAER,GAAG,CAAC,OAAO;CACZ;YACO,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;;;aAGX,IAAI;EACf,cAAc;CACf,CAAC,CAAC;IACD,CAAC;AACH,CAAC","sourcesContent":["import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';\nimport stripJsonComments from 'strip-json-comments';\nimport type { Schema } from './schema';\nimport * as ts from 'typescript';\n\nexport const possibleFlatConfigPaths = [\n 'eslint.config.js',\n 'eslint.config.mjs',\n 'eslint.config.cjs',\n];\n\nexport default function (schema: Schema): Rule {\n return (host: Tree, context: SchematicContext) => {\n const jsonConfigPath = '.eslintrc.json';\n const flatConfigPath = possibleFlatConfigPaths.find((path) =>\n host.exists(path)\n );\n const docs = 'https://ngrx.io/guide/eslint-plugin';\n\n if (flatConfigPath) {\n updateFlatConfig(host, context, flatConfigPath, schema, docs);\n return host;\n }\n\n if (!host.exists(jsonConfigPath)) {\n context.logger.warn(`\nCould not find an ESLint config at any of ${possibleFlatConfigPaths.join(\n ', '\n )} or \\`${jsonConfigPath}\\`.\nThe NgRx ESLint Plugin is installed but not configured.\nPlease see ${docs} to configure the NgRx ESLint Plugin.\n `);\n return host;\n }\n\n updateJsonConfig(host, context, jsonConfigPath, schema, docs);\n return host;\n };\n}\n\nfunction updateFlatConfig(\n host: Tree,\n context: SchematicContext,\n flatConfigPath: string,\n schema: Schema,\n docs: string\n): void {\n const ngrxPlugin = '@ngrx/eslint-plugin/v9';\n const content = host.read(flatConfigPath)?.toString('utf-8');\n if (!content) {\n context.logger.error(\n `Could not read the ESLint flat config at \\`${flatConfigPath}\\`.`\n );\n return;\n }\n\n if (content.includes(ngrxPlugin)) {\n context.logger.info(\n `Skipping installation, the NgRx ESLint Plugin is already installed in your flat config.`\n );\n return;\n }\n\n if (!content.includes('tseslint.config')) {\n context.logger.warn(\n `No tseslint found, skipping the installation of the NgRx ESLint Plugin in your flat config.`\n );\n return;\n }\n\n const source = ts.createSourceFile(\n flatConfigPath,\n content,\n ts.ScriptTarget.Latest,\n true\n );\n\n const recorder = host.beginUpdate(flatConfigPath);\n addImport();\n addNgRxPlugin();\n\n host.commitUpdate(recorder);\n context.logger.info(`\nThe NgRx ESLint Plugin is installed and configured using the '${schema.config}' configuration in your flat config.\nSee ${docs} for more details.\n `);\n\n function addImport() {\n const isESM = content!.includes('export default');\n if (isESM) {\n const lastImport = source.statements\n .filter((statement) => ts.isImportDeclaration(statement))\n .reverse()[0];\n recorder.insertRight(\n lastImport?.end ?? 0,\n `\\nimport ngrx from '${ngrxPlugin}';`\n );\n } else {\n const lastRequireVariableDeclaration = source.statements\n .filter((statement) => {\n if (!ts.isVariableStatement(statement)) return false;\n const decl = statement.declarationList.declarations[0];\n if (!decl.initializer) return false;\n return (\n ts.isCallExpression(decl.initializer) &&\n decl.initializer.expression.getText() === 'require'\n );\n })\n .reverse()[0];\n\n recorder.insertRight(\n lastRequireVariableDeclaration?.end ?? 0,\n `\\nconst ngrx = require('${ngrxPlugin}');`\n );\n }\n }\n\n function addNgRxPlugin() {\n let tseslintConfigCall: ts.CallExpression | null = null;\n function findTsEslintConfigCalls(node: ts.Node) {\n if (tseslintConfigCall) {\n return;\n }\n\n if (\n ts.isCallExpression(node) &&\n node.expression.getText() === 'tseslint.config'\n ) {\n tseslintConfigCall = node;\n }\n ts.forEachChild(node, findTsEslintConfigCalls);\n }\n findTsEslintConfigCalls(source);\n\n if (tseslintConfigCall) {\n tseslintConfigCall = tseslintConfigCall as ts.CallExpression;\n const lastArgument =\n tseslintConfigCall.arguments[tseslintConfigCall.arguments.length - 1];\n const plugin = ` {\n files: ['**/*.ts'],\n extends: [\n ...ngrx.configs.${schema.config},\n ],\n rules: {},\n }`;\n\n if (lastArgument) {\n recorder.remove(lastArgument.pos, lastArgument.end - lastArgument.pos);\n recorder.insertRight(\n lastArgument.pos,\n `${lastArgument.getFullText()},\\n${plugin}`\n );\n } else {\n recorder.insertRight(tseslintConfigCall.end - 1, `\\n${plugin}\\n`);\n }\n }\n }\n}\n\nfunction updateJsonConfig(\n host: Tree,\n context: SchematicContext,\n jsonConfigPath: string,\n schema: Schema,\n docs: string\n): void {\n const eslint = host.read(jsonConfigPath)?.toString('utf-8');\n if (!eslint) {\n context.logger.error(`\nCould not find the ESLint config at \\`${jsonConfigPath}\\`.\nThe NgRx ESLint Plugin is installed but not configured.\nPlease see ${docs} to configure the NgRx ESLint Plugin.\n`);\n return;\n }\n\n try {\n const json = JSON.parse(stripJsonComments(eslint));\n const plugin = {\n files: ['*.ts'],\n extends: [`plugin:@ngrx/${schema.config}`],\n };\n if (json.overrides) {\n if (\n !json.overrides.some((override: any) =>\n override.extends?.some((extend: any) =>\n extend.startsWith('plugin:@ngrx')\n )\n )\n ) {\n json.overrides.push(plugin);\n }\n } else if (\n !json.extends?.some((extend: any) => extend.startsWith('plugin:@ngrx'))\n ) {\n json.overrides = [plugin];\n }\n\n host.overwrite(jsonConfigPath, JSON.stringify(json, null, 2));\n\n context.logger.info(`\nThe NgRx ESLint Plugin is installed and configured with the '${schema.config}' config.\nTake a look at the docs at ${docs} if you want to change the default configuration.\n`);\n } catch (err) {\n const detailsContent =\n err instanceof Error\n ? `\nDetails:\n${err.message}\n`\n : '';\n context.logger.warn(`\nSomething went wrong while adding the NgRx ESLint Plugin.\nThe NgRx ESLint Plugin is installed but not configured.\nPlease see ${docs} to configure the NgRx ESLint Plugin.\n${detailsContent}\n`);\n }\n}\n"]}
|
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
36
|
exports.messageId = void 0;
|
|
4
|
-
const path = require("path");
|
|
37
|
+
const path = __importStar(require("path"));
|
|
5
38
|
const rule_creator_1 = require("../../rule-creator");
|
|
6
39
|
exports.messageId = 'requireSuperOnDestroy';
|
|
7
40
|
exports.default = (0, rule_creator_1.createRule)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-super-ondestroy.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/component-store/require-super-ondestroy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"require-super-ondestroy.js","sourceRoot":"","sources":["../../../../../../modules/eslint-plugin/src/rules/component-store/require-super-ondestroy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,qDAAgD;AAGnC,QAAA,SAAS,GAAG,uBAAuB,CAAC;AAIjD,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,EACT,yFAAyF;SAC5F;QACD,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE;YACR,CAAC,iBAAS,CAAC,EACT,yEAAyE;SAC5E;KACF;IACD,cAAc,EAAE,EAAE;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE;QAClB,MAAM,yBAAyB,GAAG,0CAA0C,CAAC;QAC7E,MAAM,uBAAuB,GAAG,gBAAgB,CAAC;QAEjD,IAAI,2BAA2B,GAAG,KAAK,CAAC;QAExC,OAAO;YACL,CAAC,0FAA0F,uBAAuB,IAAI,CAAC,CACrH,CAA2B;gBAE3B,2BAA2B,GAAG,IAAI,CAAC;YACrC,CAAC;YACD,CAAC,oCAAoC,uBAAuB,KAAK,yBAAyB,mGAAmG,CAAC,CAC5L,IAAyB;gBAEzB,IAAI,CAAC,2BAA2B,EAAE,CAAC;oBACjC,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,MAAM,CAAC;oBACb,IAAI;oBACJ,SAAS,EAAT,iBAAS;iBACV,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC","sourcesContent":["import * as path from 'path';\nimport { createRule } from '../../rule-creator';\nimport { TSESTree } from '@typescript-eslint/types';\n\nexport const messageId = 'requireSuperOnDestroy';\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:\n 'Overriden ngOnDestroy method in component stores require a call to super.ngOnDestroy().',\n },\n schema: [],\n messages: {\n [messageId]:\n \"Call super.ngOnDestroy() inside a component store's ngOnDestroy method.\",\n },\n },\n defaultOptions: [],\n create: (context) => {\n const ngOnDestroyMethodSelector = `MethodDefinition[key.name='ngOnDestroy']`;\n const componentStoreClassName = 'ComponentStore';\n\n let hasNgrxComponentStoreImport = false;\n\n return {\n [`ImportDeclaration[source.value='@ngrx/component-store'] ImportSpecifier[imported.name='${componentStoreClassName}']`](\n _: TSESTree.ImportSpecifier\n ) {\n hasNgrxComponentStoreImport = true;\n },\n [`ClassDeclaration[superClass.name=${componentStoreClassName}] ${ngOnDestroyMethodSelector}:not(:has(CallExpression[callee.object.type='Super'][callee.property.name='ngOnDestroy'])) > .key`](\n node: TSESTree.Identifier\n ) {\n if (!hasNgrxComponentStoreImport) {\n return;\n }\n\n context.report({\n node,\n messageId,\n });\n },\n };\n },\n});\n"]}
|