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(cli): use special errorCode for missing rules/config #4142 #4143

Merged
merged 6 commits into from
Sep 11, 2024

Conversation

escapedcat
Copy link
Member

@escapedcat escapedcat commented Sep 11, 2024

Description

Fixes #4142

I wonder if this is a breaking change.

Used 9 after looking at this:
https://www.geeksforgeeks.org/node-js-exit-codes/
Is 9 correct?

How Has This Been Tested?

Currently it is not
Adjusted existing tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

codesandbox-ci bot commented Sep 11, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@escapedcat
Copy link
Member Author

@knocte wdyt?

@@ -384,6 +387,9 @@ async function main(args: MainArgs): Promise<void> {
throw new CliError(output, pkg.name, 2);
}
}
if (!report.valid && isRulesEmpty) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@escapedcat if isRulesEmpty=true at line 347, do we really need to perform the invokation at line 348 or can return early?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried that before. We need a "formatted" report (aka output) to display the current message.
We could just throw a new error but I kinda like the current formatted way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still, wouldn't it be better to check isRulesEmpty first? i.e. if (isRulesEmpty && (!report.valid)) {, micro-optimization there; or even just if (isRulesEmpty) {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, adjusted, thanks!

@knocte
Copy link
Contributor

knocte commented Sep 11, 2024

Cool, and let's refactor the exit codes to be an int-based enum?

@escapedcat
Copy link
Member Author

Cool, and let's refactor the exit codes to be an int-based enum?

Done 👍

@knocte
Copy link
Contributor

knocte commented Sep 11, 2024

LGTM

@escapedcat
Copy link
Member Author

I'll wait for @ferrarimarco feedback and merge after.

Is this breaking in any way? I'll go with a no here 🤞

@ferrarimarco
Copy link

Thanks for this PR.

This is perhaps a better reference from the official Node docs: https://nodejs.org/api/process.html#exit-codes. Its content seem to match your link.

From a end user point of view, this will work because we can check if the exit code is 9.

I don't know enough about commitlint internals for a deep review, but I'll try to leave some comments.

Thanks a lot for working on this!

Copy link

@ferrarimarco ferrarimarco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a small thing to check.

@commitlint/cli/src/cli-error.ts Show resolved Hide resolved
@escapedcat escapedcat merged commit d7070d8 into master Sep 11, 2024
13 checks passed
@escapedcat escapedcat deleted the feat/missingRulesErrorCode branch September 11, 2024 07:49
@escapedcat
Copy link
Member Author

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

Successfully merging this pull request may close these issues.

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