diff --git a/src/rules/prefer-tacit.ts b/src/rules/prefer-tacit.ts index 801192166..7978823ad 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 11aeefb6c..25f0ad337 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", async () => { + await 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", async () => {