Nuten

Configuration

Config file

Use one of these names. When several sit in the same directory, the order of precedence is .nuon, .jsonc, .json.

  • nuten.nuon
  • nuten.jsonc
  • nuten.json
{
    line_width: 100
    indent_style: space
    indent_width: 4
    commas: inline
}

See Settings for every setting.

Config file lookup

  • The config file is looked up from the directory of the file being formatted, through each parent in turn, and the first one found is used
  • The lookup stops at the directory holding .git or the like
  • Without a config file, every setting takes its default
nuten format --config ./ci/nuten.nuon

With --config, there is no lookup and that file is used.

From treefmt-nix, the settings can also go in the module's settings.
From dprint, they go in dprint.json instead of the config file.
From Prettier, they go in the Prettier config.

Which files

{
    include: ["*.nu", "*.nuon"]
    exclude: ["vendor", "scripts/generated/*.nu"]
    respect_gitignore: true
}
  • include: the files picked when a directory is given
  • exclude: files and directories left out, even when a file is given directly
  • respect_gitignore: whether files ignored by .gitignore and the like are left out

Overrides

{
    line_width: 100
    overrides: [
        { include: ["tests/**/*.nu"], line_width: 120 }
    ]
}

Each entry picks files with include and exclude, and applies the rest of its settings to them. When a file is picked by several entries, the later one takes precedence.

EditorConfig

When there is an .editorconfig, its settings are used as well.

root = true

[*.nu]
indent_style = space
indent_size = 2
max_line_length = 100

.editorconfig is found as follows.

  • Every .editorconfig found from the directory of the file being formatted, through each parent in turn, is read
  • The lookup stops at an .editorconfig with root = true, or at the directory holding .git or the like
  • When several .editorconfig files give the same property, the one nearest the file being formatted is used

These properties are read. Properties not in the table, and values nuten cannot take, are ignored.

EditorConfig nuten Note
indent_style indent_style
indent_size indent_width When indenting with spaces
tab_width indent_width When indenting with tabs; indent_size if absent
end_of_line line_ending
max_line_length line_width off leaves lines unbroken by width

Settings written in the config file and its overrides take precedence over .editorconfig. Set editorconfig to false to leave .editorconfig unread.

From dprint and Prettier, nuten does not read .editorconfig. Prettier reads .editorconfig itself and passes it to nuten as Prettier options.

JSON Schema

nuten schema prints the JSON Schema of the config file.

nuten schema | save nuten.schema.json

In JSON or JSONC, point $schema at it and your editor completes the settings.

{
  "$schema": "./nuten.schema.json",
  "line_width": 100,
}

Last updated: