aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokuuva <okuuva@users.noreply.github.com>2023-09-29 09:12:23 +0300
committerGitHub <noreply@github.com>2023-09-28 23:12:23 -0700
commite359687e3684452ff45d7a5f1a59cd40b0bfa320 (patch)
treed5950d8944d11ba14c312beb60498310aa276162
parent92dabe1e17cc0bb462fd20660efa2196f8cde158 (diff)
feat: add darker (#80)
* feat: add darker * fix: darker args Added --no-color since we don't want color output. Also set --revision and --stdin-filename since running darker for a single file doesn't make much sense without them. * refactor: make darker args context aware If the buffer is modified we should set revision and stdin-filename in order not to lose changes. If it's not we should leave them unset so that we respect settings from pyproject.toml.
-rw-r--r--lua/conform/formatters/darker.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/lua/conform/formatters/darker.lua b/lua/conform/formatters/darker.lua
new file mode 100644
index 0000000..5f47e6b
--- /dev/null
+++ b/lua/conform/formatters/darker.lua
@@ -0,0 +1,35 @@
+local util = require("conform.util")
+---@type conform.FileFormatterConfig
+return {
+ meta = {
+ url = "https://github.com/akaihola/darker",
+ description = "Run black only on changed lines.",
+ },
+ command = "darker",
+ args = function(ctx)
+ -- make sure pre-save doesn't lose changes while post-save respects
+ -- the revision setting potentially set in pyproject.toml
+ if vim.bo[ctx.buf].modified then
+ return {
+ "--quiet",
+ "--no-color",
+ "--stdout",
+ "--revision",
+ "HEAD..:STDIN:",
+ "--stdin-filename",
+ "$FILENAME",
+ }
+ else
+ return {
+ "--quiet",
+ "--no-color",
+ "--stdout",
+ "$FILENAME",
+ }
+ end
+ end,
+ cwd = util.root_file({
+ -- https://github.com/akaihola/darker#customizing-darker-black-isort-flynt-and-linter-behavior
+ "pyproject.toml",
+ }),
+}