legend80s / git-commit-msg-linter Goto Github PK
View Code? Open in Web Editor NEWgit commit message linter hook
License: MIT License
git commit message linter hook
License: MIT License
I. Currently, I can modify/overwrite the type section and I can define my own.
************* Invalid Git Commit Message **************
commit message: fix: test
correct format: (): => Can I modify commit pattern?
example: docs: update README => This section is hardcoded in hook. Is there any place where I can put README file with my example?
II.
scope:
Optional, can be anything specifying place 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.
subject:
A very short description of the change in one line.
Can I change the description in these two sections?
I can't install commit-msg-linter, all other hooks work fine.
git init
pnpm init
pnpm add -D husky
pnpm add -D git-commit-msg-linter
pnpm exec husky install
git add .
git commit -m "hello"
sh: .git/hooks/commit-msg: No such file or directory
husky - commit-msg hook exited with code 127 (error)
husky - command not found in PATH=/home/zau/.asdf/shims:/home/zau/.asdf/bin:/usr/lib/git-core:/home/zau/.local/share/pnpm:/opt/sonar-scanner/bin:/home/zau/.gem/ruby/3.0.0/bin:/home/zau/.yarn/bin:/home/zau/.config/yarn/global/node_modules/.bin:/home/zau/.pyenv/shims:/home/zau/.pyenv/bin:/usr/share/pyenv/plugins/pyenv-virtualenv/shims:/home/zau/bin:/usr/local/bin:/home/zau/.npm-global/bin:/home/zau/.pyenv/bin:/opt/sonar-scanner/bin:/home/zau/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/zau/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/var/lib/snapd/snap/bin:/usr/local/sbin:/var/lib/flatpak/exports/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/zau/.local/bin:/home/zau/.local/share/gem/ruby/3.0.0/bin
Using asdf*
git: 2.39.1
pnpm: 7.26.3
node: 19.6.0
package.json
{
"name": "husky-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"git-commit-msg-linter": "^4.5.0",
"husky": "^8.0.3"
}
}
I configure the config file to pt-BR but the message continue in english:
my commitlinterrc.json:
{
"lang": "pt-BR",
"min-len": 8,
"max-len": 100,
"showInvalidHeader": false
}
I think a found the problem.
On the getLanguage function it converts to Lower:
/**
* @returns {string}
*/
function getLanguage(configLang) {
const lang =
configLang ||
process.env.COMMIT_MSG_LINTER_LANG ||
Intl.DateTimeFormat().resolvedOptions().locale;
return lang && lang.toLowerCase();
}
So "pt-BR" ends up as "pt-br"
and it was not found in i18n because i18n["pt-BR"] does not exist
Hello! First of all, thanks for this awesome lint.
I think that the example of a right formatted commit message for pt-BR language is wrong. I am brand new to open source contributing but I am looking forward to providing enough information to solve this problem, or even open the PR to fix the issue.
The thing is if we set the language to pt-BR
, if we try to commit with the example provided in the error message, the error still persists due to first letter being capitalized.
For example, if I try to do this
git commit -m "teste"
It gives me this error message with the following:
exemplo: docs: Atualiza o README com link para a nova documentação
If I try to commit with the example (in Portugue "exemplo") message, I still can not commit because the first letter is capitalized.
Is it possible to run the script for a range of commits from command line?
Something like:
commit-msg-linter sha1 sha2
So it can be ran from CI to make sure every commit message from sha1 and sha2 are valid.
Hey thanks for this great work. I'm totally happy with with your module, but iI found a Bug with my configuration. I couldn't get it to work with a custom example message.
Here is my config:
{
"lang": "en-US",
"types": {
"build": "Changes that affect the build system or external dependencies",
"ci": "Changes to our CI configuration files and scripts",
"docs": "Documentation only changes",
"feat": "A new feature",
"fix": "A bug fix",
"perf": "A code change that improves performance",
"refactor": "A code change that neither fixes a bug nor adds a feature",
"test": "Adding missing tests or correcting existing tests"
},
"min-len": 10,
"max-len": 80,
"scopeRequired": false,
"example": "feat(root): new button component (#1403)",
"scopeDescriptions": [
"Add one of these scopes:",
" root|storybook|config|helper|mock-api|scripts|stories|types"
],
"validScopes": ["root", "storybook", "config", "helper"],
"invalidScopeDescriptions": [
"\n A scope is required!"
],
"subjectDescriptions": [
"Write a summary about your work"
],
"invalidSubjectDescriptions": [
"\n A summary in present tense, not capitalized and without period at the end, is required!"
],
"showInvalidHeader": false,
"debug": false
}
I was also actually searching in your code where the problem is and saw that you never set or use the example key from the custom configuration. Can you add something like this to your module?
// commit-msg-linter.js
123
124 if (!validateMessage(msg, {
125 ...rest,
126
127 mergedTypes,
128 maxLen,
129 minLen,
130 verbose,
131 example: config.example ? config.example : example, <---- here
132 showInvalidHeader,
133 scopeDescriptions,
134 invalidScopeDescriptions,
135 subjectDescriptions,
136 invalidSubjectDescriptions,
137 postSubjectDescriptions,
138
139 lang,
140 englishOnly,
141 scopeRequired,
142 })) {
143 process.exit(1);
144 } else {
145 process.exit(0);
146 }
147
It is a solution that works, but maybe you know a better way.
thanks, best
请教下vite创建的vue项目应该怎么设置可以生效?我看之前vue-cli的项目应该是自带了yorkie所以直接在package.json里配置pre-commit就可以了... 现在vite不支持这个应该怎么配置? 我搜了搜都说要用husky 想请教一下有不用husky的方案么?
The .git/hooks/commit-msg of my project is at this path: "C:\Workplace\One drive\Example-Project.git\hooks\commit-msg"
Since there is a space at "\One drive" in the path, the lib doesn't work correctly because it configures the path to the lib in the commit-msg file without the quotes, like that:
#!/usr/bin/env bash
#
# [email protected] 03/04/2024, 14:57:24
# id=commit-msg-linter - THE id COMMENT SHOULD NOT BE DELETED OR MODIFIED!
# It's used to check whether this commit-msg hook file is created by us,
# if it is then we can remove it confidently on uninstallation.
cat C:/Workplace/One drive/Example-Project/node_modules/commit-msg-linter/commit-msg-linter.js | node --input-type=commonjs
When this should be like (with quotes):
cat "C:/Workplace/One drive/Example-Project/node_modules/commit-msg-linter/commit-msg-linter.js" | node --input-type=commonjs
The actual version results in an error message at the cat command.
(sorry for the bad english since its not my first language)
Hello good job! Thank you for creating this wonderful lint.
You have the possibility to include a field of
additional information in commitlinterrc.json
and display along with other information?
Is it possible to require scope? We have a monorepo and we want every message to contain a scope.
E.g. feat(web): new buttons
must have (web)
in the commit message or it fails!
Hi, after installation of lint-staged/husky (last version), commit-msg-linter stopped working. It seems commit-msg hook is not being called. Thanks
Run node node_modules/git-commit-msg-linter/install.js
will print some logs what I don't need. Support node node_modules/git-commit-msg-linter/install.js --silent
to keep quiet.
I'm getting the following error when trying to commit just after installing git-commit-msg-linter
in my project:
error: cannot spawn .git/hooks/commit-msg: No such file or directory
The project is just Vue.js boilerplate created with Vite. You can check it here.
My commit-msg
file using the current version of git-commit-msg-linter
is the following:
# [email protected] 3/29/2023, 3:54:43 PM
# id=commit-msg-linter - THE id COMMENT SHOULD NOT BE DELETED OR MODIFIED!
# It's used to check whether this commit-msg hook file is created by us,
# if it is then we can remove it confidently on uninstallation.
cat E:\Dev\Treinamentos\my-games-list\.yarn\unplugged\git-commit-msg-linter-npm-4.9.2-060e731a8e\node_modules\git-commit-msg-linter\commit-msg-linter.js | node --input-type=commonjs
I managed to fix this error rolling git-commit-msg-linter
back to the version I was using before on my projects (version 4.1.2) which has the following commit-msg
file:
#!/bin/bash
#
# Solve the problem of [Wishlist: support for ES6 modules. #14].
# https://github.com/legend80s/commit-msg-linter/issues/14
# This shell script template is from: https://google.github.io/styleguide/shellguide.html
# $0: .git/hooks/commit-msg, $1: .git/COMMIT_EDITMSG, $2: , $3:
# node '.git/hooks/commit-msg-linter.js' $1
# id=commit-msg-linter - The comment SHOULD NOT BE DELETED.
# https://nodejs.org/api/packages.html#--input-type-flag
cat .git/hooks/commit-msg-linter.js | node --input-type=commonjs
OS: Windows 11
Node: v18.15.0
Yarn: 3.5.0 (I have enabled PnP)
I'm trying to use commit-msg-linter
and Husky v5
, if I have husky installed the commit-msg-linter
doesn't work, but if I uninstall husky, everything works.
Sync with npm. This will help this project easier to understand and easier to spread this project.
After renaming this repo, github will auto redirect to https://github.com/legend80s/git-commit-msg-linter
if people visit commit-msg-linter
.
你好,请问这支持全局安装吗
Dear git-commit-msg-linter maintainers,
Thank you for your contribution to the open-source community.
This issue was automatically created to inform you a new "postinstall" script was added to version 3.3.0 of git-commit-msg-linter.
The "postinstall" script may run automatically upon installing the package.
scripts
section from the package.json file:
{
"pub:patch": "npm version patch",
"pub:minor": "npm version minor",
"pub:major": "npm version major",
"lint": "eslint *.js",
"lint:fix": "eslint --fix *.js",
"install": "echo '[git-commit-msg-linter] install start.' && node install.js",
"postinstall": "echo '[git-commit-msg-linter] postinstall start.' && node install.js",
"uninstall": "node uninstall.js",
"preversion": "npm run lint",
"postversion": "npm publish && git push && git push --tags",
"test": "echo open \"https://github.com/legend80s/commit-msg-linter-test\" && exit 0"
}
Our service monitors the open-source ecosystem and informs popular packages' owners in case of potentially harmful activity.
If you find this behavior legitimate, kindly close and ignore this issue. Read more
In the docs you say to install using the command:
npm install git-commit-msg-linter --save-dev
But in the docs the command used is gcam "message".
For this command work we shouldn't install it globally?
don't work with bun cli
Does it take some additional configuration to work with Husky 6?
Husky is up and running and the commit-msg-linter is installed but it does not run any validations.
My envirioment:
node 15.14.0
git-commit-msg-linter 3.1.0
husky 6.0.0
git version 2.30.2.windows.1
Tks
In JavaScript, the .replaceAll() function is one of the new features in ECMAScript 2021. Node.js also requires Node.js version 15 or later to support this function.
So, if you are using Node.js version 15 or later, you are free to use the .replaceAll() function. However, if you are using Node.js version less than 15, you cannot use this function and should use the replace() method instead.
is there any way to set commit message only be in English?
englishOnly
should check complete languageFirst letter of subject must be a lowercase one.
The issue #7 was not resolved. I'm trying to use your last solution @legend80s, but I'm receiving the error below:
ℹ No staged files match any configured task.
(node:98010) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
at readFile (fs.js:326:10)
at internal/util.js:297:30
at new Promise ()
at readFile (internal/util.js:296:12)
at main (/Users/viniciuscarvalho/Projects/hub-api/.git/hooks/commit-msg:47:5)
at Object. (/Users/viniciuscarvalho/Projects/hub-api/.git/hooks/commit-msg:56:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
(Use node --trace-warnings ... to show where the warning was created)
(node:98010) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:98010) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
[feat/signup 656afe6] asdfsdaf
1 file changed, 6 insertions(+), 6 deletions(-)
I have a all-in-one tool (@zanminkian/git-hooks) using this npm package as its dependency to check the commit message. The tool of mine will not install if user don't run git-hooks install
. But I cannot control it because git-commit-msg-linter
will install automatically, which means it will write the .git/hooks/commit-msg
file automatically.
I want the dependency - git-commit-msg-linter
do not setup postinstall script in its package.json
. But this is a big breaking change which should not come true. The solution is extracting the commit-msg-linter.js
to a single npm library, named commit-msg-linter
(or any other name). git-commit-msg-linter
uses commit-msg-linter
as its dependency.
May be we have to change this git repo to a monorepo.
Great tool! I'm missing an option to define valid scopes, which are then validated on pre-commit.
{
"scopeDescriptions": [
"Required, should be the name of the npm package affected.",
"The following is the list of supported scopes:",
"workspace, package1, package2, package3"
],
"invalidScopeDescriptions": [
"`scope` is required and its parenthesis cannot be empty."
],
"scopeRequired": true,
}
How does the linter know, which scopes are valid? workspace, package1, package2, package3
Or am I missing something?
Add an option validScopes: Array<string> = []
{
// ...
"validScopes": ["workspace", "package1", "package2", "package3"],
"scopeRequired": true,
}
Validation:
const invalidScope = Array.isArray(validScopes) && validScopes.length > 0 && !validScopes.includes(scope);
Change in file commit-msg-linter/commit-msg-linter.js
603 function describeTypes(mergedTypes, suggestedType = '') {
604 const types = Object.keys(mergedTypes);
605 const maxTypeLength = [...types].sort((t1, t2) => t2.length - t1.length)[0].length;
add line 604
change line 605
603 function describeTypes(mergedTypes, suggestedType = '') {
604 const sortObject = o => Object.keys(o).sort().reduce((r, k) => (r[k] = o[k], r), {})
605 const types = Object.keys(sortObject(mergedTypes));
606 const maxTypeLength = [...types].sort((t1, t2) => t2.length - t1.length)[0].length;
feat(xxx)!: support xxx
and feat!: support xxx
is now very popular today. Please consider supporting this feature.
It's reasonable. We can easily recognize the breaking change commit.
Dear git-commit-msg-linter maintainers,
Thank you for your contribution to the open-source community.
This issue was automatically created to inform you a new version (3.3.0) of git-commit-msg-linter was published without a matching tag in this repo.
Our service monitors the open-source ecosystem and informs popular packages' owners in case of potentially harmful activity.
If you find this behavior legitimate, kindly close and ignore this issue. Read more
Wishlist: support of ES6 modules.
Presently, for projects that have "type: module" in package.json, a commit will fail with the following error:
internal/process/esm_loader.js:74
internalBinding('errors').triggerUncaughtException(
^
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension "" for /home/kevin/code/ftek/receiver/.git/hooks/commit-msg
at Loader.defaultGetFormat [as _getFormat] (internal/modules/esm/get_format.js:71:15)
at Loader.getFormat (internal/modules/esm/loader.js:104:42)
at Loader.getModuleJob (internal/modules/esm/loader.js:242:31)
at async Loader.import (internal/modules/esm/loader.js:176:17)
at async Object.loadESM (internal/process/esm_loader.js:68:5) {
code: 'ERR_UNKNOWN_FILE_EXTENSION'
}
The commit-msg
hook assumes that bash is installed at /bin/bash
, but that is not the case for all systems (including NixOS, which is what I'm running).
It looks like this was broken in #39, which added the shebang:
#!/bin/bash
I think the correct shebang should be:
#!/usr/bin/env bash
which is more portable and should work on systems where bash is somewhere other than /bin/bash
(although I couldn't say if this solution works for all supported systems).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.