Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 4 tasks
ferrarimarco opened this issue Sep 10, 2024 · 9 comments · Fixed by #4143
Closed
1 of 4 tasks

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

ferrarimarco opened this issue Sep 10, 2024 · 9 comments · Fixed by #4143
Labels

Comments

@ferrarimarco
Copy link

ferrarimarco commented Sep 10, 2024

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

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

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

I'm suggesting something different from:

  • 1 (commit linting errors)
  • 2 and 3 (commit linting errors and warnings in strict mode)

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
Copy link
Member

escapedcat commented Sep 11, 2024

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
Copy link
Member

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

@ferrarimarco
Copy link
Author

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

escapedcat added a commit that referenced this issue Sep 11, 2024
* feat(cli): use special errorCode for missing rules/config #4142

* test(cli): update related tests #4142

* feat(cli): use errorCode 9 #4142

* refactor(cli): shorten statement #4142

* refactor(cli): use ExitCode Enum #4142

* refactor(cli): rename ExitCode-enum to match commitlints usage #4142
@ferrarimarco
Copy link
Author

ferrarimarco commented Sep 11, 2024

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

Thanks!

@escapedcat
Copy link
Member

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
Copy link
Author

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

@ferrarimarco
Copy link
Author

And thanks for releasing a new version so quickly!

@escapedcat
Copy link
Member

Updated the docs as well

@ferrarimarco
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants