> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qlty.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Auto-formatting

Auto-formatting is the practice of using automated tools to rewrite source code files into a consistent format. These tools ensure that your code adheres to predefined styling and formatting guidelines, removing the need for manual adjustments and maintaining uniformity across the codebase. Popular auto-formatting tools include [`go fmt`](https://go.dev/blog/gofmt) for Go, [Prettier](https://prettier.io/) for JavaScript, and [Black](https://github.com/psf/black) for Python.

<Tip>Auto-formatting is provided by [Qlty CLI](/cli/quickstart).</Tip>

## Why is Auto-Formatting Useful?

Auto-formatting offers several key benefits that can enhance your development workflow and code quality:

1. **Consistency**: Auto-formatting enforces a consistent style across the entire codebase, making the code easier to read and understand.
2. **Productivity**: By automating the formatting process, developers can focus on writing code rather than spending time on manual formatting.
3. **Faster Code Review**: Consistent formatting results in clean diffs and reduces the number of stylistic comments during code reviews, allowing reviewers to focus on the logic and functionality of the code.

## How Auto-Formatting Works

Auto-formatting tools analyze your code and apply a set of formatting rules to transform it into a standard format. These rules cover various aspects of code style, including indentation, spacing, line breaks, and more. The tools can typically be configured to match the specific style guide of your development team or project.

Here’s a simple example in Go using `go fmt`:

### Before Auto-Formatting

```go lines theme={"system"}
package main
import "fmt"
func main() { fmt.Println("Hello, world!") }
```

### After Auto-Formatting

```go lines theme={"system"}
package main

import "fmt"

func main() {
    fmt.Println("Hello, world!")
}
```

In this example, `go fmt` adjusts the import statement and function definition to follow Go's standard formatting rules.

## Integrating Auto-Formatting into Your Workflow

Qlty supports auto-formatting tools as part of its comprehensive code qualtiy toolkit via the Qlty CLI.

1. **On Demand:** By configuring auto-formatters and running `qlty fmt` regularly, you can ensure consistent code style.
2. **Pre-commit Hooks**: Adding `qlty fmt` as a Git pre-commit hook to ensure every correct formatting of every commit.
3. **Continuous Integration (CI)**: You can set up an automated job to run `qlty fmt` nightly and commit the results.

## Recommended Auto-Formatters by Language

| Language   | Auto-Formatter       |
| ---------- | -------------------- |
| Go         | go fmt               |
| GraphQL    | Prettier             |
| HTML       | Prettier             |
| Java       | google-java-format   |
| JavaScript | Prettier             |
| JSON       | Prettier             |
| Kotlin     | ktfmt                |
| Markdown   | Prettier             |
| PHP        | @prettier/plugin-php |
| Python     | Black                |
| Ruby       | standardrb           |
| Rust       | rustfmt              |
| Shell      | shfmt                |
| TypeScript | Prettier             |
| YAML       | Prettier             |

## See Also

* [Qlty CLI](/cli/quickstart)
* [`qlty fmt`](/cli/commands/fmt)
* [Available Plugins](/plugins)
* [Analysis Configuration](/analysis-configuration)
