Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 8, 2024
1 parent 238d677 commit 985a786
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe("your-consola-mock-test", () => {

```js
{
virtualConsole: new jsdom.VirtualConsole().sendTo(consola);
new jsdom.VirtualConsole().sendTo(consola);
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/wrap-all.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { consola } from "./utils";

function foo() {
console.info("console foo"); // eslint-disable-line no-console
console.info("console foo");
process.stderr.write("called from stderr\n");
}

Expand Down
6 changes: 3 additions & 3 deletions examples/wrap-console.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { consola } from "./utils";

function foo() {
console.info("foo"); // eslint-disable-line no-console
console.warn("foo warn"); // eslint-disable-line no-console
console.info("foo");
console.warn("foo warn");
}

function _trace() {
console.trace("foobar"); // eslint-disable-line no-console
console.trace("foobar");
}
function trace() {
_trace();
Expand Down
2 changes: 1 addition & 1 deletion examples/wrap-std.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { consola } from "./utils";

function foo() {
console.info("console foo"); // eslint-disable-line no-console
console.info("console foo");
process.stdout.write("called from stdout foo\n");
process.stderr.write("called from stderr foo\n");
}
Expand Down
13 changes: 5 additions & 8 deletions src/consola.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,23 +159,21 @@ export class Consola {
for (const type in this.options.types) {
// Backup original value
if (!(console as any)["__" + type]) {
// eslint-disable-line no-console
(console as any)["__" + type] = (console as any)[type]; // eslint-disable-line no-console
(console as any)["__" + type] = (console as any)[type];
}
// Override
(console as any)[type] = (this as unknown as ConsolaInstance)[
type as LogType
].raw; // eslint-disable-line no-console
].raw;
}
}

restoreConsole() {
for (const type in this.options.types) {
// Restore if backup is available
if ((console as any)["__" + type]) {
// eslint-disable-line no-console
(console as any)[type] = (console as any)["__" + type]; // eslint-disable-line no-console
delete (console as any)["__" + type]; // eslint-disable-line no-console
(console as any)[type] = (console as any)["__" + type];
delete (console as any)["__" + type];
}
}
}
Expand Down Expand Up @@ -283,15 +281,14 @@ export class Consola {

// Aliases
if (logObj.message) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
logObj.args!.unshift(logObj.message);
delete logObj.message;
}
if (logObj.additional) {
if (!Array.isArray(logObj.additional)) {
logObj.additional = logObj.additional.split("\n");
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

logObj.args!.push("\n" + logObj.additional.join("\n"));
delete logObj.additional;
}
Expand Down
5 changes: 2 additions & 3 deletions src/utils/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ export const selectKey = <
switch (this.state) {
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",
)}`;
Expand Down Expand Up @@ -787,8 +786,8 @@ export const spinner = () => {
// @see LICENSE
function ansiRegex() {
const pattern = [
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`,
].join("|");

return new RegExp(pattern, "g");
Expand Down
4 changes: 2 additions & 2 deletions src/utils/string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ansiRegex = [
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,
String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`,
].join("|");

export function stripAnsi(text: string) {
Expand Down
2 changes: 1 addition & 1 deletion test/consola.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("consola", () => {
await wait(300);
expect(logs.length).toBe(7);
// 6 + Last one indicating it repeated 4
// 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 985a786

Please sign in to comment.