wiki/contributing/formatting/tools.md
dfh a6fd265d0a
Some checks failed
buildbot/nix-build .#checks.aarch64-darwin Build done.
buildbot/nix-build .#checks.aarch64-linux Build done.
buildbot/nix-build .#checks.x86_64-darwin Build done.
buildbot/nix-build .#checks.x86_64-linux Build done.
buildbot/nix-eval Build done.
docs: update contributing/formatting/tools
2024-08-02 02:13:46 +00:00

2.8 KiB

title description published date tags editor dateCreated
Formatting tools How to format code in Aux true 2024-08-02T02:13:44.468Z markdown 2024-05-19T12:41:51.196Z

Formatting tools

Please use the standard formatting tools for your language, and obey them over all Aux formatting guidelines. If there are no listed formatting tools, you should use the tool which is most commonly used for your language and add it to this page.

You should not configure your formatter, you should instead use its default options {.is-info}

Using treefmt

// TODO

Formatting manually

If you'd prefer to avoid treefmt, you can set up the language formatters manually.

Nix

For Nix, use pkgs.nixfmt-rfc-style.

nixfmt-rfc-style is based on nixfmt, however its style differs significantly from the original nixfmt, as its style is based on NixOS RFC 166. Please don't use the original nixfmt style.

Using nixfmt

With flakes

If you're using flakes, you can set your nix formatter in your flake.nix outputs.

For nixpkgs release earlier than 24.05, nixfmt-rfc-style is unavailable, so you may need to introduce an unstable nixpkgs input if you do not already have one. {.is-info}

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
  };

  outputs = { nixpkgs, ... }: {
    formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
  };
}

...and then use the formatter by running nix fmt

$ nix fmt

If you're using direnv, you may get an error like this

nixfmt: ./.direnv/flake-inputs/99iafi55mrsflh7agb1aqvgcdxraa612-source: openTempFileWithDefaultPermissions: permission denied (Read-only file system)

As a workaround, you can specify the files to format manually

$ nix fmt **/*.nix
With nix-shell

For nixpkgs release earlier than 24.05, nixfmt-rfc-style is unavailable, you must use an unstable channel. {.is-info}

$ nix-shell -p nixfmt-rfc-style

Once you've done so, you can format all files with

$ nixfmt **/*.nix
With nix shell

For nixpkgs release earlier than 24.05, nixfmt-rfc-style is unavailable, you must use an unstable channel. {.is-info}

$ nix shell github:nixos/nixpkgs#nixfmt-rfc-style

Once you've done so, you can format all files with

$ nixfmt **/*.nix

JavaScript, TypeScript, Markdown

For JavaScript, TypeScript or Markdown, use Prettier.

For more details, you can refer to the prettier installation guide.

Python

For Python, use Black.

Linting tools