From 31c3ab68f2fddb8515451a762e899ad3c823529d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20T=C3=B3ta?= Date: Wed, 24 Jan 2024 20:35:21 +0300 Subject: [PATCH] AG-25860 Add lint-staged to the integration docs Merge in ADGUARD-FILTERS/aglint from fix/AG-25860 to master Squashed commit of the following: commit 0f6b078f9a27e7ee20c80eb095364ff11302c6ed Author: Slava Leleka Date: Wed Jan 24 18:45:32 2024 +0300 docs/repo-integration.md edited online with Bitbucket commit 0fafeb63341653171c75d65bfb96c1e6f7629955 Author: scripthunter7 Date: Wed Jan 24 16:41:08 2024 +0100 Update commit 54ac17551b5cd5f75abb7c8b50ca45d076f78522 Author: scripthunter7 Date: Wed Jan 24 16:35:06 2024 +0100 Add lint-staged to the integration docs --- docs/repo-integration.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/repo-integration.md b/docs/repo-integration.md index 2a29fc6..1f075b8 100644 --- a/docs/repo-integration.md +++ b/docs/repo-integration.md @@ -12,6 +12,7 @@ Table of contents: - [6. Use Husky hooks (optional)](#use-hooks) - [Add pre-commit hook](#pre-commit) - [Add post-merge hook](#post-merge) + - [Add lint-staged (optional)](#lint-staged) If you have a GitHub repository for adblock filters, you can integrate AGLint to your repository. In this document, we'll help you to do that. @@ -264,8 +265,39 @@ If one of them is changed, it will run `npm install` to sync your dependencies, > To make the hook work in Unix-like operating systems you may need to run > `chmod ug+x .husky/post-merge`. +### Add lint-staged (optional) + +In most cases, you don't need to lint all files in your repository in the `pre-commit` hook. +You can lint only staged files that are going to be committed. + +To do that, you can use [lint-staged] package. You can install it by running the following command: + +```bash +npm install -D lint-staged +``` + +After that, add the following content to your `package.json` file: + +```json +"lint-staged": { + "*.txt": "aglint" +} +``` + +(or simply run `npm pkg set lint-staged='{"*.txt": "aglint"}' --json`) + +This will tell lint-staged to run AGLint on all staged `.txt` files. +You can customize this to fit your needs according to [lint-staged documentation][lint-staged-config]. + +Also, don't forget to update your `pre-commit` hook to run `lint-staged` instead of `npm run lint`: + +```bash +npx husky set .husky/pre-commit "npx lint-staged" +``` [git]: https://git-scm.com/ [github-actions-docs]: https://docs.github.com/en/actions [husky]: https://www.npmjs.com/package/husky +[lint-staged-config]: https://github.com/lint-staged/lint-staged#configuration +[lint-staged]: https://www.npmjs.com/package/lint-staged [nodejs]: https://nodejs.org/en/