null-ls.nvim icon indicating copy to clipboard operation
null-ls.nvim copied to clipboard

Add HCL format builtin

Open prevostcorentin opened this issue 2 years ago • 6 comments

Issues

  • [X] I have checked existing issues and there are no existing ones with the same request.

Feature description

Hello,

I would like to see hclfmt, - a HCL configuration file formatter - supported as a built-in in null_ls. I done it locally and it is working fine.

Although I would like to make a pull request to apply the change, I understand that the contribution is too small for me being one of the null_ls contributors able to make a PR.

Below is the change.

Best regards

Help

No

Implementation help

-- lua/null-ls/builtins/formatting/hclfmt.lua
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")

local FORMATTING = methods.internal.FORMATTING

return h.make_builtin({
    name = "hclfmt",
    meta = {
        url = "https://github.com/fatih/hclfmt",
        description = "Formatter for HCL configuration files",
    },
    method = FORMATTING,
    filetypes = { "hcl" },
    generator_opts = {
        command = "hclfmt",
        to_stdin = true,
    },
    factory = h.formatter_factory,
})

prevostcorentin avatar Jan 18 '23 12:01 prevostcorentin

Looks good to me - feel free to open a PR (we don't have any restrictions on the size / scope of contributions, and all built-in contributions are always welcome).

jose-elias-alvarez avatar Jan 19 '23 19:01 jose-elias-alvarez

Thanks, following is the associated PR #1361

prevostcorentin avatar Jan 20 '23 19:01 prevostcorentin

hclfmt project is abandoned, can't you format hcl with terraform fmt?

grimm26 avatar Jan 23 '23 01:01 grimm26

I will try a hand at moving from hclfmt to terraform fmt.

Thank you for the suggesting that.

prevostcorentin avatar Jan 24 '23 10:01 prevostcorentin

There is already a builtin using terraform fmt. I simply bound its execution to hcl and nomad filetypes.

Following is the associated PR #1370

prevostcorentin avatar Jan 24 '23 10:01 prevostcorentin

There is already a builtin using terraform fmt. I simply bound its execution to hcl and nomad filetypes.

Following is the associated PR #1370

Yes, that's basically what I do in my config.

null_ls.builtins.formatting.terraform_fmt.with({                                            
     extra_filetypes = { "hcl" },                                                              
}),   

grimm26 avatar Jan 24 '23 17:01 grimm26