01Tabs ⇄ spaces

Convert tabs to spaces and re-indent code

Paste code or drop files. TabMender measures the indentation, converts tabs and spaces either way, changes the indent width and shows every space · tab → and line end ↵ it touched. Nothing leaves your browser.

order.js · 23 lines

or drop files on this box

Detected

order.js
Indentation
Mixed, mostly 4 spaces
Space step
4 columns · 100% confidence
Tab width
4 · guessed
Off-style lines
5 · lines 7, 12, 19, 20, 21
Line endings
LF ×22
Final newline
yes
Trailing space
1 line

Indent steps between lines (spaces)

  1. +43
  2. +181

Options

Indent with
Convert
1/**↵
2·*·Totals·an·order,·line·by·line.↵
3·*/↵
4export·function·orderTotal(order,·rates)·{↵
5····let·total·=·0;↵
6····for·(const·line·of·order.lines)·{↵
7Δ········const·price·=·line.qty·*·line.unitPrice;↵
8········if·(line.taxable)·{↵
9············total·+=·applyTax(price,·rates,↵
10······························line.region);↵
11········}·else·{↵
12Δ············total·+=·price;↵
13········}↵
14····}↵
15····return·round(total);··↵
16}↵
17↵
18const·LIMITS·=·{↵
19Δ····small:→10,→→//·pieces↵
20Δ····medium:→250,→//·pieces↵
21Δ····large:→5000,→//·pallets↵
22};↵

5 lines changed: Re-indented 5 lines to 4-space indentation.

04Questions

Tabs, spaces and indentation

Does converting tabs to spaces change how my code runs?

For most languages, no: indentation is whitespace the compiler ignores. It matters in Python, YAML, Makefiles and a few others. Python 3 refuses files that mix tabs and spaces inconsistently, so converting a mixed file to one style is exactly the fix it needs.

How does it work out the indent width?

It measures how far the indentation grows from one line to the next and picks the most common step, so a 4-space file shows mostly +4 steps. Lines inside block comments are skipped, and lines aligned under a bracket count as alignment rather than a new level. The confidence is the share of steps that agree.

What does “every tab, mid-line too” do?

Tabs after the indentation, such as tabs that line up comments or values, are replaced with as many spaces as it takes to reach the next tab stop. A fixed run of spaces would break the alignment; expanding to the tab stop keeps the columns where they were.

What happens to lines that line up with a bracket?

A line indented past its parent by an amount that is not a whole level, like an argument lined up under an opening parenthesis, keeps the same offset from the line above it. When you change the indent width, it moves with its parent and stays aligned.

Are line endings changed?

Only if you choose a style under Line endings. Otherwise every line keeps its own ending, CRLF, LF or CR, and files are saved back in the encoding they came in, including a byte order mark if they had one.

Is my code uploaded anywhere?

No. Files are read and converted in your browser, in a background worker so large files do not freeze the page. Nothing you paste or drop is sent to a server.