Code Monkey home page Code Monkey logo

commitlint's Introduction

Lint commit messages

Demo generated with svg-term-cli

cat docs/assets/commitlint.json | svg-term --out docs/assets/commitlint.svg --frame --profile=Seti --height=20 --width=80

npm latest node compatibility Github Actions

  • ๐Ÿš“ Be a good commitizen
  • ๐Ÿ“ฆ Share configuration via npm
  • ๐Ÿค– Tap into conventional-changelog

Contents


What is commitlint

commitlint checks if your commit messages meet the conventional commit format.

In general the pattern mostly looks like this:

type(scope?): subject  #scope is optional; multiple scopes are supported (current delimiter options: "/", "\" and ",")

Real world examples can look like this:

chore: run tests on travis ci
fix(server): send cors headers
feat(blog): add comment section

Common types according to commitlint-config-conventional (based on the Angular convention) can be:

  • build
  • chore
  • ci
  • docs
  • feat
  • fix
  • perf
  • refactor
  • revert
  • style
  • test

These can be modified by your own configuration.

Benefits of using commitlint

Getting started

# Install commitlint cli and conventional config
npm install --save-dev @commitlint/{config-conventional,cli}
# For Windows:
npm install --save-dev @commitlint/config-conventional @commitlint/cli

# Configure commitlint to use conventional config
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:

# Install Husky v6
npm install husky --save-dev
# or
yarn add husky --dev

# Activate hooks
npx husky install
# or
yarn husky install

Add hook

Warning

It's necessary that you use commit-msg as the name for hook file. Read Git hooks documentation for more info.

npx husky add .husky/commit-msg  'npx --no -- commitlint --edit ${1}'

Or use installed package instead

npm pkg set scripts.commitlint="commitlint --edit"
npx husky add .husky/commit-msg 'npm run commitlint ${1}'

Check the husky documentation on how you can automatically have Git hooks enabled after install for different yarn versions.

Detailed Setup instructions

CLI

  • Primary way to interact with commitlint.
  • npm install --save-dev @commitlint/cli
  • Packages: cli

Config

  • Configuration is picked up from:
    • .commitlintrc
    • .commitlintrc.json
    • .commitlintrc.yaml
    • .commitlintrc.yml
    • .commitlintrc.js
    • .commitlintrc.cjs
    • .commitlintrc.mjs
    • .commitlintrc.ts
    • .commitlintrc.cts
    • commitlint.config.js
    • commitlint.config.cjs
    • commitlint.config.mjs
    • commitlint.config.ts
    • commitlint.config.cts
    • commitlint field in package.json
  • Packages: cli, core
  • See Rules for a complete list of possible rules
  • An example configuration can be found at @commitlint/config-conventional

Shared configuration

A number of shared configurations are available to install and use with commitlint:

โš ๏ธ If you want to publish your own shareable config then make sure it has a name aligning with the pattern commitlint-config-emoji-log or commitlint-config-your-config-name โ€” then in extend all you have to write is emoji-log or your-config-name.

Documentation

Check the main website.

API

  • Alternative, programmatic way to interact with commitlint
  • Packages:
    • format - Format commitlint reports
    • lint - Lint a string against commitlint rules
    • load - Load shared commitlint configuration
    • read - Read commit messages from a specified range or last edit
  • See API for a complete list of methods and examples

Tools

Roadmap

commitlint is considered stable and is used in various projects as a development tool.

Ideas: conventional-changelog/commitlint#94

Version Support and Releases

  • Node.js LTS >= 18
  • git >= 2.13.2

Releases

Security patches will be applied to versions which are not yet EOL.
Features will only be applied to the current main version.

Release Initial release
v18 10/2023
v17 05/2022
v16 12/2021
v15 11/2021
v14 10/2021
v13 05/2021
v12 02/2021
v11 09/2020

EOL is usually after around a year.

We're not a sponsored OSS project. Therefore we can't promise that we will release patch versions for older releases in a timely manner.
If you are stuck on an older version and need a security patch we're happy if you can provide a PR.

Related projects

License

Copyright by @marionebl. All commitlint packages are released under the MIT license.

Development

commitlint is developed in a mono repository.

Install and run

git clone [email protected]:conventional-changelog/commitlint.git
cd commitlint
yarn
yarn run build # run build tasks
yarn start # run tests, again on change
yarn run commitlint # run CLI

For more information on how to contribute please take a look at our contribution guide.

Testing

From the project root directory, use the following commands to run the test suite

yarn clean
yarn install
yarn build
yarn test

Package dependency overview

commitlint-dependencies

(Partly outdated)

Publishing a release

npm login
nvm use (if you have nvm installed)
yarn clean
yarn install
yarn build
yarn test
yarn run publish --otp <one-time password>

If something in between fails (like a new package was added and needs to be published for the first time but you forgot) you can use lerna publish from-package to publish anything that has not been published yet.

Create GitHub release

  1. Copy changelog entry for the new version
  2. Create release for the new tag: https://github.com/conventional-changelog/commitlint/releases
  3. Post in the commitlint Slack-channel

Publish a next release (or i.e. patch release)

npm login
nvm use (if you have nvm installed)
yarn clean
yarn install
yarn build
yarn test
npx lerna publish --conventional-commits --dist-tag [`next` | `[PATCH_RELEASE_VERSION]`] --otp <one-time password>

If for some reason this stops in between, you can manually publish missing packages like this:

npm publish <package-name> --tag [`next` | `[PATCH_RELEASE_VERSION]`] --otp <one-time password>
Publishing (new) packages for the first time
npm publish [PACKAGE_NAME] --access public

From within the folder first i.e. cd @commitlint/new-packages.

Move next to latest
npm login
npx lerna exec --no-bail --no-private --no-sort --stream -- '[ -n "$(npm v . dist-tags.next)" ] && npm dist-tag add ${LERNA_PACKAGE_NAME}@$(npm v . dist-tags.next) latest --otp <one-time password>'

Remove next:

npx lerna exec --no-bail --no-private --no-sort --stream -- '[ -n "$(npm v . dist-tags.next)" ] && npm dist-tag rm ${LERNA_PACKAGE_NAME} next --otp <one-time password>'

commitlint's People

Contributors

renovate[bot] avatar marionebl avatar escapedcat avatar renovate-bot avatar bycedric avatar armano2 avatar dependabot[bot] avatar joberstein avatar songhn233 avatar ybiquitous avatar curly210102 avatar adeattwood avatar scrum avatar tehraninasab avatar backflip avatar jlegrone avatar scop avatar chalkygames123 avatar sdzialowski-godaddy avatar simeonc avatar honzajavorek avatar dangreen avatar fguitton avatar satazor avatar mike-north avatar phillip9587 avatar tomasen avatar thekangaroo avatar vighnesh153 avatar whizark avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.