conventional-changelog / commitlint

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

feat: exit with a code >3 when configuration is missing or incomplete #4142

Closed ferrarimarco closed 2 months ago

ferrarimarco commented 2 months ago

Expected Behavior

Exit with a code that's greater than 0, and different from 1, 2, and 3 when the configuration from the CLI is incomplete (such as when missing --extends), or when there's no configuration file.

Current Behavior

Commitlint exits with an exit code equal to 1 when there are configuration errors or when there are linting errors. This makes it impossible to differentiate between linting issues and commitlint configuration issues.

Affected packages

Possible Solution

I don't know much about commitlint implementation to suggest a possible design. :(

I'm suggesting something different from:

Context

Steps to reproduce the behavior:

  1. mkdir /tmp/test-commitlint

  2. cd /tmp/test-commitlint

  3. git init

  4. touch test.txt

  5. git add test.txt

  6. git commit -m "Initial commit"

  7. commitlint --last

    Output (expected):

    ⧗   input: Initial commit
    ✖   Please add rules to your `commitlint.config.js`
        - Getting started guide: https://commitlint.js.org/guides/getting-started
        - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts [empty-rules]
    
    ✖   found 1 problems, 0 warnings
    ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
  8. echo $?

    1
  9. commitlint --version

    Output:

    @commitlint/cli@19.4.1

Thanks!

escapedcat commented 2 months ago

Digged a bit.

This is what happens if there's no config:

...
⧗   input: foo
✖   Please add rules to your `commitlint.config.js`
    - Getting started guide: https://commitlint.js.org/guides/getting-started
    - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts [empty-rules]

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

husky - commit-msg script failed (code 1)

In this case it's husky failing with code 1, right? You mean that?

Looks like we're just using the commitlint default errors to display the "missing config"-error.

I'm not sure how to adjust the husky error code based on commitlints outcome. I assume this would be necessary here?

Edit: Sorry, just saw your steps now and seeing this looks like it's coming from commitlint directly. Need to check if this can be adjusted somewhere.

escapedcat commented 2 months ago

@ferrarimarco have a look at the PR. Does this make sense to you?

ferrarimarco commented 2 months ago

Thanks! I'll have a look at the PR :)

ferrarimarco commented 2 months ago

@escapedcat maybe it could be useful to update the CLI docs page as well, so users are aware of this feature?

Thanks!

escapedcat commented 2 months ago

What kind of update would you expect to see there?
It looks like we just show the current cli options there and those didn't change, right?

ferrarimarco commented 2 months ago

Maybe an addition to the --config option, similar to description about the --strict option?

ferrarimarco commented 2 months ago

And thanks for releasing a new version so quickly!

escapedcat commented 2 months ago

Updated the docs as well

ferrarimarco commented 2 months ago

Thanks!