use-join

Keeping a value next to the loop, try or function that reads it.

a single-line declaration is followed directly by a loop, try or function declaration that references what it binds

Applies when a single-line declaration is followed by a loop (for, for in, for of, while, do), a try or a function declaration that reads a name it binds. Declarations only: an assignment followed by a loop does not join.

For a function declaration, its own body is the reader. function walk() closing over const files joins to it even though nothing has called walk yet. That is the one reader where code inside a function counts: a read inside a callback passed to the loop or try does not.

Outranked by short-body and after-multiline. When the declaration is a let, let-step then puts a blank line above it, so the let and its loop form their own step.

Example

Before
function readSettings(path: string) {
  const fallback = defaults();

  try {
    return parse(readFileSync(path, "utf8"));
  } catch {
    return fallback;
  }
}
After
function readSettings(path: string) {
  const fallback = defaults();
  try {
    return parse(readFileSync(path, "utf8"));
  } catch {
    return fallback;
  }
}

On this page