Skip to content

feat: add pre-commit-hooks for spell checking, markdown linting, etc. #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ When creating a pull request, please heed the following:

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

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

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

If you made a lot of changes, run the following command to check for typos before submitting a pull request:

```sh
$ typos -w
```

After executing the above command, visit <http://localhost:5173> and try modifying the source code. You'll get live update.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ playground-temp
temp
TODOs.md
.eslintcache
.direnv/
.pre-commit-config.yaml
1 change: 1 addition & 0 deletions docs/zh/preface.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Nixpkgs 源码等各种资料中提取出我需要的信息,同时还要忽略

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


## 本书的特点

1. 以 NixOS 与 Flakes 为核心进行讲解,摈弃了传统的 Nix 配置方式
Expand Down
127 changes: 126 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};

outputs = {
self,
nixpkgs,
flake-utils,
pre-commit-hooks,
}:
flake-utils.lib.eachDefaultSystem (system: let
overlays = [
Expand All @@ -21,13 +23,39 @@
];
pkgs = import nixpkgs {inherit overlays system;};
pkgs_chromium = import nixpkgs {inherit system;};
packages = with pkgs; [node2nix nodejs pnpm yarn git];
packages = with pkgs; [
node2nix
nodejs
pnpm
yarn

git
typos
alejandra
];
in {
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
typos.enable = true; # Source code spell checker
alejandra.enable = true; # Nix linter
};
settings = {
typos = {
write = true; # Automatically fix typos
ignored-words = [];
};
};
};
};

devShells.default = pkgs.mkShell {
inherit packages;

shellHook = ''
echo "node `${pkgs.nodejs}/bin/node --version`"
${self.checks.${system}.pre-commit-check.shellHook}
'';
};

Expand Down