Skip to content

Commit

Permalink
fix(eslint-plugin): [prefer-readonly] disable checking accessors (#8300)
Browse files Browse the repository at this point in the history
* Disable checking accessors for prefer-readonly

* Granular accessor tests

* Update packages/eslint-plugin/src/rules/prefer-readonly.ts

* fix: formatting and || for isModifierFlagSet suggestion

---------

Co-authored-by: Josh Goldberg ✨ <[email protected]>
  • Loading branch information
Jamesernator and JoshuaKGoldberg authored Jan 29, 2024
1 parent e95d719 commit 4d2ce3b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/eslint-plugin/src/rules/prefer-readonly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ class ClassScope {
tsutils.isModifierFlagSet(node, ts.ModifierFlags.Private) ||
node.name.kind === ts.SyntaxKind.PrivateIdentifier
) ||
tsutils.isModifierFlagSet(node, ts.ModifierFlags.Readonly) ||
tsutils.isModifierFlagSet(
node,
ts.ModifierFlags.Accessor | ts.ModifierFlags.Readonly,
) ||
ts.isComputedPropertyName(node.name)
) {
return;
Expand Down
20 changes: 20 additions & 0 deletions packages/eslint-plugin/tests/rules/prefer-readonly.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,26 @@ class Foo {
}
}
`,
`
class TestStaticPrivateAccessor {
private static accessor staticAcc = 1;
}
`,
`
class TestStaticPrivateFieldAccessor {
static accessor #staticAcc = 1;
}
`,
`
class TestPrivateAccessor {
private accessor acc = 3;
}
`,
`
class TestPrivateFieldAccessor {
accessor #acc = 3;
}
`,
],
invalid: [
{
Expand Down

0 comments on commit 4d2ce3b

Please sign in to comment.