Glavin001 / Glavin001/tslint-clean-code

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

Open
#38 1 comment 0 reactions 0 assignees View on GitHub
bug good first issue help wanted
Dominant language
TypeScript
Stars
175
Forks
15
PR merge metrics
No merged PRs in 30d

Description

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:
```ts
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
);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.