한국어
문서
포매터

포매터

OpenCode가 파일을 편집한 뒤 Prettier, Biome, gofmt, Ruff 같은 내장 포매터나 사용자 정의 명령어로 코드를 자동으로 포맷하세요.

OpenCode는 write, edit 또는 patch 도구가 파일을 변경한 직후 포매팅을 실행할 수 있습니다. 포매터는 기본적으로 비활성화되어 있으므로 설정 파일에서 활성화해야 합니다.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "formatter": true,
}

활성화

formatter를 true로 설정하면 모든 내장 포매터가 활성화됩니다. OpenCode는 해당 실행 파일과 프로젝트별 요구 조건이 갖춰진 경우에만 내장 포매터를 실행합니다.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "formatter": true,
}

객체 형태를 사용해도 내장 포매터가 활성화되며, 기존 포매터를 재정의하거나 사용자 정의 포매터를 추가할 수 있습니다. 빈 객체는 상속된 포매터 설정을 유지하는 반면, true는 설정을 내장 기본값으로 재설정합니다.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "formatter": {},
}

내장 포매터

OpenCode에는 다음 포매터 정의가 포함되어 있습니다. 대부분 해당 명령어가 사용 가능해야 하며, 추가 감지 규칙이 있는 포매터는 요구 조건에 함께 표시되어 있습니다.

포매터확장자요구 조건
gofmt.gogofmt 명령어
mix.ex, .exs, .eex, .heex, .leex, .neex, .sfacemix 명령어
oxfmt.js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .ctspackage.json의 oxfmt 의존성
prettier.js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .cts, .html, .htm, .css, .scss, .sass, .less, .vue, .svelte, .json, .jsonc, .yaml, .yml, .toml, .xml, .md, .mdx, .graphql, .gqlpackage.json의 prettier 의존성
biome위의 prettier와 동일한 확장자biome.json 또는 biome.jsonc 및 설치된 @biomejs/biome 바이너리
zig.zig, .zonzig 명령어
clang-format.c, .cc, .cpp, .cxx, .c++, .h, .hh, .hpp, .hxx, .h++, .ino, .C, .Hclang-format 명령어 및 .clang-format
ktlint.kt, .ktsktlint 명령어
ruff.py, .pyiruff 명령어 및 Ruff 설정 또는 의존성 선언
air.RR 포매터로 식별되는 air 명령어
uv.py, .pyiuv format을 지원하는 uv 명령어
rubocop.rb, .rake, .gemspec, .rurubocop 명령어
standardrb.rb, .rake, .gemspec, .rustandardrb 명령어
htmlbeautifier.erbhtmlbeautifier 명령어
dart.dartdart 명령어
ocamlformat.ml, .mliocamlformat 명령어 및 .ocamlformat
terraform.tf, .tfvarsterraform 명령어
latexindent.texlatexindent 명령어
gleam.gleamgleam 명령어
shfmt.sh, .bashshfmt 명령어
nixfmt.nixnixfmt 명령어
rustfmt.rsrustfmt 명령어
pint.phpcomposer.json의 laravel/pint
ormolu.hsormolu 명령어
cljfmt.clj, .cljs, .cljc, .edncljfmt 명령어
dfmt.ddfmt 명령어

예를 들어 내장 포매터를 활성화하면 OpenCode가 프로젝트 로컬 Prettier 의존성을 자동으로 감지해 일치하는 파일에 실행합니다.

opencode.jsonc
{
  "formatter": true,
}

사용자 정의

이름이 지정된 항목을 추가하여 내장 포매터를 변경하거나 사용자 정의 포매터를 정의할 수 있습니다. 사용자 정의 포매터가 실행되려면 command와 extensions를 모두 지정해야 합니다.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "formatter": {
    "prettier": {
      "environment": {
        "NODE_ENV": "development",
      },
      "extensions": [".js", ".ts"],
    },
    "deno-markdown": {
      "command": ["deno", "fmt", "$FILE"],
      "extensions": [".md"],
    },
  },
}
필드타입동작
disabledbooleantrue일 때 해당 이름의 포매터를 제거합니다.
commandstring[]내장 명령어를 대체하거나 사용자 정의 명령어를 지정합니다.
environmentRecord<string, string>상위 환경을 유지하면서 추가 환경 변수를 설정합니다.
extensionsstring[]내장 확장자 목록을 대체하거나 사용자 정의 확장자 목록을 지정합니다. 앞의 점(.)을 포함해야 합니다.

모든 필드는 선택 항목입니다. 내장 포매터 항목은 생략된 값을 기본값에서 상속받지만, 새로 추가한 포매터 항목은 command나 extensions가 없으면 실행되지 않습니다.

opencode.jsonc
{
  "formatter": {
    "prettier": {
      "extensions": [".md", ".mdx"],
    },
  },
}

명령어

command는 셸 명령 문자열이 아니라 인수 배열입니다. OpenCode는 $FILE을 파일의 절대 경로로 치환하고 활성 프로젝트 디렉터리에서 명령어를 실행합니다.

opencode.jsonc
{
  "formatter": {
    "custom": {
      "command": ["custom-fmt", "--write", "$FILE"],
      "extensions": [".custom"],
    },
  },
}

확장자 매칭

OpenCode는 파일의 마지막 확장자를 extensions와 비교합니다. 매칭은 대소문자를 구분하며, notes.part.md의 마지막 확장자는 .md이므로 .part.md 같은 복합 확장자 항목과는 일치하지 않습니다.

opencode.jsonc
{
  "formatter": {
    "markdown": {
      "command": ["deno", "fmt", "$FILE"],
      "extensions": [".md"],
    },
  },
}

여러 포매터가 일치하는 경우 OpenCode는 등록된 순서대로 시도하고 처음 성공한 명령어 이후 중단합니다. 내장 포매터는 내장 순서를 유지하며, 사용자 정의 항목은 객체에 정의된 순서대로 뒤따릅니다. 한 포매터가 오류로 종료되면 OpenCode는 실패를 기록하고 다음 일치 포매터를 시도합니다.

opencode.jsonc
{
  "formatter": {
    "preferred": {
      "command": ["preferred-fmt", "$FILE"],
      "extensions": [".foo"],
    },
    "fallback": {
      "command": ["fallback-fmt", "$FILE"],
      "extensions": [".foo"],
    },
  },
}

비활성화

어느 설정 파일에도 formatter가 지정되지 않으면 포매팅은 비활성화 상태입니다. 낮은 우선순위의 설정 파일에서 활성화된 포매팅을 끄려면 false로 설정하세요.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "formatter": false,
}

다른 내장 포매터는 유지하면서 특정 내장 포매터 하나만 비활성화하려면 해당 항목에 disabled: true를 지정하세요.

opencode.jsonc
{
  "formatter": {
    "prettier": {
      "disabled": true,
    },
  },
}

AI가 편집한 코드를 기존 스타일과 일관되게 유지하는 것은 매우 중요합니다. 에이전트와 함께하는 코딩 워크플로는 가이드에서 확인하세요.

문서 출처 (MIT)