Skip to content

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

Closed
@andrewbranch

Description

@andrewbranch

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
  };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Refactoringse.g. extract to constant or function, rename symbolEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions