-
Notifications
You must be signed in to change notification settings - Fork 934
refactor(cz-commitlint,prompt): remove duplication in case conversion #2794
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
refactor(cz-commitlint,prompt): remove duplication in case conversion #2794
Conversation
@commitlint/ensure/src/case.ts
Outdated
@@ -43,7 +43,7 @@ function toCase(input: string, target: TargetCaseType): string { | |||
return input.toUpperCase(); | |||
case 'sentence-case': | |||
case 'sentencecase': | |||
return input.charAt(0).toUpperCase() + input.slice(1); | |||
return upperFirst(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is functionally equivalent to the current implementation as far as I can tell.
@@ -42,8 +42,7 @@ export default function getCaseFn(rule?: Rule): CaseFn { | |||
return (input: string) => input.toUpperCase(); | |||
case 'sentence-case': | |||
case 'sentencecase': | |||
return (input: string) => | |||
`${input.charAt(0).toUpperCase()}${input.substring(1).toLowerCase()}`; | |||
return (input: string) => upperFirst(input); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation here deviates from the one in @commitlint/ensure/src/case.ts
Hey @hasghari , thanks for this PR! Edit: Ah. you're on it right now ;) Thanks! |
Updated with description and context. |
f81f1c5
to
cfce62c
Compare
Hey @hasghari , thanks for pointing out this issue and explaining it :)
No need to worry about the monorepo thing. You could just export the function and use it in the |
7337683
to
a416168
Compare
@escapedcat I took a stab at removing the duplication. I also left my earlier commit in place but I'd be happy to squash it. |
@escapedcat @hasghari It's good to extract |
a416168
to
5350795
Compare
Thanks for pointing out the |
@hasghari would you mind rebasing this? Thanks! |
The @commitlint/cz-commitlint was previously duplicating the case conversion logic also found in the @commitlint/ensure package.
The @commitlint/prompt package was previously duplicating the case conversion logic also found in the @commitlint/ensure package.
5350795
to
5199ccf
Compare
Done. |
Thanks @hasghari ! Moving this in. |
It's released with 14.0.0/14.1.0 |
Description
The implementation of
sentence-case
for cz-commitlint differs from the one in@commitlint/ensure/src/case.ts
. Ideally the@commitlint/cz-commitlint
package should depend on the@commitlint/ensure
package and import thetoCase
function to remove the duplicate implementation but admittedly I'm not sure how to accomplish that in a monorepo like this. Does that require submitting a separate pull request for@commitlint/ensure
to export thetoCase
function?Motivation and Context
Let's say my desired commit message is "ci: Add GitHub Action for commitlint". If I author that manually, it passes commitlint. However with commitizen, it converts everything except the first character to lowercase, ending up with "ci: Add github action for commitlint"
Types of changes
Checklist: