Skip to content

Commit b694683

Browse files
authored
fix(eslint-plugin): [no-unsafe-assignment] report on an any value assigned as an initializer of an accessor property (#10785)
* handle accessor property with no-unsafe-assignemnt * also a valid test
1 parent 367fbb2 commit b694683

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

‎packages/eslint-plugin/src/rules/no-unsafe-assignment.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,16 @@ export default createRule({
337337
}
338338

339339
return {
340+
'AccessorProperty[value != null]'(
341+
node: { value: NonNullable<unknown> } & TSESTree.AccessorProperty,
342+
): void {
343+
checkAssignment(
344+
node.key,
345+
node.value,
346+
node,
347+
getComparisonType(node.typeAnnotation),
348+
);
349+
},
340350
'AssignmentExpression[operator = "="], AssignmentPattern'(
341351
node: TSESTree.AssignmentExpression | TSESTree.AssignmentPattern,
342352
): void {

‎packages/eslint-plugin/tests/rules/no-unsafe-assignment.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ class Foo {
9292
`
9393
class Foo {
9494
private a = 1;
95+
}
96+
`,
97+
`
98+
class Foo {
99+
accessor a = 1;
95100
}
96101
`,
97102
'const x: Set<string> = new Set();',
@@ -203,6 +208,14 @@ class Foo {
203208
},
204209
{
205210
code: `
211+
class Foo {
212+
accessor a = 1 as any;
213+
}
214+
`,
215+
errors: [{ messageId: 'anyAssignment' }],
216+
},
217+
{
218+
code: `
206219
const [x] = spooky;
207220
`,
208221
errors: [

0 commit comments

Comments
 (0)