@virmator/lint 14.29.0 → 14.29.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.
@@ -14,13 +14,13 @@ function isInlineCallbackArgument(node) {
14
14
  return parent.arguments.includes(node);
15
15
  }
16
16
  /**
17
- * The typescript-eslint parser emits `TSParameterProperty` nodes for constructor parameters that
18
- * use an accessibility (`public`/`private`/`protected`) or `readonly` modifier. These are absent
19
- * from the base estree `Pattern` union. Such parameters declare class fields rather than plain
20
- * positional arguments, so the rule ignores them when counting/comparing parameters.
17
+ * Class constructors are exempt: they can declare class fields through parameter properties and
18
+ * their signatures are constrained by `super()` calls in subclasses, so a params object is not
19
+ * always an available refactor.
21
20
  */
22
- function isParameterProperty(param) {
23
- return param.type === 'TSParameterProperty';
21
+ function isClassConstructor(node) {
22
+ const parent = node.parent;
23
+ return parent?.type === 'MethodDefinition' && parent.kind === 'constructor';
24
24
  }
25
25
  /**
26
26
  * Excludes a leading `this` parameter (which is a type-only annotation in TypeScript, not a real
@@ -115,36 +115,22 @@ const rule = {
115
115
  create(context) {
116
116
  const sourceCode = context.sourceCode;
117
117
  function check(node) {
118
- if (isInlineCallbackArgument(node)) {
118
+ if (isInlineCallbackArgument(node) || isClassConstructor(node)) {
119
119
  return;
120
120
  }
121
121
  const realParams = getRealParams(node.params);
122
- /**
123
- * Constructor parameter properties (those with an access modifier) declare class fields
124
- * rather than plain positional arguments, so they are excluded from the count and
125
- * duplicate-type comparison.
126
- */
127
- const consideredParams = realParams.filter((param) => !isParameterProperty(param));
128
- const messageId = consideredParams.length > 3
122
+ const messageId = realParams.length > 3
129
123
  ? 'tooManyPositionalParams'
130
- : hasDuplicateType(consideredParams, sourceCode)
124
+ : hasDuplicateType(realParams, sourceCode)
131
125
  ? 'duplicateParamType'
132
126
  : undefined;
133
127
  if (!messageId) {
134
128
  return;
135
129
  }
136
- /**
137
- * A params object can only wrap the plain parameters. When parameter properties are
138
- * interspersed there is no safe single-range replacement, so the fix is omitted and the
139
- * developer resolves it manually.
140
- */
141
- const fix = consideredParams.length === realParams.length
142
- ? buildParamsObjectFix(consideredParams, sourceCode)
143
- : undefined;
144
130
  context.report({
145
131
  node,
146
132
  messageId,
147
- fix: fix ?? null,
133
+ fix: buildParamsObjectFix(realParams, sourceCode) ?? null,
148
134
  });
149
135
  }
150
136
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virmator/lint",
3
- "version": "14.29.0",
3
+ "version": "14.29.1",
4
4
  "description": "Default ESLint linting plugin for virmator.",
5
5
  "keywords": [
6
6
  "virmator",
@@ -35,7 +35,7 @@
35
35
  "@augment-vir/assert": "^32.1.0",
36
36
  "@augment-vir/common": "^32.1.0",
37
37
  "@augment-vir/node": "^32.1.0",
38
- "@virmator/core": "^14.29.0",
38
+ "@virmator/core": "^14.29.1",
39
39
  "globals": "^17.7.0",
40
40
  "jiti": "^2.7.0",
41
41
  "mri": "^1.2.0"
@@ -46,13 +46,14 @@ function isInlineCallbackArgument(node: AnyFunctionNode): boolean {
46
46
  }
47
47
 
48
48
  /**
49
- * The typescript-eslint parser emits `TSParameterProperty` nodes for constructor parameters that
50
- * use an accessibility (`public`/`private`/`protected`) or `readonly` modifier. These are absent
51
- * from the base estree `Pattern` union. Such parameters declare class fields rather than plain
52
- * positional arguments, so the rule ignores them when counting/comparing parameters.
49
+ * Class constructors are exempt: they can declare class fields through parameter properties and
50
+ * their signatures are constrained by `super()` calls in subclasses, so a params object is not
51
+ * always an available refactor.
53
52
  */
54
- function isParameterProperty(param: Pattern): boolean {
55
- return (param as {type: string}).type === 'TSParameterProperty';
53
+ function isClassConstructor(node: AnyFunctionNode): boolean {
54
+ const parent = (node as Rule.Node).parent;
55
+
56
+ return parent?.type === 'MethodDefinition' && parent.kind === 'constructor';
56
57
  }
57
58
 
58
59
  /**
@@ -186,22 +187,16 @@ const rule: Rule.RuleModule = {
186
187
  const sourceCode = context.sourceCode;
187
188
 
188
189
  function check(node: AnyFunctionNode) {
189
- if (isInlineCallbackArgument(node)) {
190
+ if (isInlineCallbackArgument(node) || isClassConstructor(node)) {
190
191
  return;
191
192
  }
192
193
 
193
194
  const realParams = getRealParams(node.params);
194
- /**
195
- * Constructor parameter properties (those with an access modifier) declare class fields
196
- * rather than plain positional arguments, so they are excluded from the count and
197
- * duplicate-type comparison.
198
- */
199
- const consideredParams = realParams.filter((param) => !isParameterProperty(param));
200
195
 
201
196
  const messageId =
202
- consideredParams.length > 3
197
+ realParams.length > 3
203
198
  ? 'tooManyPositionalParams'
204
- : hasDuplicateType(consideredParams, sourceCode)
199
+ : hasDuplicateType(realParams, sourceCode)
205
200
  ? 'duplicateParamType'
206
201
  : undefined;
207
202
 
@@ -209,20 +204,10 @@ const rule: Rule.RuleModule = {
209
204
  return;
210
205
  }
211
206
 
212
- /**
213
- * A params object can only wrap the plain parameters. When parameter properties are
214
- * interspersed there is no safe single-range replacement, so the fix is omitted and the
215
- * developer resolves it manually.
216
- */
217
- const fix =
218
- consideredParams.length === realParams.length
219
- ? buildParamsObjectFix(consideredParams, sourceCode)
220
- : undefined;
221
-
222
207
  context.report({
223
208
  node,
224
209
  messageId,
225
- fix: fix ?? null,
210
+ fix: buildParamsObjectFix(realParams, sourceCode) ?? null,
226
211
  });
227
212
  }
228
213