Code formatter example: brace indentation

A one-line function made readable by indentation, and the language tools this pass does not replace.

Open Code Formatter to run this case yourself.

Compressed

function total(items){let sum=0;for(const item of items){if(item.qty>0){sum+=item.price*item.qty;}}return sum;}

Indented by CompareStack

function total(items){
    let sum=0;
    for(const item of items){
        if(item.qty>0){
            sum+=item.price*item.qty;
        }
    }
    return sum;
}

The problem

The function fits on one line, so the nested if is easy to misread. The formatter used here is a brace-and-bracket indentation pass. It is not a JavaScript parser and it does not insert spaces around operators. The block above is the actual output: each opening brace increases the indent, and the matching close decreases it.

What you still have to check

The logic is unchanged and still unreviewed. qty and price are still unvalidated. Indentation makes the nesting visible. It does not prove the arithmetic is what the ticket asked for. HTML-like input takes a different path, PHP’s DOM formatter, when that succeeds. Other languages get this structural pass only.

When this tool may not be the right choice

  • A language-aware formatter such as Prettier, Black, gofmt, or rustfmt. Those tools understand syntax. This one indents braces.
  • You need formatting that a repository will accept unchanged. Run the project’s formatter in CI instead of pasting a one-off result.
  • Minified production bundles. Indenting them does not make them a source of truth.

Processing and privacy

Paste tools also run on the server. The text is sent in the form POST, with a limit of 100,000 characters per field. It is not written into a document library or a user account. Server logs can still record technical request metadata such as IP address and URL. Do not paste secrets, credentials, or personal data you are not allowed to send to a web service.

The Privacy Policy and how processing works are the full description.

Open Code Formatter

Related examples

Related guides