Extract refactors break single-line if statements into two lines #53482
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbole.g. extract to constant or function, rename symbolEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
Milestone
Description
Bug Report
🔎 Search Terms
extract function single-line if
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about whether Tang was really invented by NASA
💻 Code
function f() {
return [].filter(x => {
if (!x) return false;
});
}🙁 Actual behavior
Select the arrow function callback of filter and run “Extract to inner function.” The formatting of the function contents should be the same in the extracted function.
🙂 Expected behavior
function newFunction(): (value: any, index: number, array: any[]) => unknown {
return x => {
if (!x)
return false; // New line added
};
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbole.g. extract to constant or function, rename symbolEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisYou can do this
Activity
fatcerberus commentedon Mar 24, 2023
lol
DanielRosenwasser commentedon Mar 24, 2023
brb reading every issue Andrew has filed ever just in case I missed something
andrewbranch commentedon Mar 24, 2023
You definitely did 😏
iinicole commentedon Mar 29, 2023
Hi! This is my first time contributing. I would like to try resolving this issue if possible.
andrewbranch commentedon Mar 29, 2023
Hi Nicole (@iinicole), take a look at https://github.com/microsoft/TypeScript/blob/main/CONTRIBUTING.md for how to get started. My guess is the fix is likely to be similar to #39280. The first step (after you get the source code cloned, building, and running) will be to write a failing fourslash test case. The PR I just linked contains one you can use for reference. Feel free to ask for help if you get stuck, but how much guidance we can give varies by how busy things are, how close you are to being on the right track, and how complicated the bug ends up being—sometimes these things look easy and end up being difficult; sometimes the opposite happens. If it gets to be overwhelming, no worries; I’d encourage you to look for an issue labeled “Good First Issue” in that case. Good luck and thanks!