piapia123
en

C# Code Formatter

Format

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Indentation cleanup for C#. Not bracket counting — this uses a real parser (tree-sitter) to build the syntax tree and decide from the grammar how deep each line goes. Why does that matter? A bracket-counting approach cannot tell whether a `}` is in the code or inside a string or comment. One file containing `"}"` throws off every line after it, with nothing to indicate anything went wrong. With a syntax tree, block boundaries come from the parser. ⚠️ Only the leading whitespace of each line changes — not a character inside it. That constraint is deliberate: the worst failure for a formatter is not ugly output but breaking working code, which is worse than doing nothing. Touching only line starts means strings, comments and templates cannot be affected; even unusual syntax merely ends up indented differently while the code still runs. So there is no inline spacing cleanup, no reordering, no re-wrapping and no line removal. Incomplete code still produces output instead of an error — that is how formatting while typing is supposed to work.

Features

  • A real tree-sitter parse — indentation follows the grammar, not bracket counting
  • Brackets and keywords inside strings or comments do not affect the structure
  • Only leading whitespace changes; not a character inside a line
  • Indent with 2 spaces, 4 spaces or tabs
  • Incomplete code still produces output instead of an error
  • Syntax-highlighted output
  • Runs entirely on your device — the code is never uploaded

How to use

  1. Paste the code into the left pane
  2. Pick an indent width
  3. Press Ctrl/⌘ + Enter or click Run
  4. Copy the result

FAQ

How is this different from other online formatters?
Most online formatters do text-level indentation: scan character by character, indent on `{`, dedent on `}`. They cannot tell whether a bracket is in the code or inside a string. This one uses a real parser: the code becomes a syntax tree first, and each line’s depth is decided by the grammar it belongs to. The cost is a grammar file per language (a few hundred KB up to a few MB), downloaded only when you open that tool’s page. What you get in return is structure detection that does not guess.
Why did my code come out unchanged?
That usually means it was already correct, which is the best outcome. The worst failure for a formatter is not ugly output but altering correct code — that change lands in a diff and in code review, and it is hard to say who made it. So the strategy here is to act only when there is something to fix. When the code genuinely is misindented, the output does change.
Will it change what my code does?
No. Only the leading whitespace of each line is touched — not one character inside a line, no reordering, no re-wrapping, no line removal, nothing inside strings or comments. So even with wildly unusual formatting the worst case is indentation you do not like, while the code still runs. By the same token, it cannot add missing syntax (a dropped bracket, a forgotten semicolon). It is an indentation tool, not a repair tool.

Related tools