Skip to content

Commit

Permalink
fix(readonly-type): empty object types should not trigger reports
Browse files Browse the repository at this point in the history
fix #796
  • Loading branch information
RebeccaStevens committed Apr 1, 2024
1 parent 052191c commit fc6a394
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/rules/readonly-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,16 @@ function checkTypeLiteral(
}

if (mode === "generic") {
const needsWrapping = node.members.every(
(member) =>
(isPropertyDefinition(member) ||
isTSIndexSignature(member) ||
isTSParameterProperty(member) ||
isTSPropertySignature(member)) &&
member.readonly,
);
const needsWrapping =
node.members.length > 0 &&
node.members.every(
(member) =>
(isPropertyDefinition(member) ||
isTSIndexSignature(member) ||
isTSParameterProperty(member) ||
isTSPropertySignature(member)) &&
member.readonly,
);

if (needsWrapping) {
return {
Expand Down
7 changes: 7 additions & 0 deletions tests/rules/readonly-type/ts/valid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ const tests: Array<ValidTestCaseSet<OptionsOf<typeof rule>>> = [
`,
optionsSet: [["keyword"]],
},
// Empty should not cause issues
{
code: dedent`
type Foo = {};
`,
optionsSet: [["keyword"], ["generic"]],
},
];

export default tests;

0 comments on commit fc6a394

Please sign in to comment.