Skip to content

Commit bec484f

Browse files
committed
feat: add pre-commit-hooks for spell checking, markdown linting, etc.
1 parent 46062cb commit bec484f

File tree

5 files changed

+166
-4
lines changed

5 files changed

+166
-4
lines changed

.github/CONTRIBUTING.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ When creating a pull request, please heed the following:
3333

3434
You will need [nix](https://github.com/NixOS/nix) & with flakes enabled.
3535

36-
After cloning the repo, run enter an environment with pnpm and vitepress installed first:
36+
After cloning the repo, run enter an environment with pnpm, vitepress, spell checker and markdown linter installed first:
3737

3838
```sh
3939
$ nix develop
@@ -46,4 +46,10 @@ Boot up the documentation site locally, with live reloading of the source code:
4646
$ pnpm run docs:dev
4747
```
4848

49+
If you made a lot of changes, run the following command to check for typos before submitting a pull request:
50+
51+
```sh
52+
$ typos -w
53+
```
54+
4955
After executing the above command, visit <http://localhost:5173> and try modifying the source code. You'll get live update.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ playground-temp
1818
temp
1919
TODOs.md
2020
.eslintcache
21+
.direnv/
22+
.pre-commit-config.yaml

docs/zh/preface.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Nixpkgs 源码等各种资料中提取出我需要的信息,同时还要忽略
6262
我写这本小书的原因只是因为没有人为当时还是新手的我做这件事,如上所述,社区的文档太乱了,所以我选择自己动手,丰衣足食。
6363
即使我知道我可能会犯错,但这总比什么都不做要好得多。
6464

65-
我希望这本书能帮助更多的人,让他们能够体验到 NixOS 的乐趣。希望你们喜欢它!
65+
我希望这本书能帮助更多的人,让他们能够体验到 NixOS 的乐趣。希望你们喜欢它!
66+
6667

6768
## 本书的特点
6869

flake.lock

+126-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+29-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
66
flake-utils.url = "github:numtide/flake-utils";
7+
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
78
};
89

910
outputs = {
1011
self,
1112
nixpkgs,
1213
flake-utils,
14+
pre-commit-hooks,
1315
}:
1416
flake-utils.lib.eachDefaultSystem (system: let
1517
overlays = [
@@ -21,13 +23,39 @@
2123
];
2224
pkgs = import nixpkgs {inherit overlays system;};
2325
pkgs_chromium = import nixpkgs {inherit system;};
24-
packages = with pkgs; [node2nix nodejs pnpm yarn git];
26+
packages = with pkgs; [
27+
node2nix
28+
nodejs
29+
pnpm
30+
yarn
31+
32+
git
33+
typos
34+
alejandra
35+
];
2536
in {
37+
checks = {
38+
pre-commit-check = pre-commit-hooks.lib.${system}.run {
39+
src = ./.;
40+
hooks = {
41+
typos.enable = true; # Source code spell checker
42+
alejandra.enable = true; # Nix linter
43+
};
44+
settings = {
45+
typos = {
46+
write = true; # Automatically fix typos
47+
ignored-words = [];
48+
};
49+
};
50+
};
51+
};
52+
2653
devShells.default = pkgs.mkShell {
2754
inherit packages;
2855

2956
shellHook = ''
3057
echo "node `${pkgs.nodejs}/bin/node --version`"
58+
${self.checks.${system}.pre-commit-check.shellHook}
3159
'';
3260
};
3361

0 commit comments

Comments
 (0)