aboutsummaryrefslogtreecommitdiffstats
path: root/lua/conform/formatters/darker.lua
blob: 5f47e6b5d525098c7579a2378b2fddbb8f003aac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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",
  }),
}