diff --git a/src/reporters/browser.ts b/src/reporters/browser.ts index 362aad8..145f385 100644 --- a/src/reporters/browser.ts +++ b/src/reporters/browser.ts @@ -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 || ""; diff --git a/src/utils/prompt.ts b/src/utils/prompt.ts index 9754d1b..7bc528c 100644 --- a/src/utils/prompt.ts +++ b/src/utils/prompt.ts @@ -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); + } } }; @@ -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; @@ -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; @@ -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`; } } @@ -241,16 +255,18 @@ export const select = [], 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) => @@ -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) => diff --git a/src/utils/string.ts b/src/utils/string.ts index 19224f9..d1b944c 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -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; + } } } diff --git a/test/consola.test.ts b/test/consola.test.ts index e1fbeaa..c43c9d5 100644 --- a/test/consola.test.ts +++ b/test/consola.test.ts @@ -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)"]); }); });