Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Add HCL format builtin #1353

Open
1 task done
prevostcorentin opened this issue Jan 18, 2023 · 6 comments
Open
1 task done

Add HCL format builtin #1353

prevostcorentin opened this issue Jan 18, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@prevostcorentin
Copy link
Contributor

prevostcorentin commented Jan 18, 2023

Issues

  • 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 prevostcorentin added the enhancement New feature or request label Jan 18, 2023
@jose-elias-alvarez
Copy link
Owner

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).

@prevostcorentin
Copy link
Contributor Author

Thanks, following is the associated PR #1361

@grimm26
Copy link

grimm26 commented Jan 23, 2023

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

@prevostcorentin
Copy link
Contributor Author

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

Thank you for the suggesting that.

@prevostcorentin
Copy link
Contributor Author

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

Following is the associated PR #1370

@grimm26
Copy link

grimm26 commented Jan 24, 2023

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" },                                                              
}),   

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants