Skip to content

Add OXC.Format — oxfmt NIF bindings#3

Merged
dannote merged 2 commits into
masterfrom
format
Apr 21, 2026
Merged

Add OXC.Format — oxfmt NIF bindings#3
dannote merged 2 commits into
masterfrom
format

Conversation

@dannote
Copy link
Copy Markdown
Member

@dannote dannote commented Apr 21, 2026

Prettier-compatible JS/TS formatter via oxfmt, ~30× faster than Prettier.

API

OXC.Format.format!("const   x=1;let   y =  2;", "test.js")
# "const x = 1;\nlet y = 2;\n"

OXC.Format.format!("const x = 1;", "test.js", semi: false)
# "const x = 1\n"

OXC.Format.format!(source, "test.js", sort_imports: true, single_quote: true)

All oxfmt options supported: print_width, tab_width, use_tabs, semi,
single_quote, jsx_single_quote, trailing_comma, bracket_spacing,
bracket_same_line, arrow_parens, end_of_line, quote_props,
single_attribute_per_line, object_wrap, experimental_operator_position,
experimental_ternaries, embedded_language_formatting, sort_imports
(bool or map with sub-options), sort_tailwindcss (bool or map with sub-options).

Implementation

  • Separate oxc_fmt_nif crate (same pattern as oxc_lint_nif) — git dep on oxc_formatter since it's not on crates.io
  • Reads BEAM terms directly via Term::map_get with pre-declared atoms, no serde
  • 19 tests

Uniform API: submodules use run/3 and run!/3, the module name
provides context. Add bang variant to OXC.Lint, raise OXC.Error
consistently.
@dannote dannote merged commit 42144c4 into master Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant