@angular-eslint/eslint-plugin 22.5.1-alpha.29 → 22.5.1-alpha.30
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefer-signal-model.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-signal-model.ts"],"names":[],"mappings":"AASA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvE,KAAK,OAAO,GAAG;IACb;QACE,eAAe,EAAE,OAAO,CAAC;KAC1B;CACF,CAAC;AAMF,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAC7C,eAAO,MAAM,SAAS,wBAAwB,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"prefer-signal-model.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-signal-model.ts"],"names":[],"mappings":"AASA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvE,KAAK,OAAO,GAAG;IACb;QACE,eAAe,EAAE,OAAO,CAAC;KAC1B;CACF,CAAC;AAMF,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAC7C,eAAO,MAAM,SAAS,wBAAwB,CAAC;;;;AA+C/C,wBAiMG;AAEH,eAAO,MAAM,mBAAmB;;CAG/B,CAAC"}
|
|
@@ -12,6 +12,18 @@ const DEFAULT_OPTIONS = {
|
|
|
12
12
|
useTypeChecking: false,
|
|
13
13
|
};
|
|
14
14
|
exports.RULE_NAME = 'prefer-signal-model';
|
|
15
|
+
function getEmitCallee(reference) {
|
|
16
|
+
const { parent } = reference;
|
|
17
|
+
return parent?.type === utils_2.AST_NODE_TYPES.MemberExpression &&
|
|
18
|
+
parent.object === reference &&
|
|
19
|
+
!parent.computed &&
|
|
20
|
+
parent.property.type === utils_2.AST_NODE_TYPES.Identifier &&
|
|
21
|
+
parent.property.name === 'emit' &&
|
|
22
|
+
parent.parent?.type === utils_2.AST_NODE_TYPES.CallExpression &&
|
|
23
|
+
parent.parent.callee === parent
|
|
24
|
+
? parent
|
|
25
|
+
: undefined;
|
|
26
|
+
}
|
|
15
27
|
function hasTransformOption(options) {
|
|
16
28
|
return (options?.type === utils_2.AST_NODE_TYPES.ObjectExpression &&
|
|
17
29
|
options.properties.some((property) => property.type === utils_2.AST_NODE_TYPES.Property &&
|
|
@@ -49,6 +61,7 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
49
61
|
const { sourceCode } = context;
|
|
50
62
|
const inputs = new Map();
|
|
51
63
|
const outputs = new Map();
|
|
64
|
+
const thisReferences = new Map();
|
|
52
65
|
let services;
|
|
53
66
|
function getTypeServices() {
|
|
54
67
|
return (services ??= utils_2.ESLintUtils.getParserServices(context));
|
|
@@ -114,32 +127,49 @@ exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
|
114
127
|
"PropertyDefinition > CallExpression[callee.name='input']": createSignalCollector(inputs, { hasInitialValueArgument: true }),
|
|
115
128
|
"PropertyDefinition > CallExpression[callee.object.name='input'][callee.property.name='required']": createSignalCollector(inputs, { hasInitialValueArgument: false }),
|
|
116
129
|
"PropertyDefinition > CallExpression[callee.name='output']": createSignalCollector(outputs, { hasInitialValueArgument: false }),
|
|
130
|
+
'MemberExpression[object.type="ThisExpression"][computed=false][property.type="Identifier"]'(node) {
|
|
131
|
+
const { name } = node.property;
|
|
132
|
+
const references = thisReferences.get(name);
|
|
133
|
+
if (references) {
|
|
134
|
+
references.push(node);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
thisReferences.set(name, [node]);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
117
140
|
'ClassDeclaration:exit'() {
|
|
118
141
|
const twoWayBindings = [...inputs]
|
|
119
142
|
.map(([name, input]) => ({
|
|
143
|
+
name,
|
|
120
144
|
input,
|
|
121
145
|
output: outputs.get(`${name}Change`),
|
|
122
146
|
}))
|
|
123
147
|
.filter((binding) => binding.output !== undefined &&
|
|
124
148
|
haveMergeableTypes(binding.input, binding.output));
|
|
125
|
-
for (const { input, output } of twoWayBindings) {
|
|
149
|
+
for (const { name, input, output } of twoWayBindings) {
|
|
150
|
+
const emitCallees = (thisReferences.get(`${name}Change`) ?? []).map(getEmitCallee);
|
|
151
|
+
const isRewritable = emitCallees.every(utils_1.isNotNullOrUndefined);
|
|
126
152
|
context.report({
|
|
127
153
|
node: input.property,
|
|
128
154
|
messageId: 'preferSignalModel',
|
|
129
|
-
fix:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
155
|
+
fix: isRewritable
|
|
156
|
+
? (fixer) => [
|
|
157
|
+
utils_1.RuleFixes.getImportAddFix({
|
|
158
|
+
fixer,
|
|
159
|
+
importName: 'model',
|
|
160
|
+
moduleName: '@angular/core',
|
|
161
|
+
node: input.property,
|
|
162
|
+
}),
|
|
163
|
+
fixer.replaceText(input.callee, 'model'),
|
|
164
|
+
fixer.remove(output.property),
|
|
165
|
+
...emitCallees.map((callee) => fixer.replaceText(callee, `this.${name}.set`)),
|
|
166
|
+
].filter(utils_1.isNotNullOrUndefined)
|
|
167
|
+
: undefined,
|
|
139
168
|
});
|
|
140
169
|
}
|
|
141
170
|
inputs.clear();
|
|
142
171
|
outputs.clear();
|
|
172
|
+
thisReferences.clear();
|
|
143
173
|
},
|
|
144
174
|
};
|
|
145
175
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin",
|
|
3
|
-
"version": "22.5.1-alpha.
|
|
3
|
+
"version": "22.5.1-alpha.30",
|
|
4
4
|
"description": "ESLint plugin for Angular applications, following https://angular.dev/style-guide",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@angular-eslint/bundled-angular-compiler": "22.5.1-alpha.
|
|
23
|
-
"@angular-eslint/utils": "22.5.1-alpha.
|
|
22
|
+
"@angular-eslint/bundled-angular-compiler": "22.5.1-alpha.30",
|
|
23
|
+
"@angular-eslint/utils": "22.5.1-alpha.30",
|
|
24
24
|
"ts-api-utils": "^2.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@angular-eslint/test-utils": "22.5.1-alpha.
|
|
27
|
+
"@angular-eslint/test-utils": "22.5.1-alpha.30"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@typescript-eslint/utils": "^8.0.0",
|