conventional-changelog / commitlint

📓 Lint commit messages
https://commitlint.js.org
MIT License
16.72k stars 901 forks source link

fix: `echo "feat: asdasd" | npx --yes @commitlint/cli` -> Please add rules to your `commitlint.config.js` #3662

Open bf opened 1 year ago

bf commented 1 year ago

Expected Behavior

use default config and dont throw error

Current Behavior

$ echo "feat: asdasd" | npx --yes @commitlint/cli 
⧗   input: feat: asdasd
✖   Please add rules to your `commitlint.config.js`
    - Getting started guide: https://commitlint.js.org/#/?id=getting-started
    - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js [empty-rules]

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

Affected packages

Possible Solution

load default config

Steps to Reproduce

1. `echo "feat: asdasd" | npx --yes @commitlint/cli`
2. `echo "feat: asdasd" | npx --yes commitlint`

Context

https://commitlint.js.org/#/guides-local-setup?id=test-simple-usage says "For a first simple usage test of commitlint you can do the following: npx commitlint --from HEAD~1 --to HEAD --verbose" but if you adapt it to read from stdin it does not work.

commitlint --version

@commitlint/cli@17.7.1

git --version

git version 2.42.0

node --version

v20.5.1

bf commented 1 year ago

It seems that echo "feat: asdasd" | npx --yes commitlint -x @commitlint/config-conventional --verbose works. The cli docs are a bit misleading at https://commitlint.js.org/#/reference-cli

The default npx --yes commitlink should just work in my opinion.

escapedcat commented 1 year ago

Doubt we gonna fix this. But happy for a PR to adjust the docs.

I assume it might work with at least a commitlint-config (i.e. commitlint.config.js) but not sure.

bf commented 1 year ago

Thanks for quick reply. Is there any way to run commitlint via npx without installing the @commitlint/config-conventional package via npm beforehand? It's so weird that the cli does not come with a default config!

escapedcat commented 1 year ago

Ah, sorry, see my updated comment above.

bf commented 1 year ago

It's a bit weird, because my use case is to configure git to have a pre-receive hook that checks for properly formatted commit messages with commitlint. I want to run npx --yes commitlint so it downloads commitlint and stores it in a temp folder, but does not create any node_modules/ or package.json files.

As npx --yes commitlint only works with npx --yes commitlint -x @commitlint/config-conventional there needs to be a node_modules folder in near the git pre-receive hook which is not ideal.

Is nobody using commitlint in the git pre-receive? When I use it in a github action, the commit is already pushed to the repo and the damage is done.