mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
chore: add a more ergonomic (and cleaner) devshell
- project a pre-commit hook for contributors - add an editorconfig
This commit is contained in:
parent
27e2435aa7
commit
f9a8373893
5 changed files with 109 additions and 3 deletions
29
.editorconfig
Normal file
29
.editorconfig
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Editor configuration, see http://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# Ignore diffs/patches
|
||||
[*.{diff,patch}]
|
||||
end_of_line = unset
|
||||
insert_final_newline = unset
|
||||
trim_trailing_whitespace = unset
|
||||
indent_size = unset
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[tests/cases/**]
|
||||
end_of_line = unset
|
||||
insert_final_newline = unset
|
||||
trim_trailing_whitespace = unset
|
||||
charset = unset
|
||||
indent_style = unset
|
||||
indent_size = unset
|
15
README.md
15
README.md
|
@ -116,6 +116,21 @@ Let's get Alejandra on our systems:
|
|||
- [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt)
|
||||
- [nixfmt](https://github.com/serokell/nixfmt)
|
||||
|
||||
## Contributing
|
||||
|
||||
#### With `direnv`
|
||||
|
||||
```console
|
||||
$ direnv allow
|
||||
```
|
||||
|
||||
#### Without `direnv`
|
||||
|
||||
```console
|
||||
$ nix develop -c $SHELL
|
||||
$ menu
|
||||
```
|
||||
|
||||
## Footnotes
|
||||
|
||||
[^benchmark-specs]:
|
||||
|
|
16
flake.lock
generated
16
flake.lock
generated
|
@ -38,6 +38,21 @@
|
|||
"type": "github"
|
||||
}
|
||||
},
|
||||
"devshell": {
|
||||
"locked": {
|
||||
"lastModified": 1643393796,
|
||||
"narHash": "sha256-+wb2OFWJjXUZw3HQezACc9Lj/5uuhNpUtrjDiIYw8H4=",
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"rev": "fff3dc6e4538f6df85ee3027f13cc7730b23f61d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "devshell",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"fenix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
|
@ -111,6 +126,7 @@
|
|||
"root": {
|
||||
"inputs": {
|
||||
"alejandra": "alejandra",
|
||||
"devshell": "devshell",
|
||||
"fenix": "fenix",
|
||||
"flakeCompat": "flakeCompat",
|
||||
"flakeUtils": "flakeUtils",
|
||||
|
|
27
flake.nix
27
flake.nix
|
@ -20,6 +20,7 @@
|
|||
treefmt.url = "github:numtide/treefmt";
|
||||
treefmt.inputs.flake-utils.follows = "flakeUtils";
|
||||
treefmt.inputs.nixpkgs.follows = "nixpkgs";
|
||||
devshell.url = "github:numtide/devshell";
|
||||
};
|
||||
outputs =
|
||||
inputs:
|
||||
|
@ -31,6 +32,7 @@
|
|||
nixpkgs = import inputs.nixpkgs { inherit system; };
|
||||
cargoToml = builtins.fromTOML ( builtins.readFile ./Cargo.toml );
|
||||
treefmt = inputs.treefmt.defaultPackage.${ system };
|
||||
devshell = inputs.devshell.legacyPackages.${ system };
|
||||
fenix = inputs.fenix.packages.${ system };
|
||||
fenixPlatform = nixpkgs.makeRustPlatform { inherit ( fenix.latest ) cargo rustc; };
|
||||
in
|
||||
|
@ -60,11 +62,16 @@
|
|||
};
|
||||
};
|
||||
devShell =
|
||||
nixpkgs.mkShell
|
||||
devshell.mkShell
|
||||
{
|
||||
imports = [ "${ devshell.extraModulesDir }/git/hooks.nix" ];
|
||||
git.hooks = {
|
||||
enable = true;
|
||||
pre-commit.text = builtins.readFile ./pre-commit.sh;
|
||||
};
|
||||
name = "alejandra";
|
||||
packages = [
|
||||
fenix.rust-analyzer
|
||||
fenix.latest.cargo
|
||||
fenix.latest.clippy
|
||||
fenix.latest.rust-src
|
||||
fenix.latest.rustc
|
||||
|
@ -75,7 +82,21 @@
|
|||
nixpkgs.nodePackages.prettier
|
||||
nixpkgs.nodePackages.prettier-plugin-toml
|
||||
nixpkgs.shfmt
|
||||
treefmt
|
||||
];
|
||||
commands = [
|
||||
{
|
||||
package = fenix.latest.cargo;
|
||||
name = "cargo";
|
||||
help = "the cargo tool";
|
||||
}
|
||||
{
|
||||
package = treefmt;
|
||||
category = "formatters";
|
||||
}
|
||||
{
|
||||
package = nixpkgs.editorconfig-checker;
|
||||
category = "formatters";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
25
pre-commit.sh
Normal file
25
pre-commit.sh
Normal file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1; then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=$(${git}/bin/git hash-object -t tree /dev/null)
|
||||
fi
|
||||
|
||||
diff="git diff-index --name-only --cached $against --diff-filter d"
|
||||
all_files=($($diff))
|
||||
|
||||
# Format the entire tree.
|
||||
treefmt
|
||||
|
||||
# check editorconfig
|
||||
editorconfig-checker -- "${all_files[@]}"
|
||||
if [[ $? != '0' ]]; then
|
||||
printf "%b\n" \
|
||||
"\nCode is not aligned with .editorconfig" \
|
||||
"Review the output and commit your fixes" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue