Skip to content

Commit

Permalink
chore: lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 18, 2023
1 parent 7793e84 commit d424218
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/reporters/browser.ts
Expand Up @@ -34,7 +34,7 @@ export class BrowserReporter {
const consoleLogFn = this._getLogFn(logObj.level);

// Type
const type = logObj.type !== "log" ? logObj.type : "";
const type = logObj.type === "log" ? "" : logObj.type;

// Tag
const tag = logObj.tag || "";
Expand Down
62 changes: 40 additions & 22 deletions src/utils/prompt.ts
Expand Up @@ -57,14 +57,18 @@ const S_ERROR = s("■", "x");
const symbol = (state: State) => {
switch (state) {
case "initial":
case "active":
case "active": {
return color.cyan(S_STEP_ACTIVE);
case "cancel":
}
case "cancel": {
return color.red(S_STEP_CANCEL);
case "error":
}
case "error": {
return color.yellow(S_STEP_ERROR);
case "submit":
}
case "submit": {
return color.green(S_STEP_SUBMIT);
}
}
};

Expand All @@ -89,27 +93,31 @@ export const text = (opts: TextOptions) => {
? color.inverse(opts.placeholder[0]) +
color.dim(opts.placeholder.slice(1))
: color.inverse(color.hidden("_"));
const value = !this.value ? placeholder : this.valueWithCursor;
const value = this.value ? this.valueWithCursor : placeholder;

switch (this.state) {
case "error":
case "error": {
return `${title.trim()}\n${color.yellow(
S_BAR
)} ${value}\n${color.yellow(S_BAR_END)} ${color.yellow(
this.error
)}\n`;
case "submit":
}
case "submit": {
return `${title}${color.gray(S_BAR)} ${color.dim(
this.value || opts.placeholder
)}`;
case "cancel":
}
case "cancel": {
return `${title}${color.gray(S_BAR)} ${color.strikethrough(
color.dim(this.value ?? "")
)}${this.value?.trim() ? "\n" + color.gray(S_BAR) : ""}`;
default:
}
default: {
return `${title}${color.cyan(S_BAR)} ${value}\n${color.cyan(
S_BAR_END
)}\n`;
}
}
},
}).prompt() as Promise<string | symbol>;
Expand All @@ -132,22 +140,26 @@ export const password = (opts: PasswordOptions) => {
const masked = this.masked;

switch (this.state) {
case "error":
case "error": {
return `${title.trim()}\n${color.yellow(
S_BAR
)} ${masked}\n${color.yellow(S_BAR_END)} ${color.yellow(
this.error
)}\n`;
case "submit":
}
case "submit": {
return `${title}${color.gray(S_BAR)} ${color.dim(masked)}`;
case "cancel":
}
case "cancel": {
return `${title}${color.gray(S_BAR)} ${color.strikethrough(
color.dim(masked ?? "")
)}${masked ? "\n" + color.gray(S_BAR) : ""}`;
default:
}
default: {
return `${title}${color.cyan(S_BAR)} ${value}\n${color.cyan(
S_BAR_END
)}\n`;
}
}
},
}).prompt() as Promise<string | symbol>;
Expand All @@ -173,21 +185,23 @@ export const confirm = (opts: ConfirmOptions) => {
const value = this.value ? active : inactive;

switch (this.state) {
case "submit":
case "submit": {
return `${title}${color.gray(S_BAR)} ${color.dim(value)}`;
case "cancel":
}
case "cancel": {
return `${title}${color.gray(S_BAR)} ${color.strikethrough(
color.dim(value)
)}\n${color.gray(S_BAR)}`;
}
default: {
return `${title}${color.cyan(S_BAR)} ${
this.value
? `${color.green(S_RADIO_ACTIVE)} ${active}`
: `${color.dim(S_RADIO_INACTIVE)} ${color.dim(active)}`
} ${color.dim("/")} ${
!this.value
? `${color.green(S_RADIO_ACTIVE)} ${inactive}`
: `${color.dim(S_RADIO_INACTIVE)} ${color.dim(inactive)}`
this.value
? `${color.dim(S_RADIO_INACTIVE)} ${color.dim(inactive)}`
: `${color.green(S_RADIO_ACTIVE)} ${inactive}`
}\n${color.cyan(S_BAR_END)}\n`;
}
}
Expand Down Expand Up @@ -241,16 +255,18 @@ export const select = <Options extends Option<Value>[], Value>(
}\n`;

switch (this.state) {
case "submit":
case "submit": {
return `${title}${color.gray(S_BAR)} ${opt(
this.options[this.cursor],
"selected"
)}`;
case "cancel":
}
case "cancel": {
return `${title}${color.gray(S_BAR)} ${opt(
this.options[this.cursor],
"cancelled"
)}\n${color.gray(S_BAR)}`;
}
default: {
return `${title}${color.cyan(S_BAR)} ${this.options
.map((option, i) =>
Expand Down Expand Up @@ -302,17 +318,19 @@ export const selectKey = <
}\n`;

switch (this.state) {
case "submit":
case "submit": {
return `${title}${color.gray(S_BAR)} ${opt(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.options.find((opt) => opt.value === this.value)!,
"selected"
)}`;
case "cancel":
}
case "cancel": {
return `${title}${color.gray(S_BAR)} ${opt(
this.options[0],
"cancelled"
)}\n${color.gray(S_BAR)}`;
}
default: {
return `${title}${color.cyan(S_BAR)} ${this.options
.map((option, i) =>
Expand Down
12 changes: 8 additions & 4 deletions src/utils/string.ts
Expand Up @@ -39,13 +39,17 @@ export function align(
space = " "
) {
switch (alignment) {
case "left":
case "left": {
return leftAlign(str, len, space);
case "right":
}
case "right": {
return rightAlign(str, len, space);
case "center":
}
case "center": {
return centerAlign(str, len, space);
default:
}
default: {
return str;
}
}
}
3 changes: 2 additions & 1 deletion test/consola.test.ts
Expand Up @@ -53,7 +53,8 @@ describe("consola", () => {
await wait(300);
expect(logs.length).toBe(7);
// 6 + Last one indicating it repeated 4
expect(logs[logs.length - 1].args).toEqual(["SPAM", "(repeated 4 times)"]);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(logs.at(-1)!.args).toEqual(["SPAM", "(repeated 4 times)"]);
});
});

Expand Down

0 comments on commit d424218

Please sign in to comment.