From 7c182e363e50bb05335f2f8fb9cb08154fbd73dc Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Wed, 18 Jul 2018 12:57:06 +0100 Subject: [PATCH] style: fix style issues --- src/bin/commands/augment.js | 6 +++--- src/bin/commands/pretty-print.js | 24 ++++++++++++------------ src/factories/createLogger.js | 4 ++-- src/log.js | 9 +++++---- src/types.js | 2 ++ test/roarr/roarr.js | 5 ++--- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/bin/commands/augment.js b/src/bin/commands/augment.js index 98be11e..35b10a6 100644 --- a/src/bin/commands/augment.js +++ b/src/bin/commands/augment.js @@ -9,9 +9,6 @@ import { isRoarrLine } from './utilities'; -export const command = 'augment'; -export const desc = 'Augments Roarr logs with additional information.'; - type LogFormatterConfigurationType = {| +appendHostname: boolean, +appendInstanceId: boolean, @@ -46,6 +43,9 @@ const createLogFormatter = (configuration: LogFormatterConfigurationType) => { return stream; }; +export const command = 'augment'; +export const desc = 'Augments Roarr logs with additional information.'; + // eslint-disable-next-line flowtype/no-weak-types export const builder = (yargs: Object) => { return yargs diff --git a/src/bin/commands/pretty-print.js b/src/bin/commands/pretty-print.js index 9743a87..d5a8a73 100644 --- a/src/bin/commands/pretty-print.js +++ b/src/bin/commands/pretty-print.js @@ -7,8 +7,15 @@ import { isRoarrLine } from './utilities'; -export const command = 'pretty-print'; -export const desc = 'Format logs for user-inspection.'; +type ArgvType = {| + +excludeOrphans: boolean, + +includeContext: boolean +|}; + +type LogFormatterConfigurationType = {| + +includeContext: boolean, + +excludeOrphans: boolean +|}; /* eslint-disable quote-props */ const logLevels = { @@ -34,11 +41,6 @@ const getLogLevelName = (logLevel: number): string => { return logLevels[logLevel] || 'INFO'; }; -type LogFormatterConfigurationType = {| - +includeContext: boolean, - +excludeOrphans: boolean -|}; - const createLogFormatter = (configuration: LogFormatterConfigurationType) => { const stream = split((line) => { if (!isRoarrLine(line)) { @@ -100,6 +102,9 @@ const createLogFormatter = (configuration: LogFormatterConfigurationType) => { return stream; }; +export const command = 'pretty-print'; +export const desc = 'Format logs for user-inspection.'; + // eslint-disable-next-line flowtype/no-weak-types export const builder = (yargs: Object) => { return yargs @@ -116,11 +121,6 @@ export const builder = (yargs: Object) => { }); }; -type ArgvType = {| - +excludeOrphans: boolean, - +includeContext: boolean -|}; - export const handler = (argv: ArgvType) => { process.stdin .pipe(createLogFormatter(argv)) diff --git a/src/factories/createLogger.js b/src/factories/createLogger.js index 54a883e..6deff2b 100644 --- a/src/factories/createLogger.js +++ b/src/factories/createLogger.js @@ -63,9 +63,9 @@ const createLogger = (onMessage: OnMessageEventHandlerType, parentContext: Messa if (typeof context === 'function') { return createLogger((message) => { if (typeof context !== 'function') { - throw new Error('Unexpected state.'); + throw new TypeError('Unexpected state.'); } - onMessage(context(message)) + onMessage(context(message)); }, parentContext); } diff --git a/src/log.js b/src/log.js index c0bc275..60c36b4 100644 --- a/src/log.js +++ b/src/log.js @@ -7,10 +7,6 @@ import { import { ROARR_LOG } from './config'; -export type { - MessageType, - TranslatorType -} from './types'; global.ROARR = createRoarrInititialGlobalState(global.ROARR || {}); @@ -26,6 +22,11 @@ if (!global.ROARR.registeredFlush) { }); } +export type { + MessageType, + TranslatorType +} from './types'; + export default createLogger((message) => { if (!ROARR_LOG) { return; diff --git a/src/types.js b/src/types.js index b9b33a8..877d536 100644 --- a/src/types.js +++ b/src/types.js @@ -1,5 +1,7 @@ // @flow +/* eslint-disable import/exports-last, flowtype/require-types-at-top */ + export type SerializableObjectType = { +[key: string]: string | number | null | SerializableObjectType }; diff --git a/test/roarr/roarr.js b/test/roarr/roarr.js index e15b79a..904ab55 100644 --- a/test/roarr/roarr.js +++ b/test/roarr/roarr.js @@ -203,9 +203,8 @@ test('translates child message', (t) => { return { ...message, message: message.message + 'bar' - } - }) - ('foo'); + }; + })('foo'); t.deepEqual(log.messages, [ {