Skip to content

빠른 시작

권장 설정과 일반적인 사용 흐름입니다.

설치

oxfmt를 dev 의존성으로 설치합니다.

sh
$ npm add -D oxfmt
sh
$ pnpm add -D oxfmt
sh
$ yarn add -D oxfmt
sh
$ bun add -D oxfmt

package.json에 스크립트를 추가합니다.

package.json
json
{
  "scripts": {
    "fmt": "oxfmt",
    "fmt:check": "oxfmt --check"
  }
}

포맷 실행:

sh
npm run fmt
sh
pnpm run fmt
sh
yarn run fmt
sh
bun run fmt

파일을 쓰지 않고 검사만:

sh
npm run fmt:check
sh
pnpm run fmt:check
sh
yarn run fmt:check
sh
bun run fmt:check

사용법

sh
oxfmt [OPTIONS] [PATH]...

인자 없이 실행하면 현재 디렉터리를 포맷합니다(prettier --write .와 동일).

--no-semi 같은 CLI 전용 옵션은 없습니다. CLI와 에디터가 같은 설정을 쓰도록 설정 파일을 사용하세요.

위치 인자에 글로브를 쓸 때는 반드시 따옴표로 감싸세요. 환경에 따라 셸이 먼저 확장할 수 있습니다.

전체 옵션은 CLI 참조를 보세요.

일반 워크플로

lint-staged로 pre-commit

package.json
json
{
  "lint-staged": {
    "*": "oxfmt --no-error-on-unmatched-pattern"
  }
}

--no-error-on-unmatched-pattern은 패턴에 맞는 파일이 없어도 오류를 내지 않게 합니다.

설정 파일 만들기

기본값으로 .oxfmtrc.json 초기화:

sh
oxfmt --init

Prettier에서 마이그레이션

sh
oxfmt --migrate prettier

자세한 내용은 Prettier에서 마이그레이션을 참고하세요.

달라진 파일 목록

sh
oxfmt --list-different

무시할 파일을 정할 때 유용합니다.

파이프로 내용 전달

sh
echo 'const   x   =   1' | oxfmt --stdin-filepath test.ts

출력: const x = 1;

Node.js API

ts
import { format, type FormatOptions } from "oxfmt";

const input = `let a=42;`;
const options: FormatOptions = {
  semi: false,
};

const { code } = await format("a.js", input, options);
console.log(code); // "let a = 42"

다음 단계