From 861088c163c231068531bf8230a5f058e07f8fcb Mon Sep 17 00:00:00 2001 From: LuckJMG <25126199+LuckJMG@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:14:07 -0300 Subject: [PATCH 1/2] docs(hook): husky v5 installation --- README.md | 66 +++++++++++++++++++++----------------- docs/guides-local-setup.md | 41 ++++++++++++----------- 2 files changed, 59 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 1d92871c4f..301806e0b6 100644 --- a/README.md +++ b/README.md @@ -18,21 +18,26 @@ ## Contents -- [What is commitlint](#what-is-commitlint) - - [Benefits using commitlint](#benefits-using-commitlint) -- [Getting started](#getting-started) -- [CLI](#cli) -- [Config](#config) -- [Shared configuration](#shared-configuration) -- [API](#api) -- [Tools](#tools) -- [Roadmap](#roadmap) -- [Version Support](#version-support) -- [Related projects](#related-projects) -- [License](#license) -- [Development](#development) - - [Install and run](#install-and-run) - - [Publishing a release](#publishing-a-release) +- [Get Started | Let's chat(https://conventional-changelog.github.io/commitlint)](#get-started--lets-chat-slack11--website) + - [Contents](#contents) + - [What is commitlint](#what-is-commitlint) + - [Benefits using commitlint](#benefits-using-commitlint) + - [Getting started](#getting-started) + - [CLI](#cli) + - [Config](#config) + - [Shared configuration](#shared-configuration) + - [API](#api) + - [Tools](#tools) + - [Roadmap](#roadmap) + - [Version Support](#version-support) + - [Related projects](#related-projects) + - [License](#license) + - [Development](#development) + - [Install and run](#install-and-run) + - [Package dependency overview](#package-dependency-overview) + - [Publishing a release](#publishing-a-release) + - [Publish a `next` release](#publish-a-next-release) + - [Move `next` to `latest`](#move-next-to-latest) --- @@ -93,27 +98,28 @@ npm install --save-dev @commitlint/config-conventional @commitlint/cli echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js ``` -To lint commits before they are created you can use Husky's 'commit-msg' hook. +To lint commits before they are created you can use Husky's `commit-msg` hook: -Install in your project `npm install husky --save-dev` or `yarn add -D husky`. - -After that, you can create a `.huskyrc` file or add to your `package.json` the following code for +```sh +# Install Husky v5 +npm install husky --save-dev +# or +yarn add husky --dev -Husky V4: +# Active hooks +npx husky install +# or +yarn husky install -```json -{ - "husky": { - "hooks": { - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" - } - } -} +# Add hook +npx husky add .husky/commit-msg "npx --no-install commitlint --edit $1" +# or +yarn husky add .husky/commit-msg "yarn commitlint --edit $1" ``` -Husky V5 +If the file `.husky/commit-msg` already exists, you can edit the file and put this: -``` +```sh # .husky/commit-msg # ... npx --no-install commitlint --edit $1 diff --git a/docs/guides-local-setup.md b/docs/guides-local-setup.md index df2f9f8f5d..2a3899adf2 100644 --- a/docs/guides-local-setup.md +++ b/docs/guides-local-setup.md @@ -10,9 +10,6 @@ Install `commitlint` and a `commitlint-config-*` of your choice as devDependency configure `commitlint` to use it. ```bash -# Create a package.json if needed -npm init - # Install and configure if needed npm install --save-dev @commitlint/{cli,config-conventional} echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js @@ -24,24 +21,32 @@ Alternatively the configuration can be defined in `.commitlintrc.js`, `.commitli Install `husky` as devDependency, a handy git hook helper available on npm. -```bash -npm install --save-dev husky +```sh +# Install Husky v5 +npm install husky --save-dev +# or +yarn add husky --dev + +# Active hooks +npx husky install +# or +yarn husky install + +# Add hook +npx husky add .husky/commit-msg "npx --no-install commitlint --edit $1" +# or +yarn husky add .husky/commit-msg "yarn commitlint --edit $1" ``` -This allows us to add [git hooks](https://git-scm.com/docs/githooks) directly into our `package.json` via the `husky.hooks` field. - -```json -// package.json -{ - "husky": { - "hooks": { - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" - } - } -} -``` +If the file `.husky/commit-msg` already exists, you can edit the file and put this: -Using `commit-msg` gives us exactly what we want: It is executed whenever a new commit is created. Passing husky's `HUSKY_GIT_PARAMS` to `commitlint` via the `-E|--env` flag directs it to the relevant edit file. `-e` would default to `.git/COMMIT_EDITMSG`. +```sh +# .husky/commit-msg +# ... +npx --no-install commitlint --edit $1 +# or +yarn commitlint --edit $1 +``` ## Test From c7fa22e83bac88f5beceda15f8f0ba273eedf351 Mon Sep 17 00:00:00 2001 From: Lucas Mosquera <25126199+LuckJMG@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:18:09 -0300 Subject: [PATCH 2/2] docs(readme): update readme --- README.md | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 301806e0b6..387a1572c0 100644 --- a/README.md +++ b/README.md @@ -18,26 +18,21 @@ ## Contents -- [Get Started | Let's chat(https://conventional-changelog.github.io/commitlint)](#get-started--lets-chat-slack11--website) - - [Contents](#contents) - - [What is commitlint](#what-is-commitlint) - - [Benefits using commitlint](#benefits-using-commitlint) - - [Getting started](#getting-started) - - [CLI](#cli) - - [Config](#config) - - [Shared configuration](#shared-configuration) - - [API](#api) - - [Tools](#tools) - - [Roadmap](#roadmap) - - [Version Support](#version-support) - - [Related projects](#related-projects) - - [License](#license) - - [Development](#development) - - [Install and run](#install-and-run) - - [Package dependency overview](#package-dependency-overview) - - [Publishing a release](#publishing-a-release) - - [Publish a `next` release](#publish-a-next-release) - - [Move `next` to `latest`](#move-next-to-latest) +- [What is commitlint](#what-is-commitlint) + - [Benefits using commitlint](#benefits-using-commitlint) +- [Getting started](#getting-started) +- [CLI](#cli) +- [Config](#config) +- [Shared configuration](#shared-configuration) +- [API](#api) +- [Tools](#tools) +- [Roadmap](#roadmap) +- [Version Support](#version-support) +- [Related projects](#related-projects) +- [License](#license) +- [Development](#development) + - [Install and run](#install-and-run) + - [Publishing a release](#publishing-a-release) ---