From 61a3911be7e01273e13bf35a3a16285f413f0b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E6=9D=89?= Date: Mon, 21 Jan 2019 23:35:07 +0800 Subject: [PATCH] fix format (#140) --- datetime/test.ts | 4 ++-- format.ts | 6 +----- log/handlers.ts | 7 ++----- log/test.ts | 31 ++++++++++++++++--------------- 4 files changed, 21 insertions(+), 27 deletions(-) diff --git a/datetime/test.ts b/datetime/test.ts index 5bc7eda21b..ce8193dfb3 100644 --- a/datetime/test.ts +++ b/datetime/test.ts @@ -31,7 +31,7 @@ test(function parseDateTime() { test(function invalidParseDateTimeFormatThrows() { try { (datetime as any).parseDateTime("2019-01-01 00:00", "x-y-z"); - assert(false, 'no exception was thrown'); + assert(false, "no exception was thrown"); } catch (e) { assertEqual(e.message, "Invalid datetime format!"); } @@ -55,7 +55,7 @@ test(function parseDate() { test(function invalidParseDateFormatThrows() { try { (datetime as any).parseDate("2019-01-01", "x-y-z"); - assert(false, 'no exception was thrown'); + assert(false, "no exception was thrown"); } catch (e) { assertEqual(e.message, "Invalid date format!"); } diff --git a/format.ts b/format.ts index 2e7b9a6060..cee84a2993 100755 --- a/format.ts +++ b/format.ts @@ -27,11 +27,7 @@ async function main() { await checkVersion(); const prettier = run({ - args: [ - "bash", - "-c", - "prettier --write *.ts */*.ts */**/*.ts *.md */*.md */**/*.md" - ] + args: ["bash", "-c", "prettier --write '**/*.ts' '**/*.md'"] }); const s = await prettier.status(); exit(s.code); diff --git a/log/handlers.ts b/log/handlers.ts index bb684bdef2..c39102c8e8 100644 --- a/log/handlers.ts +++ b/log/handlers.ts @@ -32,7 +32,7 @@ export class BaseHandler { if (this.formatter instanceof Function) { return this.formatter(logRecord); } - + return this.formatter.replace(/{(\S+)}/g, (match, p1) => { const value = logRecord[p1]; @@ -73,10 +73,7 @@ export class FileHandler extends WriterHandler { private _file: File; private _filename: string; - constructor( - levelName: string, - options: FileHandlerOptions, - ) { + constructor(levelName: string, options: FileHandlerOptions) { super(levelName, options); this._filename = options.filename; } diff --git a/log/test.ts b/log/test.ts index 4b623207fe..2f34313480 100644 --- a/log/test.ts +++ b/log/test.ts @@ -32,15 +32,15 @@ test(function testDefaultlogMethods() { test(async function testDefaultFormatter() { await log.setup({ handlers: { - test: new TestHandler("DEBUG"), + test: new TestHandler("DEBUG") }, loggers: { test: { level: "DEBUG", - handlers: ["test"], - }, - }, + handlers: ["test"] + } + } }); const logger = log.getLogger("test"); @@ -53,16 +53,16 @@ test(async function testFormatterAsString() { await log.setup({ handlers: { test: new TestHandler("DEBUG", { - formatter: "test {levelName} {msg}", - }), + formatter: "test {levelName} {msg}" + }) }, loggers: { test: { level: "DEBUG", - handlers: ["test"], - }, - }, + handlers: ["test"] + } + } }); const logger = log.getLogger("test"); @@ -75,20 +75,21 @@ test(async function testFormatterAsFunction() { await log.setup({ handlers: { test: new TestHandler("DEBUG", { - formatter: logRecord => `fn formmatter ${logRecord.levelName} ${logRecord.msg}`, - }), + formatter: logRecord => + `fn formmatter ${logRecord.levelName} ${logRecord.msg}` + }) }, loggers: { test: { level: "DEBUG", - handlers: ["test"], - }, - }, + handlers: ["test"] + } + } }); const logger = log.getLogger("test"); const handler = log.getHandler("test"); logger.error("Hello, world!"); assertEqual(handler.testOutput, "fn formmatter ERROR Hello, world!\n"); -}); \ No newline at end of file +});