All Projects → legend80s → Commit Msg Linter

legend80s / Commit Msg Linter

Licence: mit
git commit message linter hook

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Commit Msg Linter

go-namecheck
Source code analyzer that helps you to maintain variable/field naming conventions inside your project.
Stars: ✭ 37 (-57.47%)
Mutual labels:  conventions, linter
Tlint
Tighten linter for Laravel conventions
Stars: ✭ 274 (+214.94%)
Mutual labels:  linter, conventions
Go Critic
The most opinionated Go source code linter for code audit.
Stars: ✭ 875 (+905.75%)
Mutual labels:  linter, conventions
Static Analysis
⚙️ A curated list of static analysis (SAST) tools for all programming languages, config files, build tools, and more.
Stars: ✭ 9,310 (+10601.15%)
Mutual labels:  linter
Joker
Small Clojure interpreter, linter and formatter.
Stars: ✭ 1,161 (+1234.48%)
Mutual labels:  linter
Vscode Gremlins
Gremlins tracker for Visual Studio Code: reveals invisible whitespace and other annoying characters
Stars: ✭ 78 (-10.34%)
Mutual labels:  linter
Hookmsrbysvm
hook msr by amd svm
Stars: ✭ 86 (-1.15%)
Mutual labels:  hook
Psscriptanalyzer
Download ScriptAnalyzer from PowerShellGallery
Stars: ✭ 1,137 (+1206.9%)
Mutual labels:  linter
React Selector Hooks
Collection of hook-based memoized selector factories for declarations outside of render.
Stars: ✭ 84 (-3.45%)
Mutual labels:  hook
Dynamicoc
深入理解 iOS 热修复原理
Stars: ✭ 76 (-12.64%)
Mutual labels:  hook
React Hook Mighty Mouse
🐭 React hook that tracks mouse events on selected element - zero dependencies
Stars: ✭ 75 (-13.79%)
Mutual labels:  hook
Sandhook
Android ART Hook/Native Inline Hook/Single Instruction Hook - support 4.4 - 11.0 32/64 bit - Xposed API Compat
Stars: ✭ 1,172 (+1247.13%)
Mutual labels:  hook
Jjexception
Protect the objective-c application(保护App不闪退)
Stars: ✭ 1,216 (+1297.7%)
Mutual labels:  hook
Linter Jscs
Atom JSCS linter providers
Stars: ✭ 69 (-20.69%)
Mutual labels:  linter
Delphihookutils
Delphi Hooking Library by Lsuper
Stars: ✭ 85 (-2.3%)
Mutual labels:  hook
Lint Staged
🚫💩 — Run linters on git staged files
Stars: ✭ 9,492 (+10810.34%)
Mutual labels:  linter
Lottie React
A lightweight React library for rendering complex After Effects animations in real time using Lottie.
Stars: ✭ 83 (-4.6%)
Mutual labels:  hook
Stylelint
A mighty, modern linter that helps you avoid errors and enforce conventions in your styles.
Stars: ✭ 9,350 (+10647.13%)
Mutual labels:  linter
Wechat Pc Hook Ws
微信PcHooker websocket api
Stars: ✭ 74 (-14.94%)
Mutual labels:  hook
Ysf
YSF Server Functions
Stars: ✭ 77 (-11.49%)
Mutual labels:  hook

Welcome to git-commit-msg-linter 👋

npm version npm downloads prerequisite node version Install Size

👀 Watching your every git commit message INSTANTLY 🚀.

git-commit-msg-linter-demo

A git "commit-msg" hook for linting your git commit message against the popular Angular Commit Message Guidelines. As a hook it will run at every commiting to make sure that the message to commit is valid against the conventions. If not the commit will be aborted.

Heavily inspired by pre-commit. Thanks.

简体中文

Install

npm install git-commit-msg-linter --save-dev

Just Install No Configurations Required and your commit message is under linting from now on.

💡 Tips: for husky 5 see Work With Husky 5.

Recommended Commit Message Format

<type>(<scope>): <short summary>
  │       │             │
  │       │             └─⫸ Summary in present tense. Not capitalized. No period at the end.
  │       │
  │       └─⫸ Commit Scope: Optional, can be anything specifying the scope of the commit change.
  |                          For example $location|$browser|$compile|$rootScope|ngHref|ngClick|ngView, etc.
  |                          In App Development, scope can be a page, a module or a component.
  │
  └─⫸ Commit Type: feat|fix|docs|style|refactor|test|chore|perf|ci|build|temp

The <type> and <summary> fields are mandatory, the (<scope>) field is optional.

Bad:

Correct spelling of CHANGELOG.

Good:

docs: correct spelling of CHANGELOG

Good (commit message with scope):

docs(CHANGELOG): correct spelling

The default commit types can be extended or modified by commitlinterrc.json.

Zero Configuration

Configuration Not Required! If it has to be customized we have the guide below.

The default types includes feat, fix, docs, style, refactor, test, chore, perf, ci, build and temp.

The default max-len is 100 which means the commit message cannot be longer than 100 characters.

commitlinterrc.json

Except for default types, you can add, overwrite or forbid certain types and so does the max-len.

For example if you have this commitlinterrc.json file below in the root directory of your project:

{
  "types": {
    "feat": "ユーザーが知覚できる新機能",
    "build": "ビルドシステムまたは外部の依存関係に影響する変更(スコープの例:gulp、broccoli、npm)",
    "deps": "依存関係を追加、アップグレード、削除",
    "temp": false,
    "chore": false
  },
  "max-len": 80,
  "debug": true
}

