Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nimelrian opened this issue Jan 10, 2018 · 1 comment
Open

Comments

@Nimelrian
Copy link
Contributor

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
        );
    }
}
@Glavin001 Glavin001 added the bug label Jan 10, 2018
@Glavin001
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants