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(prompt): migrate prompt to typescript #2371
Changes from 5 commits
51a8cec
16b856c
8f3029b
fbe70c7
49684d5
a7883ef
e75ce8d
de281e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import vorpal from 'vorpal'; | ||
import input from './input'; | ||
|
||
type Commit = (input: string) => void; | ||
|
||
/** | ||
* Entry point for commitizen | ||
* @param _ inquirer instance passed by commitizen, unused | ||
* @param commit callback to execute with complete commit message | ||
* @return generated commit message | ||
*/ | ||
export const prompter = async (_: unknown, commit: Commit): Promise<void> => { | ||
const message = await input(vorpal); | ||
commit(message); | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ruleIsApplicable from './rule-is-applicable'; | ||
import ruleIsActive from './rule-is-active'; | ||
import {RuleEntry} from './types'; | ||
import {RuleConfigSeverity} from '@commitlint/types'; | ||
|
||
export default function enumRuleIsActive( | ||
rule: RuleEntry | ||
): rule is [ | ||
string, | ||
Readonly< | ||
[RuleConfigSeverity.Warning | RuleConfigSeverity.Error, 'always', string[]] | ||
> | ||
] { | ||
return ( | ||
ruleIsActive(rule) && | ||
ruleIsApplicable(rule) && | ||
Array.isArray(rule[1][2]) && | ||
rule[1][2].length > 0 | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,17 @@ import kebabCase from 'lodash/kebabCase'; | |
import snakeCase from 'lodash/snakeCase'; | ||
import upperFirst from 'lodash/upperFirst'; | ||
import startCase from 'lodash/startCase'; | ||
import {RuleEntry} from './types'; | ||
|
||
/** | ||
* Get forced case for rule | ||
* @param {object} rule to parse | ||
* @return {fn} transform function applying the enforced case | ||
* @param rule to parse | ||
* @return transform function applying the enforced case | ||
*/ | ||
export default function getForcedCaseFn(rule) { | ||
const noop = (input) => input; | ||
export default function getForcedCaseFn( | ||
rule?: RuleEntry | ||
): (input: string) => string { | ||
const noop = (input: string) => input; | ||
|
||
if (!rule) { | ||
return noop; | ||
|
@@ -25,13 +28,13 @@ export default function getForcedCaseFn(rule) { | |
const [level] = config; | ||
|
||
if (level === 0) { | ||
return; | ||
return noop; | ||
} | ||
|
||
const [, when] = config; | ||
|
||
if (when === 'never') { | ||
return; | ||
return noop; | ||
} | ||
|
||
const [, , target] = config; | ||
|
@@ -42,27 +45,27 @@ export default function getForcedCaseFn(rule) { | |
|
||
switch (target) { | ||
case 'camel-case': | ||
return (input) => camelCase(input); | ||
return (input: string) => camelCase(input); | ||
case 'kebab-case': | ||
return (input) => kebabCase(input); | ||
return (input: string) => kebabCase(input); | ||
case 'snake-case': | ||
return (input) => snakeCase(input); | ||
return (input: string) => snakeCase(input); | ||
case 'pascal-case': | ||
return (input) => upperFirst(camelCase(input)); | ||
return (input: string) => upperFirst(camelCase(input)); | ||
case 'start-case': | ||
return (input) => startCase(input); | ||
return (input: string) => startCase(input); | ||
case 'upper-case': | ||
case 'uppercase': | ||
return (input) => input.toUpperCase(); | ||
return (input: string) => input.toUpperCase(); | ||
case 'sentence-case': | ||
case 'sentencecase': | ||
return (input) => | ||
return (input: string) => | ||
`${input.charAt(0).toUpperCase()}${input.substring(1).toLowerCase()}`; | ||
case 'lower-case': | ||
case 'lowercase': | ||
case 'lowerCase': // Backwards compat config-angular v4 | ||
return (input) => input.toLowerCase() === input; | ||
return (input: string) => input.toLowerCase(); | ||
default: | ||
throw new TypeError(`Unknown target case "${rule[2]}"`); | ||
throw new TypeError(`Unknown target case "${target}"`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch again, I think you are right with the |
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import getRuleName from './get-rule-name'; | ||
import {RuleEntry} from './types'; | ||
|
||
/** | ||
* Get a predicate matching rule definitions with a given name | ||
*/ | ||
export default function getHasName(name: string) { | ||
return <T extends RuleEntry>( | ||
rule: RuleEntry | ||
): rule is Exclude<T, [string, undefined]> => getRuleName(rule[0]) === name; | ||
} |
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.
in case of lowecase this code was producing invalid result
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.
Good catch!
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.
i found out why this code did not crash for anyone, few lines above we have:
and this condition never passes as we should use