Glavin001/tslint-clean-code

feature-envy doesn't take destructuring of own data into account.

Open

#38 创建于 2018年1月10日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)TypeScript (15 fork)github user discovery
buggood first issuehelp wanted

仓库指标

Star
 (175 star)
PR 合并指标
 (30 天内没有已合并 PR)

描述

When destructuring the data of an object inside one of its methods, the feature-envy rule does not realize that the newly created variables actually belong to the object.

Example:

const foreign = {
    constant1: 5,
    constant2: 5,
    constant3: 5
};

class Foo {
    private ownStuff = {
        num1: 42,
        num2: 1337,
        num3: 1024
    };

    // Method "doStuff" uses "foreign" more than its own class "Foo". Extract or Move Method from "doStuff" into "foreign". (no-feature-envy)
    public doStuff(num: number) {
        const { num1, num2, num3, num4, num5, num6 } = this.ownStuff;
        return foreign.constant1 + foreign.constant2 + foreign.constant3 + num1 + num2 + num3;
    }

    // No error
    public doOtherStuff(num: number) {
        return (
            foreign.constant1 +
            foreign.constant2 +
            foreign.constant3 +
            this.ownStuff.num1 +
            this.ownStuff.num2 +
            this.ownStuff.num3
        );
    }
}

贡献者指南