# Formatting and linting

Source: https://athas.dev/docs/formatting

Format a file or selection, enable format on save, and diagnose missing formatters.

Formatting rewrites code layout. Linting reports problems and may offer fixes. Each depends on
your language tooling and project configuration.

## Format a file or selection

1. Open the source file and confirm its detected language.
2. Install or enable the relevant [language integration](https://athas.dev/docs/language-servers).
3. Run **Format Document** from the command palette (`Shift+Alt+F` in the default keymap).
4. For a smaller change, select code and run **Format Selection**.
5. Review the result and save the file.

A formatter may support whole documents without supporting selected ranges.

## Format and lint on save

Enable **Format on Save** and **Lint on Save** in Settings. Choose the formatter your project
expects when a choice is available. Keep the project's formatter configuration in version control
so teammates and CI use the same rules.

If Auto Save is enabled, consider how often save-time tooling will run before turning on both.

## Troubleshoot formatting

- Confirm the integration supplies a formatter for this language.
- Check the required executable or runtime is installed.
- Inspect project configuration for syntax errors or excluded paths.
- Try **Format Document** manually and read any error before relying on save-time formatting.
- Restart the [language server](https://athas.dev/docs/language-servers) if the tool's environment changed.

Use [Diagnostics](https://athas.dev/docs/diagnostics) to inspect lint errors and quick fixes, and [Diff Viewer](https://athas.dev/docs/git-diff)
to review formatting changes before committing.
