diff --git a/index.js b/index.js index 4f33c1d..f924ccf 100644 --- a/index.js +++ b/index.js @@ -60,7 +60,9 @@ function cleanEnv(inputEnv, specs = {}, options = {}) { ((devDefault !== undefined) && (devDefault === rawValue)) try { - if (rawValue === undefined && !usingFalsyDefault) throw new EnvMissingError(spec.desc || '') + if (rawValue === undefined && !usingFalsyDefault) { + throw new EnvMissingError(spec.desc || '') + } output[k] = validateVar({ name: k, spec, rawValue }) } catch (err) { if (options.reporter === null) throw err @@ -90,4 +92,6 @@ function cleanEnv(inputEnv, specs = {}, options = {}) { return Object.freeze(output) } -module.exports = { cleanEnv, makeValidator, bool, num, str, json, url, email, EnvError, EnvMissingError } +module.exports = { + cleanEnv, makeValidator, bool, num, str, json, url, email, EnvError, EnvMissingError +} diff --git a/lib/validators.js b/lib/validators.js index edf92e4..c015099 100644 --- a/lib/validators.js +++ b/lib/validators.js @@ -54,7 +54,7 @@ exports.num = makeValidator(input => { }, 'num') exports.str = makeValidator(input => { - if (typeof input === 'string') return input; + if (typeof input === 'string') return input throw new EnvError(`Not a string: "${input}"`) }, 'str') @@ -65,7 +65,7 @@ exports.email = makeValidator(x => { exports.url = makeValidator(x => { const url = require('url') - let isValid; + let isValid = false if (url.URL) { try { diff --git a/tests/test_basics.js b/tests/test_basics.js index 3465718..1aeff92 100644 --- a/tests/test_basics.js +++ b/tests/test_basics.js @@ -17,11 +17,12 @@ test('strict option: only specified fields are passed through', () => { }) test('transformer option: allow transformation of keys', () => { + const lowerCaseKey = (acc, [key, value]) => Object.assign(acc, { [key.toLowerCase()]: value }) const opts = { transformer: i => Object .keys(i) .map(e => [e, i[e]]) - .reduce((memo, [key, value]) => Object.assign({}, memo, { [key.toLowerCase()]: value }), {}) + .reduce(lowerCaseKey, {}) } const env = cleanEnv({ FOO: 'bar', FOO_BAR: 'baz' }, { FOO: str() diff --git a/tests/test_dotenv.js b/tests/test_dotenv.js index a027526..62bf311 100644 --- a/tests/test_dotenv.js +++ b/tests/test_dotenv.js @@ -1,6 +1,6 @@ const fs = require('fs') const { createGroup, assert } = require('painless') -const { cleanEnv, EnvError, str, num } = require('..') +const { cleanEnv, str, num } = require('..') const test = createGroup() test.beforeEach(() => fs.writeFileSync('.env', ` diff --git a/tests/test_reporter.js b/tests/test_reporter.js index 6744892..508e72d 100644 --- a/tests/test_reporter.js +++ b/tests/test_reporter.js @@ -9,7 +9,7 @@ test.beforeEach(() => { exitSpy = stub(process, 'exit', () => {}) }) test.afterEach(() => { - console.error.restore() + console.error.restore() // eslint-disable-line no-console process.exit.restore() })