Skip to content

Commit

Permalink
fix: use default value for null options
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Oct 8, 2018
1 parent 15208d8 commit e1aac3d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/resolve-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {isUndefined, castArray} = require('lodash');
const {isNil, castArray} = require('lodash');

module.exports = ({assets, message}) => ({
assets: isUndefined(assets)
assets: isNil(assets)
? ['CHANGELOG.md', 'package.json', 'package-lock.json', 'npm-shrinkwrap.json']
: assets
? castArray(assets)
Expand Down
9 changes: 5 additions & 4 deletions lib/verify.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const {isString, isUndefined, isArray, isPlainObject} = require('lodash');
const {isString, isNil, isArray, isPlainObject} = require('lodash');
const AggregateError = require('aggregate-error');
const getError = require('./get-error');
const resolveConfig = require('./resolve-config');

const isNonEmptyString = value => isString(value) && value.trim();
const isStringOrStringArray = value => isNonEmptyString(value) || (isArray(value) && value.every(isNonEmptyString));
const isArrayOf = validator => array => isArray(array) && array.every(value => validator(value));
const canBeDisabled = validator => value => value === false || validator(value);

const VALIDATORS = {
assets: isArrayOf(
asset => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path))
assets: canBeDisabled(
isArrayOf(asset => isStringOrStringArray(asset) || (isPlainObject(asset) && isStringOrStringArray(asset.path)))
),
message: isNonEmptyString,
};
Expand All @@ -28,7 +29,7 @@ module.exports = pluginConfig => {

const errors = Object.entries(options).reduce(
(errors, [option, value]) =>
!isUndefined(value) && value !== false && !VALIDATORS[option](value)
!isNil(value) && !VALIDATORS[option](value)
? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})]
: errors,
[]
Expand Down

0 comments on commit e1aac3d

Please sign in to comment.