Skip to content

Format

Formatters help your code be consistent, beautiful and more maintainable.

formatBash

Ensure that Bash code is formatted according to shfmt.

Types:

  • formatBash:
    • enable (boolean): Optional. Defaults to false.
    • targets (listOf str): Optional. Files or directories (relative to the project) to format. Defaults to the entire project.

Example:

{
  formatBash = {
    enable = true;
    targets = [
      "/" # Entire project
      "/file.sh" # A file
      "/directory" # A directory within the project
    ];
  };
}
m . /formatBash

formatMarkdown

Warning

This function is only available on Linux at the moment.

Ensure that Markdown code is formatted according to doctoc.

Types:

  • formatMarkdown:
    • enable (boolean): Optional. Defaults to false.
    • doctocArgs (listOf str): Optional. Extra CLI flags to propagate to doctoc. Defaults to [ ].
    • targets (listOf str): File s (relative to the project) to format.

Example:

1
2
3
4
5
6
7
{
  formatMarkdown = {
    enable = true;
    doctocArgs = [ "--title" "# Contents" ];
    targets = [ "/README.md" ];
  };
}
m . /formatMarkdown

formatNix

Ensure that Nix code is formatted according to nixfmt.

Types:

  • formatNix:
    • enable (boolean): Optional. Defaults to false.
    • targets (listOf str): Optional. Files or directories (relative to the project) to format. Defaults to the entire project.

Example:

{
  formatNix = {
    enable = true;
    targets = [
      "/" # Entire project
      "/file.nix" # A file
      "/directory" # A directory within the project
    ];
  };
}
m . /formatNix

formatPython

Ensure that Python code is formatted according to Black and isort.

Types:

  • formatPython (attrsOf targetType): Optional. Mapping of names to format targets. Defaults to { }.
  • targetType (submodule):
    • config (atrrs): Optional.
    • targets (listOf str): Optional. Files or directories (relative to the project) to format. Defaults to the entire project.

Example:

1
2
3
4
5
6
7
8
{
  formatPython = {
    my-config = {
      targets = ["/"];
      config = {};
    };
  };
}
m . /formatPython/my-config

formatTerraform

Ensure that Terraform code is formatted according to Terraform FMT.

Types:

  • formatTerraform:
    • enable (boolean): Optional. Defaults to false.
    • targets (listOf str): Optional. Files or directories (relative to the project) to format. Defaults to the entire project.

Example:

{
  formatTerraform = {
    enable = true;
    targets = [
      "/" # Entire project
      "/main.tf" # A file
      "/terraform/module" # A directory within the project
    ];
  };
}
m . /formatTerraform

formatYaml

Ensure that YAML code is formatted according to yamlfix.

Types:

  • formatYaml:
    • enable (boolean): Optional. Defaults to false.
    • targets (listOf str): Optional. Files or directories (relative to the project) to format. Defaults to the entire project.

Example:

{
  formatYaml = {
    enable = true;
    targets = [
      "/" # Entire project
      "/main.yaml" # A file
      "/yamls/" # A directory within the project
    ];
  };
}
m . /formatYaml