# format-code

Learn how to format code files.

This action formats code files using the project's configured formatter, if available. If no formatter is found or formatting fails, the action completes silently without error.

## Example

The following template downloads a component and formats it:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Component installer",
  "description": "Downloads and formats a component file.",
  "actions": [
    {
      "name": "download",
      "source": "./code/hero.tsx",
      "destination": "src/components"
    },
    {
      "name": "format-code",
      "files": ["src/components/hero.tsx"]
    }
  ]
}
```

To apply this template, run:

```sh
croct use template.json5
```

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `format-code` for this action.

- `files`: `Array<string>`

  The list of file paths to format.

## Explore

- [Write file](/reference/cli/templates/actions/write-file): Learn how to write a file to format.
- [Replace file content](/reference/cli/templates/actions/replace-file-content): Learn how to modify code before formatting.
- [Resolve import](/reference/cli/templates/actions/resolve-import): Learn how to resolve imports before formatting.
- [Install](/reference/cli/templates/actions/install): Learn how to install formatter dependencies.
