Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ You can view this list in vim with `:help conform-formatters`
- [dart_format](https://dart.dev/tools/dart-format) - Replace the whitespace in your program with formatting that follows Dart guidelines.
- [dcm_fix](https://dcm.dev/docs/cli/formatting/fix/) - Fixes issues produced by dcm analyze, dcm check-unused-code or dcm check-dependencies commands.
- [dcm_format](https://dcm.dev/docs/cli/formatting/format/) - Formats .dart files.
- [deno_fmt](https://deno.land/manual/tools/formatter) - Use [Deno](https://deno.land/) to format TypeScript, JavaScript/JSON and markdown.
- [deno_fmt](https://docs.deno.com/runtime/reference/cli/fmt/) - Use [Deno](https://deno.com/) to format TypeScript, JavaScript, JSON, Markdown and more.
- [dfmt](https://github.com/dlang-community/dfmt) - Formatter for D source code.
- [dioxus](https://github.com/dioxuslabs/dioxus) - Format `rsx!` snippets in Rust files.
- [djlint](https://github.com/Riverside-Healthcare/djLint) - ✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang.
Expand Down
54 changes: 37 additions & 17 deletions lua/conform/formatters/deno_fmt.lua
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
local log = require("conform.log")

-- Requires `--unstable-component` flag or
-- `"unstable": ["fmt-component]` config option.
-- https://docs.deno.com/runtime/reference/cli/formatter/#formatting-options-unstable-component
local unstable_extensions = {
-- Some formats require --unstable-x flags to be passed to the formatter
-- https://docs.deno.com/runtime/reference/cli/fmt/#supported-file-types
--
-- Requires `--unstable-component` flag
local unstable_component = {
astro = "astro",
svelte = "svelte",
vue = "vue",
}
-- Requires `--unstable-sql` flag
local unstable_sql = {
sql = "sql",
}

local extensions = vim.tbl_extend("keep", {
css = "css",
html = "html",
-- js
javascript = "js",
javascriptreact = "jsx",
json = "json",
jsonc = "jsonc",
less = "less",
markdown = "md",
sass = "sass",
scss = "scss",
typescript = "ts",
typescriptreact = "tsx",
-- css
css = "css",
less = "less",
scss = "scss",
-- markup
html = "html",
svg = "svg",
xml = "xml",
-- data / config
json = "json",
jsonc = "jsonc",
yaml = "yml",
}, unstable_extensions)
-- other
markdown = "md",
}, unstable_component, unstable_sql)

---@type conform.FileFormatterConfig
return {
meta = {
url = "https://deno.land/manual/tools/formatter",
description = "Use [Deno](https://deno.land/) to format TypeScript, JavaScript/JSON and markdown.",
url = "https://docs.deno.com/runtime/reference/cli/fmt/",
description = "Use [Deno](https://deno.com/) to format TypeScript, JavaScript, JSON, Markdown and more.",
},
command = "deno",
cond = function(self, ctx)
Expand All @@ -43,14 +55,22 @@ return {
extension,
}

if unstable_extensions[extension] then
if unstable_component[extension] then
log.info(
"Adding `--unstable-component` to enable formatting of .%s files. See the Deno documentation for more information: https://docs.deno.com/runtime/reference/cli/formatter/#formatting-options-unstable-component",
"Adding `--unstable-component` to enable formatting of .%s files: https://docs.deno.com/runtime/reference/cli/fmt/#supported-file-types",
extension
)
formatter_args = vim.list_extend(formatter_args, { "--unstable-component" })
end

if unstable_sql[extension] then
log.info(
"Adding `--unstable-sql` to enable formatting of .%s files: https://docs.deno.com/runtime/reference/cli/fmt/#supported-file-types",
extension
)
formatter_args = vim.list_extend(formatter_args, { "--unstable-sql" })
end

return formatter_args
end,
}
Loading