opencode / packages /web /src /content /docs /ko /formatters.mdx
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
0dbc9de verified
Raw
History Blame Contribute Delete
9.75 kB
---
title: ํฌ๋งคํ„ฐ
description: OpenCode๋Š” ์–ธ์–ด๋ณ„ ํฌ๋งคํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
---
OpenCode๋Š” ํŒŒ์ผ์„ writeํ•˜๊ฑฐ๋‚˜ editํ•œ ๋’ค, ์–ธ์–ด๋ณ„ ํฌ๋งคํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด ์ž๋™์œผ๋กœ ํฌ๋งทํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์ƒ์„ฑ๋œ ์ฝ”๋“œ๊ฐ€ ํ”„๋กœ์ ํŠธ์˜ ์ฝ”๋“œ ์Šคํƒ€์ผ์„ ๋”ฐ๋ฅด๋„๋ก ๋ณด์žฅํ•ฉ๋‹ˆ๋‹ค.
---
## ๋‚ด์žฅ
OpenCode๋Š” ์ฃผ์š” ์–ธ์–ด์™€ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์œ„ํ•œ ์—ฌ๋Ÿฌ ๋‚ด์žฅ ํฌ๋งคํ„ฐ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ํฌ๋งคํ„ฐ ๋ชฉ๋ก, ์ง€์› ํ™•์žฅ์ž, ํ•„์š”ํ•œ ๋ช…๋ น ๋˜๋Š” config ์˜ต์…˜์ž…๋‹ˆ๋‹ค.
| ํฌ๋งคํ„ฐ | ํ™•์žฅ์ž | ์š”๊ตฌ ์‚ฌํ•ญ |
| -------------------- | ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| air | .R | `air` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| biome | .js, .jsx, .ts, .tsx, .html, .css, .md, .json, .yaml, [๊ธฐํƒ€](https://biomejs.dev/) | `biome.json(c)` config ํŒŒ์ผ |
| cargofmt | .rs | `cargo fmt` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| clang-format | .c, .cpp, .h, .hpp, .ino, [๊ธฐํƒ€](https://clang.llvm.org/docs/ClangFormat.html) | `.clang-format` config ํŒŒ์ผ |
| cljfmt | .clj, .cljs, .cljc, .edn | `cljfmt` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| dart | .dart | `dart` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| dfmt | .d | `dfmt` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| gleam | .gleam | `gleam` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| gofmt | .go | `gofmt` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| htmlbeautifier | .erb, .html.erb | `htmlbeautifier` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| ktlint | .kt, .kts | `ktlint` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| mix | .ex, .exs, .eex, .heex, .leex, .neex, .sface | `mix` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| nixfmt | .nix | `nixfmt` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| ocamlformat | .ml, .mli | `ocamlformat` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ ๋ฐ `.ocamlformat` config ํŒŒ์ผ ํ•„์š” |
| ormolu | .hs | `ormolu` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| oxfmt (Experimental) | .js, .jsx, .ts, .tsx | `package.json`์— `oxfmt` dependency ํ•„์š” ๋ฐ [experimental env variable flag](/docs/cli/#experimental) |
| pint | .php | `composer.json`์— `laravel/pint` dependency ํ•„์š” |
| prettier | .js, .jsx, .ts, .tsx, .html, .css, .md, .json, .yaml, [๊ธฐํƒ€](https://prettier.io/docs/en/index.html) | `package.json`์— `prettier` dependency ํ•„์š” |
| rubocop | .rb, .rake, .gemspec, .ru | `rubocop` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| ruff | .py, .pyi | `ruff` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ ๋ฐ ๊ด€๋ จ config ํ•„์š” |
| rustfmt | .rs | `rustfmt` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| shfmt | .sh, .bash | `shfmt` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| standardrb | .rb, .rake, .gemspec, .ru | `standardrb` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| terraform | .tf, .tfvars | `terraform` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| uv | .py, .pyi | `uv` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
| zig | .zig, .zon | `zig` ๋ช…๋ น ์‚ฌ์šฉ ๊ฐ€๋Šฅ |
์˜ˆ๋ฅผ ๋“ค์–ด ํ”„๋กœ์ ํŠธ `package.json`์— `prettier`๊ฐ€ ์žˆ์œผ๋ฉด OpenCode๊ฐ€ ์ž๋™์œผ๋กœ ํ•ด๋‹น ํฌ๋งคํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
---
## ์ž‘๋™ ๋ฐฉ์‹
OpenCode๊ฐ€ ํŒŒ์ผ์„ writeํ•˜๊ฑฐ๋‚˜ editํ•  ๋•Œ ๋‹ค์Œ ์ˆœ์„œ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค.
1. ํ™œ์„ฑํ™”๋œ ๋ชจ๋“  ํฌ๋งคํ„ฐ์™€ ํŒŒ์ผ ํ™•์žฅ์ž๋ฅผ ๋Œ€์กฐํ•ฉ๋‹ˆ๋‹ค.
2. ํŒŒ์ผ์— ๋งž๋Š” ํฌ๋งคํ„ฐ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
3. ํฌ๋งท ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ์ž๋™์œผ๋กœ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.
์ด ๊ณผ์ •์€ background์—์„œ ์‹คํ–‰๋˜๋ฉฐ, ์ˆ˜๋™ ์ž‘์—… ์—†์ด ์ฝ”๋“œ ์Šคํƒ€์ผ์ด ์œ ์ง€๋ฉ๋‹ˆ๋‹ค.
---
## ๊ตฌ์„ฑ
OpenCode config์˜ `formatter` ์„น์…˜์—์„œ ํฌ๋งคํ„ฐ๋ฅผ ์ปค์Šคํ„ฐ๋งˆ์ด์ฆˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"formatter": {}
}
```
๊ฐ formatter ์„ค์ •์—์„œ ์ง€์›ํ•˜๋Š” ํ•ญ๋ชฉ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.
| ์†์„ฑ | ํƒ€์ž… | ์„ค๋ช… |
| ------------- | -------- | ---------------------------------------------- |
| `disabled` | boolean | `true`๋กœ ์„ค์ •ํ•˜๋ฉด ํ•ด๋‹น ํฌ๋งคํ„ฐ๋ฅผ ๋น„ํ™œ์„ฑํ™”ํ•ฉ๋‹ˆ๋‹ค |
| `command` | string[] | ํฌ๋งท ์‹คํ–‰ ๋ช…๋ น์ž…๋‹ˆ๋‹ค |
| `environment` | object | ํฌ๋งคํ„ฐ ์‹คํ–‰ ์‹œ ์„ค์ •ํ•  ํ™˜๊ฒฝ ๋ณ€์ˆ˜์ž…๋‹ˆ๋‹ค |
| `extensions` | string[] | ํ•ด๋‹น ํฌ๋งคํ„ฐ๊ฐ€ ์ฒ˜๋ฆฌํ•  ํŒŒ์ผ ํ™•์žฅ์ž์ž…๋‹ˆ๋‹ค |
์•„๋ž˜ ์˜ˆ์‹œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.
---
### ํฌ๋งคํ„ฐ ๋น„ํ™œ์„ฑํ™”
์ „์ฒด ํฌ๋งคํ„ฐ๋ฅผ ์ „์—ญ์—์„œ ๋น„ํ™œ์„ฑํ™”ํ•˜๋ ค๋ฉด `formatter`๋ฅผ `false`๋กœ ์„ค์ •ํ•˜์„ธ์š”.
```json title="opencode.json" {3}
{
"$schema": "https://opencode.ai/config.json",
"formatter": false
}
```
ํŠน์ • ํฌ๋งคํ„ฐ๋งŒ ๋น„ํ™œ์„ฑํ™”ํ•˜๋ ค๋ฉด `disabled`๋ฅผ `true`๋กœ ์„ค์ •ํ•˜์„ธ์š”.
```json title="opencode.json" {5}
{
"$schema": "https://opencode.ai/config.json",
"formatter": {
"prettier": {
"disabled": true
}
}
}
```
---
### ์‚ฌ์šฉ์ž ์ •์˜ ํฌ๋งคํ„ฐ
๋ช…๋ น, ํ™˜๊ฒฝ ๋ณ€์ˆ˜, ํŒŒ์ผ ํ™•์žฅ์ž๋ฅผ ์ง€์ •ํ•ด ๋‚ด์žฅ ํฌ๋งคํ„ฐ๋ฅผ overrideํ•˜๊ฑฐ๋‚˜ ์ƒˆ ํฌ๋งคํ„ฐ๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
```json title="opencode.json" {4-14}
{
"$schema": "https://opencode.ai/config.json",
"formatter": {
"prettier": {
"command": ["npx", "prettier", "--write", "$FILE"],
"environment": {
"NODE_ENV": "development"
},
"extensions": [".js", ".ts", ".jsx", ".tsx"]
},
"custom-markdown-formatter": {
"command": ["deno", "fmt", "$FILE"],
"extensions": [".md"]
}
}
}
```
๋ช…๋ น์˜ **`$FILE` placeholder**๋Š” ํฌ๋งท ๋Œ€์ƒ ํŒŒ์ผ ๊ฒฝ๋กœ๋กœ ์น˜ํ™˜๋ฉ๋‹ˆ๋‹ค.