Skip to content

Extract refactors break single-line if statements into two lines #53482

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

Closed
andrewbranch opened this issue Mar 23, 2023 · 5 comments · Fixed by #53732
Closed

Extract refactors break single-line if statements into two lines #53482

andrewbranch opened this issue Mar 23, 2023 · 5 comments · Fixed by #53732
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Milestone

Comments

@andrewbranch
Copy link
Member

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
  };
}
@andrewbranch andrewbranch added Bug A bug in TypeScript Help Wanted You can do this Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Domain: Refactorings e.g. extract to constant or function, rename symbol labels Mar 23, 2023
@andrewbranch andrewbranch added this to the Backlog milestone Mar 23, 2023
@fatcerberus
Copy link

and I reviewed the FAQ for entries about whether Tang was really invented by NASA

lol

@DanielRosenwasser
Copy link
Member

brb reading every issue Andrew has filed ever just in case I missed something

@andrewbranch
Copy link
Member Author

You definitely did 😏

@iinicole
Copy link
Contributor

Hi! This is my first time contributing. I would like to try resolving this issue if possible.

@andrewbranch
Copy link
Member Author

Hi @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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants