Lefthook installation

To use Vale automatically when committing new changes, you need to install a hook manager named Lefthook.

Follow these steps to install Lefthook:

1- Install Node.js

Install the latest version of Node.js

https://nodejs.org/en

2- Install Lefthook

Inside the root folder of your project, Install the latest version of Lefthook using the following command:

npm install lefthook --save-dev

Note

If you are on windows, run Set-ExecutionPolicy RemoteSigned before installing lefthook

3- Add lefthook.yml

Inside the same folder, add lefthook.yml by running the following command:

lefthook install

4- Update lefthook.yml

Remove the existing content from lefthook.yml and add the following code:

pre-commit:
  commands:
    vale: # Requires Vale: https://docs.gitlab.com/ee/development/documentation/testing.html#install-linters
      tags: documentation style
      glob: '*.rst'
      run: 'if [ $VALE_WARNINGS ]; then minWarnings=warning; else minWarnings=error; fi; if command -v vale > /dev/null 2>&1; then if ! vale --config .vale.ini --no-wrap --minAlertLevel suggestion {staged_files}; then echo "ERROR: Fix any linting errors and make sure you are using the latest version of Vale."; exit 1; fi; else echo "ERROR: Vale not found. For more information, see https://docs.errata.ai/vale/install."; exit 1; fi'

Once you commit your change(s), Vale automatically looks for all staged files and checks them against your mentioned style guide(s). It stops the commit process once facing any issues (errors only). In cases of showing only warnings or suggestions, the commit process will continue.

5- Update .gitignore

Before pushing new change(s), add the following items to your .gitignore file:

node_modules

npm-debug.log

.nyc

.env

package.json

package-lock.json