dnscontrol icon indicating copy to clipboard operation
dnscontrol copied to clipboard

"fmt" should be more standard

Open tlimoncelli opened this issue 1 year ago • 5 comments

Is your feature request related to a problem? Please describe.

The default formatting for JavaScript that popular code editors use is very different than what dnscontrol fmt generates.

Describe the solution you'd like

fmt should format code like other systems. Our format lost the format wars. Let's accept defeat and be like them.

Also.... I'm sick of sending PRs back to my co-workers who use such editors.

Describe alternatives you've considered Get new coworkers. (turns out... I like them for other reasons)

Additional context n/a

tlimoncelli avatar Dec 13 '24 02:12 tlimoncelli

prettier is probably the most often used tool for reformatting code and it supports plenty of programming languages. Still, it is sometimes interesting to identify how to get it peforming nicely side-by-side with the respective linter. There are usually plugins for that purpose.

e.g. prettier + eslint for javascript. Here an guide about the prettier / eslint / vscode combination.

working with git hooks to trigger a pre-commit format check, might be an idea as well (vs. format check on ci level, or having both things in place).

Not sure if that input helps...

KaiSchwarz-cnic avatar Dec 13 '24 09:12 KaiSchwarz-cnic

I wonder how users would feel if "dnscontrol fmt" just called prettier :-(

tlimoncelli avatar Dec 13 '24 13:12 tlimoncelli

CC @jpbede who wrote the original "fmt" command.

tlimoncelli avatar Dec 13 '24 13:12 tlimoncelli

I'm more than happy to go down the prettier route, considering that jsbeautifier-go isn't maintained since a long time. We just need to think about how we handle the prettier dependency.

Edit: Or we drop the fmt support at all and describe how a user could do it on their own with prettier and pre-commit hooks.

jpbede avatar Dec 13 '24 13:12 jpbede

My preference would be for fmt to just call prettier. If it doesn't exist, it can print a helpful message.

Sadly prettier really wants to print the domain name on a separate line:

D("stackauth.dev", REG_CSCGLOBAL,

Becomes:

D(
    "stackauth.dev",
    REG_CSCGLOBAL,

Maybe there's a different formatter that can be configured not to do that. Or... maybe I'll just learn to love the new format.

tlimoncelli avatar May 13 '25 20:05 tlimoncelli