From 8869d56075f5300b719595c47a3d315882e252ab Mon Sep 17 00:00:00 2001 From: baseballyama Date: Wed, 7 May 2025 10:45:08 +0900 Subject: [PATCH 1/2] fix: prevent to report `prefer-tacit` in direct child of getter --- src/rules/prefer-tacit.ts | 19 +++++++++++++++++++ tests/rules/prefer-tacit.test.ts | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/rules/prefer-tacit.ts b/src/rules/prefer-tacit.ts index 801192166..41359f6e1 100644 --- a/src/rules/prefer-tacit.ts +++ b/src/rules/prefer-tacit.ts @@ -118,6 +118,18 @@ function isCallerViolation( .some((signature) => signature.parameters.length === caller.arguments.length); } +/** + * Is the given node a direct child of a getter. + */ +function isDirectChildOfGetter(node: TSESTree.Node): boolean { + const { parent } = node; + if (parent?.type !== TSESTree.AST_NODE_TYPES.Property) { + return false; + } + + return parent.kind === 'get'; +} + /** * Get the fixes for a call to a reference violation. */ @@ -260,6 +272,13 @@ function checkFunction( context: Readonly>, options: RawOptions, ): RuleResult { + if (isDirectChildOfGetter(node)) { + return { + context, + descriptors: [], + }; + } + return { context, descriptors: [ diff --git a/tests/rules/prefer-tacit.test.ts b/tests/rules/prefer-tacit.test.ts index 802f747a1..f9b608a35 100644 --- a/tests/rules/prefer-tacit.test.ts +++ b/tests/rules/prefer-tacit.test.ts @@ -97,6 +97,23 @@ describe(name, () => { `); }); + it("doesn't report getters", () => { + valid(dedent` + const foo = () => { + const getBar = () => 1; + const setBar = (value: number) => {}; + return { + get baz() { + return getBar(); + }, + set baz(value) { + setBar(value); + }, + }; + }; + `); + }); + describe("options", () => { describe("checkMemberExpressions", () => { it("doesn't report member expressions when disabled", () => { From 1d9e789ce6910e3a9f2e81a67a22d4ad737fa44f Mon Sep 17 00:00:00 2001 From: Rebecca Stevens Date: Mon, 2 Jun 2025 21:50:08 +1200 Subject: [PATCH 2/2] style: small fix up --- src/rules/prefer-tacit.ts | 2 +- tests/rules/prefer-tacit.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rules/prefer-tacit.ts b/src/rules/prefer-tacit.ts index 41359f6e1..7978823ad 100644 --- a/src/rules/prefer-tacit.ts +++ b/src/rules/prefer-tacit.ts @@ -127,7 +127,7 @@ function isDirectChildOfGetter(node: TSESTree.Node): boolean { return false; } - return parent.kind === 'get'; + return parent.kind === "get"; } /** diff --git a/tests/rules/prefer-tacit.test.ts b/tests/rules/prefer-tacit.test.ts index 02123c939..25f0ad337 100644 --- a/tests/rules/prefer-tacit.test.ts +++ b/tests/rules/prefer-tacit.test.ts @@ -97,8 +97,8 @@ describe(name, () => { `); }); - it("doesn't report getters", () => { - valid(dedent` + it("doesn't report getters", async () => { + await valid(dedent` const foo = () => { const getBar = () => 1; const setBar = (value: number) => {};