Formatting



Consistent formatting makes code more readable and understandable. Hof automatically formats many languages with widely used defaults while also providing a means to customize or add new languages.

When you generate code with hof it will automatically format the output for known extensions and languages. This typically happens by running a container in the background, though some languages are handled directly in gocode. (See below)

hof will start a container the first time it is needed for you. You can fetch, run, and stop formatters manually with the hof fmt.

We have built several hof/formatters which use the most common tool for a language and use the most commonly used rules. You can build your own and configure generators to use them too, see the custom formatters section

hof fmt

hof/fmt is a command which will format any and all languages. You can create your own formatters as well.

hof needs a code formatter for the languages it generates. It runs the pre-output through before applying diff and merging with any custom code you added to output files. This is simplifies the job of template authors, but is also required to avoid unnecessary merge conflicts.

You will need Docker available to use this feature. Hof will pull and run containers in the background. You can disable this by setting an environment variable.

HOF_FMT_DISABLED=1

$ hof help fmt

With hof fmt, you can
  1. format any language from a single tool
  2. run formatters as api servers for IDEs and hof
  3. manage the underlying formatter containers

Usage:
  hof fmt [filepaths or globs] [flags]
  hof fmt [command]

Available Commands:
  info        get formatter info
  pull        docker pull a formatter
  start       start a formatter
  stop        stop a formatter
  test        test that formatter(s) are working

Flags:
      --fmt-data   include cue,yaml,json,toml,xml files, set to false to disable (default true)
  -h, --help       help for fmt

Global Flags:
  -E, --all-errors               print all available errors
  -i, --ignore-errors            turn off output and assume defaults at prompts
  -D, --include-data             auto include all data files found with cue files
  -V, --inject-env               inject all ENV VARs as default tag vars
  -I, --input stringArray        extra data to unify into the root value
  -p, --package string           the Cue package context to use during execution
  -l, --path stringArray         CUE expression for single path component when placing data files
  -q, --quiet                    turn off output and assume defaults at prompts
  -d, --schema stringArray       expression to select schema to apply to data files
      --stats                    print generator statistics
  -0, --stdin-empty              A flag that ensure stdin is zero and does not block
  -t, --tags stringArray         @tags() to be injected into CUE code
  -U, --user-files stringArray   file globs to embed into the root value (<cue-path>=<file-glob>), use % as slash to trim before
  -v, --verbosity int            set the verbosity of output
      --with-context             add extra context for data files, usable in the -l/path flag

Use "hof fmt [command] --help" for more information about a command.

Supported Languages

If a language you need is missing, open an issue. If you can, please provide a link to a common tool used for that language.


Language Tool
csharp csharpier
css prettier/css
cue gocode
go gocode
graphql prettier/graphql
groovy prettier/groovy
html prettier/html
java prettier/java
js prettier/babel
json gocode
jsx prettier/babel
less prettier/less
md prettier/markdown
php prettier/php
python black
rb prettier/ruby
rs prettier/rust
scss prettier/scss
toml gocode
ts prettier/typescript
tsx prettier/typescript
vue prettier/vue
xml gocode
yaml gocode