diff options
| author | Kitson Kelly <me@kitsonkelly.com> | 2019-03-05 11:53:35 +1100 |
|---|---|---|
| committer | Ryan Dahl <ry@tinyclouds.org> | 2019-03-04 19:53:35 -0500 |
| commit | 17663c12326dd1053f89a3bd741807f139973dae (patch) | |
| tree | 4588e84042b0155e11d7f5442ae38a6007922585 /log | |
| parent | 9f33cd28963a72d8fea0b1e99bb61ca9bec21a94 (diff) | |
Add eslint for linting (denoland/deno_std#235)
Original: https://github.com/denoland/deno_std/commit/c0390ade3de4d825423c9f0f5e1aa56ffd509942
Diffstat (limited to 'log')
| -rw-r--r-- | log/handlers.ts | 16 | ||||
| -rw-r--r-- | log/handlers_test.ts | 1 | ||||
| -rw-r--r-- | log/logger.ts | 30 | ||||
| -rw-r--r-- | log/logger_test.ts | 2 | ||||
| -rw-r--r-- | log/mod.ts | 39 | ||||
| -rw-r--r-- | log/test.ts | 4 |
6 files changed, 51 insertions, 41 deletions
diff --git a/log/handlers.ts b/log/handlers.ts index 96d8c056f..c1f664cc0 100644 --- a/log/handlers.ts +++ b/log/handlers.ts @@ -24,7 +24,7 @@ export class BaseHandler { this.formatter = options.formatter || DEFAULT_FORMATTER; } - handle(logRecord: LogRecord) { + handle(logRecord: LogRecord): void { if (this.level > logRecord.level) return; const msg = this.format(logRecord); @@ -48,9 +48,9 @@ export class BaseHandler { }); } - log(msg: string) {} - async setup() {} - async destroy() {} + log(_msg: string): void {} + async setup(): Promise<void> {} + async destroy(): Promise<void> {} } export class ConsoleHandler extends BaseHandler { @@ -77,7 +77,7 @@ export class ConsoleHandler extends BaseHandler { return msg; } - log(msg: string) { + log(msg: string): void { console.log(msg); } } @@ -86,7 +86,7 @@ export abstract class WriterHandler extends BaseHandler { protected _writer: Writer; private _encoder = new TextEncoder(); - log(msg: string) { + log(msg: string): void { this._writer.write(this._encoder.encode(msg + "\n")); } } @@ -104,13 +104,13 @@ export class FileHandler extends WriterHandler { this._filename = options.filename; } - async setup() { + async setup(): Promise<void> { // open file in append mode - write only this._file = await open(this._filename, "a"); this._writer = this._file; } - async destroy() { + async destroy(): Promise<void> { await this._file.close(); } } diff --git a/log/handlers_test.ts b/log/handlers_test.ts index 52eca16ea..7dc4e2089 100644 --- a/log/handlers_test.ts +++ b/log/handlers_test.ts @@ -1,6 +1,5 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { assertEqual, test } from "../testing/mod.ts"; -import { LogRecord, Logger } from "./logger.ts"; import { LogLevel, getLevelName, getLevelByName } from "./levels.ts"; import { BaseHandler } from "./handlers.ts"; diff --git a/log/logger.ts b/log/logger.ts index 678d5ed94..d92c34a58 100644 --- a/log/logger.ts +++ b/log/logger.ts @@ -4,6 +4,7 @@ import { BaseHandler } from "./handlers.ts"; export interface LogRecord { msg: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any args: any[]; datetime: Date; level: number; @@ -13,6 +14,7 @@ export interface LogRecord { export class Logger { level: number; levelName: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any handlers: any[]; constructor(levelName: string, handlers?: BaseHandler[]) { @@ -22,7 +24,8 @@ export class Logger { this.handlers = handlers || []; } - _log(level: number, msg: string, ...args: any[]) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + _log(level: number, msg: string, ...args: any[]): void { if (this.level > level) return; // TODO: it'd be a good idea to make it immutable, so @@ -41,23 +44,28 @@ export class Logger { }); } - debug(msg: string, ...args: any[]) { - return this._log(LogLevel.DEBUG, msg, ...args); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + debug(msg: string, ...args: any[]): void { + this._log(LogLevel.DEBUG, msg, ...args); } - info(msg: string, ...args: any[]) { - return this._log(LogLevel.INFO, msg, ...args); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + info(msg: string, ...args: any[]): void { + this._log(LogLevel.INFO, msg, ...args); } - warning(msg: string, ...args: any[]) { - return this._log(LogLevel.WARNING, msg, ...args); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + warning(msg: string, ...args: any[]): void { + this._log(LogLevel.WARNING, msg, ...args); } - error(msg: string, ...args: any[]) { - return this._log(LogLevel.ERROR, msg, ...args); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + error(msg: string, ...args: any[]): void { + this._log(LogLevel.ERROR, msg, ...args); } - critical(msg: string, ...args: any[]) { - return this._log(LogLevel.CRITICAL, msg, ...args); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + critical(msg: string, ...args: any[]): void { + this._log(LogLevel.CRITICAL, msg, ...args); } } diff --git a/log/logger_test.ts b/log/logger_test.ts index a2275a00b..8ff328c48 100644 --- a/log/logger_test.ts +++ b/log/logger_test.ts @@ -53,7 +53,7 @@ test(function customHandler() { test(function logFunctions() { let handler: TestHandler; - const doLog = (level: string) => { + const doLog = (level: string): void => { handler = new TestHandler(level); let logger = new Logger(level, [handler]); logger.debug("foo"); diff --git a/log/mod.ts b/log/mod.ts index 96dc81ff1..ef5ca5a89 100644 --- a/log/mod.ts +++ b/log/mod.ts @@ -36,8 +36,8 @@ const DEFAULT_CONFIG: LogConfig = { }; const state = { - handlers: new Map(), - loggers: new Map(), + handlers: new Map<string, BaseHandler>(), + loggers: new Map<string, Logger>(), config: DEFAULT_CONFIG }; @@ -48,18 +48,7 @@ export const handlers = { FileHandler }; -export const debug = (msg: string, ...args: any[]) => - getLogger("default").debug(msg, ...args); -export const info = (msg: string, ...args: any[]) => - getLogger("default").info(msg, ...args); -export const warning = (msg: string, ...args: any[]) => - getLogger("default").warning(msg, ...args); -export const error = (msg: string, ...args: any[]) => - getLogger("default").error(msg, ...args); -export const critical = (msg: string, ...args: any[]) => - getLogger("default").critical(msg, ...args); - -export function getLogger(name?: string) { +export function getLogger(name?: string): Logger { if (!name) { return state.loggers.get("default"); } @@ -73,11 +62,27 @@ export function getLogger(name?: string) { return state.loggers.get(name); } -export function getHandler(name: string) { +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const debug = (msg: string, ...args: any[]): void => + getLogger("default").debug(msg, ...args); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const info = (msg: string, ...args: any[]): void => + getLogger("default").info(msg, ...args); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const warning = (msg: string, ...args: any[]): void => + getLogger("default").warning(msg, ...args); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const error = (msg: string, ...args: any[]): void => + getLogger("default").error(msg, ...args); +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const critical = (msg: string, ...args: any[]): void => + getLogger("default").critical(msg, ...args); + +export function getHandler(name: string): BaseHandler { return state.handlers.get(name); } -export async function setup(config: LogConfig) { +export async function setup(config: LogConfig): Promise<void> { state.config = { handlers: { ...DEFAULT_CONFIG.handlers, ...config.handlers }, loggers: { ...DEFAULT_CONFIG.loggers, ...config.loggers } @@ -106,7 +111,7 @@ export async function setup(config: LogConfig) { for (const loggerName in loggers) { const loggerConfig = loggers[loggerName]; const handlerNames = loggerConfig.handlers || []; - const handlers = []; + const handlers: BaseHandler[] = []; handlerNames.forEach(handlerName => { if (state.handlers.has(handlerName)) { diff --git a/log/test.ts b/log/test.ts index 918368b97..3599247bd 100644 --- a/log/test.ts +++ b/log/test.ts @@ -1,8 +1,6 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import { assertEqual, test } from "../testing/mod.ts"; import * as log from "./mod.ts"; -import { BaseHandler } from "./handlers.ts"; -import { LogRecord } from "./logger.ts"; import { LogLevel } from "./levels.ts"; import "./handlers_test.ts"; @@ -18,7 +16,7 @@ import "./logger_test.ts"; class TestHandler extends log.handlers.BaseHandler { public messages: string[] = []; - log(msg: string) { + log(msg: string): void { this.messages.push(msg); } } |
