Skip to content

Commit

Permalink
feat: add ReScript formatter (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelofallars committed Feb 13, 2024
1 parent c0e0e80 commit a34b66f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ You can view this list in vim with `:help conform-formatters`
- [pretty-php](https://github.com/lkrms/pretty-php) - The opinionated PHP code formatter.
- [puppet-lint](https://github.com/puppetlabs/puppet-lint) - Check that your Puppet manifests conform to the style guide.
- [reorder-python-imports](https://github.com/asottile/reorder-python-imports) - Rewrites source to reorder python imports
- [rescript-format](https://github.com/rescript-lang/rescript-compiler) - The built-in ReScript formatter.
- [rubocop](https://github.com/rubocop/rubocop) - Ruby static code analyzer and formatter, based on the community Ruby style guide.
- [rubyfmt](https://github.com/fables-tales/rubyfmt) - Ruby Autoformatter! (Written in Rust)
- [ruff_fix](https://beta.ruff.rs/docs/) - An extremely fast Python linter, written in Rust. Fix lint errors.
Expand Down
40 changes: 40 additions & 0 deletions lua/conform/formatters/rescript-format.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- The formatter expects one of [.res | .resi | .ml | .mli] passed as
-- the value to the '-stdin' argument.
local valid_extensions = {
res = true,
resi = true,
ml = true,
mli = true,
}

local default_extension = "res"

---@type conform.FileFormatterConfig
return {
meta = {
url = "https://rescript-lang.org/",
description = "The built-in ReScript formatter.",
},
command = "rescript",
args = function(self, ctx)
local extension = vim.fn.fnamemodify(ctx.filename, ":e")

local is_invalid_extension = valid_extensions[extension] == nil
if is_invalid_extension then
extension = default_extension
end

return {
"format",
"-stdin",
"." .. extension,
}
end,
stdin = true,

require_cwd = true,
cwd = require("conform.util").root_file({
"rescript.json",
"bsconfig.json",
}),
}

0 comments on commit a34b66f

Please sign in to comment.