liveBook · Manning

Formatter

As explained in "Looks Good to Me"

A formatter is a software tool that automatically reformats source code according to specified formatting rules.

A formatter automatically reformats source code according to rules agreed in a team style guide. It replaces subjective style debates with consistent, repeatable checks. section 4.2.3 section 5.3.1

Use a formatter at several points in development:

  • Provide real-time feedback while developers write code. section 5.3.1
  • Run it locally before committing changes. section 5.3.1
  • Run it as a pull-request gate so reviewers can ignore failures of basic formatting. section 5.3.1
  • Keep trivial style comments from blocking approval; define those approval rules separately in the team working agreement. section 4.2.3

Spacing between declarations and logic

A team may require a blank line between variable declarations and business logic. The formatter can enforce that choice consistently instead of relying on each developer to remember it. section 5.3.1

Listing 5.4 Line break spacing between variable declarations and logic (JavaScript)
function GetTotalDonutCalories() {

  const donutLog = [
    { day: 'Monday', totalEaten: 2 },
    { day: 'Tuesday', totalEaten: 1 },
    { day: 'Wednesday', totalEaten: 3 },
    { day: 'Thursday', totalEaten: 2 },
    { day: 'Friday', totalEaten: 4 },
  ];

  const caloriesConsumed = donutLog.reduce((lastCount, currentEntry));

  return caloriesConsumed;
}

Inspect a JavaScript example that applies the agreed spacing between declarations and logic. section 5.3.1

How "Looks Good to Me" covers it

How deep it goes
Explains practical enforcement points and team-policy boundaries, but does not describe formatter internals.
Examples
Uses JavaScript listings showing spaced, unspaced, and inconsistently spaced declarations and logic.
What it assumes
Assumes a team style guide exists and teaches how to codify its conventions into automated checks.
What you can do after
Operate a formatter through real-time feedback, local checks, and pull-request gates to maintain agreed style.
How it connects
Connects formatting with style guides, code review, pull requests, PR gate checks, and team working agreements.

Also explained in

Compare how 2 books explain formatter →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of "Looks Good to Me". The section links point to the parts of the book it draws on.