Skip to content

Commit 307e6da

Browse files
committed
Fix linting
1 parent e49ab20 commit 307e6da

File tree

8 files changed

+39
-33
lines changed

8 files changed

+39
-33
lines changed

src/exit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export const exitProcess = function ({ name, opts: { exitOn } }) {
3232
}, EXIT_TIMEOUT)
3333
}
3434

35-
export const EXIT_TIMEOUT = 3000
36-
export const EXIT_STATUS = 1
35+
const EXIT_TIMEOUT = 3000
36+
const EXIT_STATUS = 1
3737

3838
export const validateExitOn = function ({ exitOn }) {
3939
if (exitOn === undefined) {

src/level.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { emitWarning } from 'process'
22

33
import filterObj from 'filter-obj'
44
import { multipleValidOptions } from 'jest-validate'
5+
import mapObj from 'map-obj'
56

6-
import { result, mapValues } from './utils.js'
7+
import { result } from './utils.js'
78

89
// Retrieve error's log level
910
export const getLevel = function ({ opts, name, error }) {
@@ -36,7 +37,10 @@ export const applyDefaultLevels = function ({
3637
return { ...DEFAULT_LEVEL, ...levelA }
3738
}
3839

39-
const defaultLevels = mapValues(DEFAULT_LEVEL, () => defaultLevel)
40+
const defaultLevels = mapObj(DEFAULT_LEVEL, (eventName) => [
41+
eventName,
42+
defaultLevel,
43+
])
4044
return { ...defaultLevels, ...levelA }
4145
}
4246

@@ -46,12 +50,12 @@ const isDefined = function (key, value) {
4650

4751
// Use during options validation
4852
export const getExampleLevels = function () {
49-
return mapValues(DEFAULT_LEVEL, getExampleLevel)
53+
return mapObj(DEFAULT_LEVEL, getExampleLevel)
5054
}
5155

52-
const getExampleLevel = function (level) {
56+
const getExampleLevel = function (eventName, level) {
5357
// eslint-disable-next-line no-empty-function
54-
return multipleValidOptions(level, () => {})
58+
return [eventName, multipleValidOptions(level, () => {})]
5559
}
5660

5761
export const validateLevels = function ({ level }) {
@@ -77,7 +81,7 @@ const isValidLevel = function ({ level }) {
7781
const LEVELS_ARR = ['debug', 'info', 'warn', 'error', 'silent', 'default']
7882
const LEVELS = new Set(LEVELS_ARR)
7983

80-
export const DEFAULT_LEVEL = {
84+
const DEFAULT_LEVEL = {
8185
default: 'error',
8286
uncaughtException: 'error',
8387
warning: 'warn',

src/limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ const ERROR_MESSAGE = (name) =>
4747
const ERROR_NAME = 'LogProcessErrors'
4848
const ERROR_CODE = 'TooManyErrors'
4949

50-
export const MAX_EVENTS = 100
50+
const MAX_EVENTS = 100

src/utils.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import mapObj from 'map-obj'
2-
3-
// Like Lodash mapValues()
4-
export const mapValues = function (object, mapper) {
5-
return mapObj(object, (key, value) => [key, mapper(value, key)])
6-
}
7-
81
// Like Lodash result(), but faster
92
export const result = function (val, ...args) {
103
if (typeof val !== 'function') {

test/exit.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import test from 'ava'
66
import sinon from 'sinon'
77
import { each } from 'test-each'
88

9-
// Required directly because this is exposed through documentation, but not
10-
// through code
11-
import { EXIT_TIMEOUT, EXIT_STATUS } from '../src/exit.js'
12-
139
import { EVENTS } from './helpers/events/main.js'
1410
import { startLogging } from './helpers/init.js'
1511
import { removeProcessListeners } from './helpers/remove.js'
1612

1713
const pNextTick = promisify(process.nextTick)
1814

15+
const EXIT_TIMEOUT = 3000
16+
const EXIT_STATUS = 1
17+
1918
removeProcessListeners()
2019

2120
// Stub `process.exit()`

test/helpers/events/main.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// Required directly because this is exposed through documentation, but not
2-
// through code
3-
import { DEFAULT_LEVEL } from '../../../src/level.js'
4-
import { mapValues } from '../../../src/utils.js'
1+
import mapObj from 'map-obj'
52

63
import { multipleResolves } from './multiple_resolves.js'
74
import { rejectionHandled } from './rejection_handled.js'
@@ -10,7 +7,7 @@ import { unhandledRejection } from './unhandled_rejection.js'
107
import { warning } from './warning.js'
118

129
const getEventsMap = function () {
13-
return mapValues(EVENTS_SIMPLE_MAP, getEvent)
10+
return mapObj(EVENTS_SIMPLE_MAP, getEvent)
1411
}
1512

1613
const EVENTS_SIMPLE_MAP = {
@@ -21,10 +18,13 @@ const EVENTS_SIMPLE_MAP = {
2118
warning,
2219
}
2320

24-
const getEvent = function (emit, eventName) {
21+
const getEvent = function (eventName, emit) {
2522
const emitMany = emitEvents.bind(null, emit)
2623
const defaultLevel = DEFAULT_LEVEL[eventName]
27-
return { title: eventName, eventName, emit, emitMany, defaultLevel }
24+
return [
25+
eventName,
26+
{ title: eventName, eventName, emit, emitMany, defaultLevel },
27+
]
2828
}
2929

3030
// Emit several emits in parallel
@@ -33,6 +33,15 @@ export const emitEvents = async function (emit, maxEvents) {
3333
await Promise.all(array)
3434
}
3535

36+
const DEFAULT_LEVEL = {
37+
default: 'error',
38+
uncaughtException: 'error',
39+
warning: 'warn',
40+
unhandledRejection: 'error',
41+
rejectionHandled: 'error',
42+
multipleResolves: 'info',
43+
}
44+
3645
// Map of all possible events, with related information and helper methods
3746
export const EVENTS_MAP = getEventsMap()
3847

test/helpers/init.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import mapObj from 'map-obj'
12
import sinon from 'sinon'
23

34
import logProcessErrors from '../../src/main.js'
4-
import { mapValues } from '../../src/utils.js'
55

66
// Call `logProcessErrors()` then return spied objects and `stopLogging()`
77
export const startLogging = function ({ eventName, log, level, ...opts } = {}) {
@@ -45,7 +45,10 @@ const getLevel = function ({ level, eventName }) {
4545

4646
const levelA = level === undefined ? { default: 'default' } : level
4747

48-
return mapValues(levelA, (levelB) => onlyEvent.bind(null, levelB, eventName))
48+
return mapObj(levelA, (key, levelB) => [
49+
key,
50+
onlyEvent.bind(null, levelB, eventName),
51+
])
4952
}
5053

5154
const onlyEvent = function (level, eventName, error) {

test/limit.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import test from 'ava'
22
import { each } from 'test-each'
33

4-
// Required directly because this is exposed through documentation, but not
5-
// through code
6-
import { MAX_EVENTS } from '../src/limit.js'
7-
84
import { EVENTS } from './helpers/events/main.js'
95
import { startLogging } from './helpers/init.js'
106
import { removeProcessListeners } from './helpers/remove.js'
117
import { stubStackTraceRandom, unstubStackTrace } from './helpers/stack.js'
128

9+
const MAX_EVENTS = 100
10+
1311
removeProcessListeners()
1412

1513
each(EVENTS, ({ title }, { eventName, emit, emitMany }) => {

0 commit comments

Comments
 (0)