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

refactor(prompt): migrate prompt to typescript #2371

Merged
merged 8 commits into from Jan 4, 2021

Conversation

armano2
Copy link
Contributor

@armano2 armano2 commented Dec 15, 2020

Description

Part of #659, last package that is compiled with babel, main issue is with types of vorpal, this package has not been updated for few years and definition for it in DefinedTypes is really bad

Changes in this PR has been limited to only necessary type addition as refactoring of this code without proper tests is really dangerous

Motivation and Context

Ported prompt to typescript as part of #659

fixes #608

How Has This Been Tested?

Manual tests and unit tests from project

tests in this package are very limited

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.

@armano2 armano2 changed the title Refactor/prompt refactor(prompt): port prompt to typescript Dec 15, 2020
@@ -46,7 +46,7 @@ export default {
},
body: {
description: '<body> holds additional information about the change',
multline: true,
multiline: true,
Copy link
Contributor Author

@armano2 armano2 Dec 15, 2020

Choose a reason for hiding this comment

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

not sure if i should fix this, as previous field was never used

Copy link
Member

Choose a reason for hiding this comment

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

I think this is good to leave. The body can actually be multiline, but we don't have that many users running into this. If your body is just one line of text, you will never use it anyways 😉

Comment on lines 64 to 67
return (input) => input.toLowerCase() === input;
return (input: string) => input.toLowerCase();
Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

@armano2 armano2 Dec 19, 2020

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:

	const [config] = rule;
	if (!Array.isArray(config)) {
		return noop;
	}

and this condition never passes as we should use

	const [, config] = rule;

Comment on lines 66 to 69
throw new TypeError(`Unknown target case "${rule[2]}"`);
throw new TypeError(`Unknown target case "${target}"`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rule[2] is never defined, it has to be config[2] or target to print correct value

Copy link
Member

Choose a reason for hiding this comment

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

Good catch again, I think you are right with the target here. Looks like target is also config[2] 😄

Comment on lines +26 to +55
export interface PrompterCommand {
description(value: string): this;
action(
action: (args: {
[key: string]: any;
options: {
[key: string]: any;
};
}) => Promise<void> | void
): this;
}

export interface Prompter {
delimiter(value: string): this;
show(): this;
exec(command: string): Promise<any>;
log(text?: string): void;
catch(command: string, description?: string): PrompterCommand;
command(command: string, description?: string): PrompterCommand;
removeAllListeners(input?: string): void;
addListener(input: string, cb: (event: any) => void): void;
ui: {
log(text?: string): void;
input(text?: string): string;
redraw: {
(text: string, ...texts: string[]): void;
done(): void;
};
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will be nice if we could use vorpal types instead but, @types/vorpal is not correct

Copy link
Member

Choose a reason for hiding this comment

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

That's unfortunate, thanks for adding the types anyways!

Copy link
Member

@byCedric byCedric left a comment

Choose a reason for hiding this comment

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

Thanks for helping out again @armano2 ❤️ Looks good!

@@ -46,7 +46,7 @@ export default {
},
body: {
description: '<body> holds additional information about the change',
multline: true,
multiline: true,
Copy link
Member

Choose a reason for hiding this comment

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

I think this is good to leave. The body can actually be multiline, but we don't have that many users running into this. If your body is just one line of text, you will never use it anyways 😉

Comment on lines +26 to +55
export interface PrompterCommand {
description(value: string): this;
action(
action: (args: {
[key: string]: any;
options: {
[key: string]: any;
};
}) => Promise<void> | void
): this;
}

export interface Prompter {
delimiter(value: string): this;
show(): this;
exec(command: string): Promise<any>;
log(text?: string): void;
catch(command: string, description?: string): PrompterCommand;
command(command: string, description?: string): PrompterCommand;
removeAllListeners(input?: string): void;
addListener(input: string, cb: (event: any) => void): void;
ui: {
log(text?: string): void;
input(text?: string): string;
redraw: {
(text: string, ...texts: string[]): void;
done(): void;
};
};
}
Copy link
Member

Choose a reason for hiding this comment

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

That's unfortunate, thanks for adding the types anyways!

Comment on lines 64 to 67
return (input) => input.toLowerCase() === input;
return (input: string) => input.toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

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

Good catch!

Comment on lines 66 to 69
throw new TypeError(`Unknown target case "${rule[2]}"`);
throw new TypeError(`Unknown target case "${target}"`);
Copy link
Member

Choose a reason for hiding this comment

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

Good catch again, I think you are right with the target here. Looks like target is also config[2] 😄

Comment on lines 90 to 104
const inputMaxLength = hasMaxLength ? maxLenghtRule[1][1] : Infinity;
const inputMaxLength =
maxLengthRule &&
maxLengthRule[1] &&
maxLengthRule[1][0] > 0 &&
typeof maxLengthRule[1][1] === 'number'
? maxLengthRule[1][1]
: Infinity;
Copy link
Contributor Author

@armano2 armano2 Dec 19, 2020

Choose a reason for hiding this comment

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

there is one more issue here, this code should be same as in input, right now is going to always return Infinity

[name, [severity, applicable, length]]

instead of reading maxLengthRule[1][1] e should read maxLengthRule[1][2] and check if rule is applicable

or write helper like this one and use it in input and here:

export function getMaxLength (rule?: RuleEntry): number {
	if (rule && ruleIsActive(rule) && ruleIsApplicable(rule) && typeof rule[1][2] === 'number') {
		return rule[1][2]
	}
	return Infinity
}

@armano2
Copy link
Contributor Author

armano2 commented Dec 22, 2020

I created some tests for this package and fixed some of known issues #608

@armano2 armano2 changed the title refactor(prompt): port prompt to typescript refactor(prompt): migrate prompt to typescript Dec 24, 2020
@escapedcat
Copy link
Member

@byCedric approved already @armano2 should we merge this?

@escapedcat escapedcat merged commit 8c41651 into conventional-changelog:master Jan 4, 2021
@armano2 armano2 deleted the refactor/prompt branch January 6, 2021 05:16
@armano2 armano2 mentioned this pull request Jan 10, 2021
18 tasks
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.

prompt-cli does not work with body-max-length or footer-max-length
3 participants