빠른 시작
권장 설정 및 일반 워크플로우.
설치
oxfmt를 개발 의존성으로 설치하세요:
sh
$ npm add -D oxfmtsh
$ pnpm add -D oxfmtsh
$ yarn add -D oxfmtsh
$ bun add -D oxfmtpackage.json에 스크립트를 추가하세요:
json
{
"scripts": {
"fmt": "oxfmt",
"fmt:check": "oxfmt --check"
}
}파일을 형식화하세요:
sh
npm run fmtsh
pnpm run fmtsh
yarn run fmtsh
bun run fmt파일을 쓰지 않고 형식을 확인하세요:
sh
npm run fmt:checksh
pnpm run fmt:checksh
yarn run fmt:checksh
bun run fmt:check사용법
sh
oxfmt [옵션] [경로]...인수 없이 oxfmt를 실행하면 현재 디렉터리가 형식화됩니다 (즉, prettier --write .과 동일합니다).
--no-semi와 같은 CLI 옵션은 지원되지 않습니다. 클라이언트 및 에디터 통합에서 일관된 설정을 보장하기 위해 구성 파일을 사용하세요.
위치 인자 경로에서 글로브 패턴을 사용하려면 반드시 따옴표로 감싸야 합니다. 그렇지 않으면 환경에 따라 전개되거나 안될 수 있습니다.
모든 옵션의 완전한 목록은 CLI 참조를 참조하세요.
일반 워크플로우
lint-staged와 함께 프리커밋 사용
json
{
"lint-staged": {
"*": "oxfmt --no-error-on-unmatched-pattern"
}
}--no-error-on-unmatched-pattern은 패턴과 일치하는 파일이 없을 때 오류를 방지합니다.
구성 파일 생성
기본값으로 .oxfmtrc.json을 초기화하세요:
sh
oxfmt --initPrettier에서 마이그레이션
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"