Skip to content

Migrar do Prettier

Guia para sair do Prettier e passar a usar o Oxfmt.

Início rápido

Em setups simples, um comando:

bash
$ npm add -D oxfmt@latest && npx oxfmt --migrate=prettier && npx oxfmt
bash
$ pnpm add -D oxfmt@latest && pnpm oxfmt --migrate=prettier && pnpm oxfmt
bash
$ yarn add -D oxfmt@latest && yarn oxfmt --migrate=prettier && yarn oxfmt
bash
$ bun add -D oxfmt@latest && bunx oxfmt --migrate=prettier && bunx oxfmt

Migrar com Skills

Fluxo interativo com a skill migrate-oxfmt:

bash
npx skills add https://github.com/oxc-project/oxc --skill migrate-oxfmt

Depois rode /migrate-oxfmt e o agente orienta o processo completo.

Antes de migrar

Compatível com grande parte das configs do Prettier v3.8.

Diferenças-chave:

  • printWidth padrão é 100 (Prettier usa 80)
  • Plugins do Prettier não são suportados (alguns foram nativamente implementados)
  • Algumas opções não existem (veja referência de config)

Consulte também Funcionalidades não suportadas e a matriz de compatibilidade.

Etapa 1: Atualizar Prettier para v3.8 (opcional)

Saídas do Oxfmt ficam mais próximas ao Prettier 3.8; atualizar antes reduz diffs.

Etapa 2: Instalar Oxfmt

bash
$ npm add -D oxfmt@latest
bash
$ pnpm add -D oxfmt@latest
bash
$ yarn add -D oxfmt@latest
bash
$ bun add -D oxfmt@latest
bash
$ deno add -D npm:oxfmt@latest

Etapa 3: Migrar configuração

Oxfmt aceita .oxfmtrc.json, .oxfmtrc.jsonc ou oxfmt.config.ts. Exemplo básico:

.oxfmtrc.jsonc
jsonc
{
  "$schema": "./node_modules/oxfmt/configuration_schema.json",
  "printWidth": 80,
}

Rode oxfmt --migrate prettier para converter automaticamente.

Exemplo prettierrc.js

Antes:

prettierrc.js
js
module.exports = {
  singleQuote: true,
  jsxSingleQuote: true,
};

Depois (oxfmt.config.ts):

oxfmt.config.ts
ts
import { defineConfig } from "oxfmt";

export default defineConfig({
  singleQuote: true,
  jsxSingleQuote: true,
  printWidth: 80,
});

Exemplo prettierrc.yaml

Antes:

prettierrc.yaml
yaml
trailingComma: "es5"
tabWidth: 4
semi: false
singleQuote: true

Depois (.oxfmtrc.jsonc):

.oxfmtrc.jsonc
jsonc
{
  "$schema": "./node_modules/oxfmt/configuration_schema.json",
  "trailingComma": "es5",
  "tabWidth": 4,
  "semi": false,
  "singleQuote": true,
  "printWidth": 80,
}

Etapa 4: Atualizar scripts

package.json

diff
{
  "scripts": {
-   "format": "prettier --write .",
+   "format": "oxfmt",
-   "format:check": "prettier --check ."
+   "format:check": "oxfmt --check"
  }
}

CI

diff
  - name: Check formatting
-   run: yarn prettier --check .
+   run: yarn oxfmt --check

Hooks (husky, lint-staged)

diff
"lint-staged": {
- "*": "prettier --write --no-error-on-unmatched-pattern"
+ "*": "oxfmt --no-error-on-unmatched-pattern"
}

Etapa 5: Rodar o formatador

sh
npm run format

Remova o Prettier se não for mais necessário.

Opcional

Integrações de editor

Veja Editores.

Documentação interna

Atualize menções ao Prettier em CONTRIBUTING.md, AGENTS.md, CLAUDE.md se couber.

Regras de lint

Remova eslint-plugin-prettier se existir; substitua por job oxfmt --check no CI.

Se continuar com ESLint, mantenha ou adicione eslint-config-prettier para desligar regras de estilo conflitantes — é só config, não adiciona regras novas.

Considere migrar para Oxlint.

.git-blame-ignore-revs

Inclua o SHA do commit de reformatação para ocultar no git blame.

Trocar .prettierignore por ignorePatterns

Se Prettier sair de cena, pode mover o conteúdo de .prettierignore para "ignorePatterns" na config Oxfmt. .prettierignore é global; ignorePatterns segue o escopo do arquivo de config — em config aninhada o conjunto ignorado pode mudar. Veja Ignorar arquivos.