rewrite-static-analysis
rewrite-static-analysis copied to clipboard
InlineOneTimeUsageVariable
Please complete the InlineVariable function where it stops. While this is the intended behavior, it also misaligns the true indentation
make new one: InlineOneTimeUsagesVariable
BEFORE
class A {
public int calculateArea() {
int length = 1;
int width = 2;
int area = length + width; // Area calculation
return area;
}
}
InlineOneTimeUsageVariable / InlineAllVariable
class A {
public int calculateAreaImproved() {
return 1 + 2; // Length and width inlined
}
}
InlineVariable this is actually more something like InlineImmediateVariable
class A {
public int calculateArea() {
int length = 1;
int width = 2;
return length + width; // Area calculation
}
}
Code Examples
Here are some examples demonstrating these principles:
const calculateArea = () => {
const length = 1;
const width = 2;
const area = length + width;
return area;
};
// here is where the InlineVariable stops which is the intend but also kind of stupid
const calculateAreaWithParams = () => {
const length = 1;
const width = 2;
return length + width;
};
const calculateAreaInline = () => {
return 1 + 2;
};
- https://github.com/openrewrite/rewrite-static-analysis/pull/367
Partly this has already been achieved through
- https://github.com/openrewrite/rewrite-static-analysis/pull/647
I don't see us extending this to inline just any variable that's used once, as readability would suffer. With that we can close this issue.