local null_ls = require('null-ls')
local opts = {
  sources = {
    null_ls.builtins.diagnostics.mypy,
    null_ls.builtins.diagnostics.flake8.with({
      extra_args = {"--select","E,W,F","--ignore","E501,E402,E722,W503","--max-line-length","150"}
    }),
    null_ls.builtins.formatting.autoflake,
    null_ls.builtins.formatting.autopep8.with({
      extra_args = {"--select","E,W,F","--ignore","E501,E402,E722,W503","--max-line-length","150"}
    }),
  },
  -- autoformat on save
  on_attach = function(client, bufnr)
    if client.supports_method("textDocument/formatting") then
      vim.api.nvim_clear_autocmds({
        group = augroup,
        buffer = bufnr,
      })
      vim.api.nvim_create_autocmd("BufWritePre", {
        group = augroup,
        buffer = bufnr,
        callback = function()
          vim.lsp.buf.format({ bufnr = bufnr })
        end,
      })
    end
  end,
}

return opts
