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

This commit is contained in:
Ryan Yin 2024-03-16 17:11:37 +08:00 committed by GitHub
parent 46062cb884
commit 55d42d1e48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 165 additions and 3 deletions

View File

@ -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
@ -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
.gitignore vendored
View File

@ -18,3 +18,5 @@ playground-temp
temp
TODOs.md
.eslintcache
.direnv/
.pre-commit-config.yaml

View File

@ -64,6 +64,7 @@ Nixpkgs 源码等各种资料中提取出我需要的信息,同时还要忽略
我希望这本书能帮助更多的人,让他们能够体验到 NixOS 的乐趣。希望你们喜欢它!
## 本书的特点
1. 以 NixOS 与 Flakes 为核心进行讲解,摈弃了传统的 Nix 配置方式

View File

@ -1,5 +1,21 @@
{
"nodes": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
@ -18,6 +34,45 @@
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1703887061,
"narHash": "sha256-gGPa9qWNc6eCXT/+Z5/zMkyYOuRZqeFZBDbopNZQkuY=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "43e1aa1308018f37118e34d3a9cb4f5e75dc11d5",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1701802827,
@ -34,10 +89,65 @@
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1704874635,
"narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1704842529,
"narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "eabe8d3eface69f5bb16c18f8662a702f50c20d5",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": "nixpkgs_2",
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1708018599,
"narHash": "sha256-M+Ng6+SePmA8g06CmUZWi1AjG2tFBX9WCXElBHEKnyM=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "5df5a70ad7575f6601d91f0efec95dd9bc619431",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
@ -54,6 +164,21 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -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 = [
@ -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}
'';
};