javaluaformattingneovimneovim-plugin

Neovim configuration setup with none_ls


I'm configuring my none-ls.lua file for neovim right now and I'm trying to to find the best builtin formatting for java. But there are too many different types of java formatting builtins out there. Does anyone know the the most well known formatting for java.

This is what my config looks like right now:

return {
    "nvimtools/none-ls.nvim",
    config = function()
        local null_ls = require("null-ls")
        null_ls.setup({
            sources = {
                null_ls.builtins.formatting.stylua,
                null_ls.builtins.formatting.black,
                null_ls.builtins.formatting.isort,
            },
        })

        vim.keymap.set("n", "<leader>gf", vim.lsp.buf.format, {})
    end,
}

I've been searching on google for the past hour to find the best formatting out there. But i can't find it, because there are just too many. And I don't want to waste time finding out which of the different ones work and which don't.

Thank you for you help!


Solution

  • My NVIM-CONFIG

    I woudl not recommend any of the ones you listed, I primarly code in Java/Spring-Boot.

    My recommendation:

      config = function()
        local null_ls = require("null-ls")
        null_ls.setup({
          sources = {
            -- JAVA
            null_ls.builtins.formatting.google_java_format,
            null_ls.builtins.diagnostics.checkstyle.with({
              extra_args = { "-c", "/google_checks.xml" },
            }),
            -- --------------------------------------------
            -- rest of config...
          },
        })
    
        vim.keymap.set("n", "<leader>cf", vim.lsp.buf.format, {})
      end,
    }
    

    My Configurations are linked above. In case you want to see my overall setup for other languages like Js, Ts, Py, Bash.