Which means:

  • Modify existing type feat's description to "ユーザーが知覚できる新機能".
  • Add two new types: build and deps.
  • temp is not allowed.
  • chore is forbidden as build covers the same scope.
  • Maximum length of a commit message is adjusted to 80.
  • Display verbose information about the commit message.

A more detailed commitlinterrc.json

{
  "lang": "en-US", // or "zh-CN". Set linter prompt's language
  "types": {
    "feat": "ユーザーが知覚できる新機能",
    "build": "ビルドシステムまたは外部の依存関係に影響する変更(スコープの例:gulp、broccoli、npm)",
    "deps": "依存関係を追加、アップグレード、削除",
    "docs": "ドキュメントのみ変更",
    "fix": false,
    "style": false,
    "refactor": false,
    "test": false,
    "perf": false,
    "ci": false,
    "temp": false,
    "chore": false
  },
  "min-len": 10,
  "max-len": 80,
  "example": "feat: 新機能",
  "scopeDescriptions": [
    "オプションで、コミット変更の場所を指定するものであれば何でもかまいません。",
    "たとえば、$ location、$ browser、$ compile、$ rootScope、ngHref、ngClick、ngViewなど。",
    "アプリ開発では、スコープはページ、モジュール、またはコンポーネントです。"
  ],
  "invalidScopeDescriptions": [
    "`scope`はオプションですが、括弧が存在する場合は空にすることはできません。"
  ],
  "subjectDescriptions": [
    "1行での変更の非常に短い説明。"
  ],
  "invalidSubjectDescriptions": [
    "最初の文字を大文字にしないでください",
    "最後にドット「。」なし"
  ],
  "showInvalidHeader": false,
  "debug": false
}

In this config, the one-line example and scope, subject's description section are modified as what your write in the commitlinterrc.json. And the the invalid header is hidden by set "showInvalidHeader": false

detailed-config-demo

Set Linting Prompter's Language

It will use your system's language as the default language. But two ways are provided also. Priority from high to low.

Set in commitlinterrc.json

{
  "lang": "zh-CN"
}

lang in ["en-US", "zh-CN"]

Set in bash profiles

echo 'export COMMIT_MSG_LINTER_LANG=zh-CN' >> ~/.zshrc

profiles such as .bash_profile, .zshrc etc.

Features

  1. Visualization, low cost to Learn
  2. Zero configuration
  3. Prompt error msg precisely, friendly to commit messge format unfamiliar developers
  4. i18 en-US and zh-CN supported
  5. Customizable for your team's format
  6. It works with the husky flow.

Why yet a new linter

Firstly it's very important to follow certain git commit message conventions and we recommend Angular's.

Secondly no simple git commit message hook ever exists right now. To Add, to overwrite or to remove types is not so friendly supported. Why not conventional-changelog/commitlint or husky, read the FAQs.

How it works

The commit-msg hook takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use it to validate your project state or commit message before allowing a commit to go through.

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

After installed, it will copy the hook {PROJECT_ROOT}/.git/hooks/commit-msg if it exists to {PROJECT_ROOT}/.git/hooks/commit-msg.old then the commit-msg will be overwritten by our linting rules.

To uninstall run the uninstall script instead of removing it manually because only in this way, the old commit-msg hook can be restored, so that your next commit messages will be ignored by the linter.

npm uninstall git-commit-msg-linter --save-dev

Before uninstalling, the commit-msg file will be restored and the commit-msg.old will be removed.

FAQs

1. Why not conventional-changelog/commitlint?

  • Configuration is relatively complex.
  • No description for type, unfriendly to commit newbies. Because every time your are wondering which type should I use, you must jump out of you commit context to seek documentation in the wild web.
  • To modify type description is also not supported. Unfriendly to non-english speakers. For example, all my team members are Japanese, isn't it more productive to change all the descriptions to Japanese?
  • To add more types is also impossible. This is unacceptable for project with different types already existed.

2. Work With Husky 5

This linter can work by standalone. But if you have husky 5 installed, because husky 5 will ignore the .git/hooks/commit-msg so a .husky/commit-msg need to be added manually:

npx husky add .husky/commit-msg ".git/hooks/commit-msg \$1"

Show the file content of .husky/commit-msg to make sure it has been added successfully otherwise do it manually.

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

.git/hooks/commit-msg $1

More details at issues 8.

TODO

  • [x] Existing rule can be overwritten and new ones can be added through commitlinterrc.json.
  • [ ] is-english-only should be configurable through commitlinterrc.json, default false.
  • [x] max-len should be configurable through commitlinterrc.json, default 100.
  • [x] First letter of subject must be a lowercase one.
  • [x] subject must not end with dot.
  • [x] Empty scope parenthesis not allowed.
  • [x] scope parenthesis must be of English which means full-width ones are not allowed.
  • [ ] Keep a space between Chinese and English character.
  • [x] Fix git merge commit not valid.
  • [x] Enable showing verbose information for debugging.
  • [x] Suggest similar but valid type on invalid input using did-you-mean.
  • [x] No backup when commit-msg.old existed.
  • [x] Display commit message on invalid error.
  • [x] i18n.
  • [x] Set lang in zshrc, or commitlinrrc.

Development

Publish

npm version patch / minor / major && npm publish && git push && git push --tags

References

  1. Angular Commit Message Guidelines
  2. Angular.js Git Commit Guidelines
  3. Google AngularJS Git Commit Message Conventions

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

📝 License

Copyright © 2019 legend80s.

This project is MIT licensed.


This README was generated with ❤️ by readme-md-generator

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].