Skip to content

Commit

Permalink
fix: Config file array files should be recognized as options of array…
Browse files Browse the repository at this point in the history
… type (#1199)
  • Loading branch information
rpl authored and kumar303 committed Jan 9, 2018
1 parent cdb5b00 commit 854c82c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/config.js
Expand Up @@ -66,7 +66,11 @@ export function applyConfigToArgv({
const expectedType = options[decamelizedOptName].type ===
'count' ? 'number' : options[decamelizedOptName].type;

const optionType = typeof configObject[option];
const optionType = (
Array.isArray(configObject[option]) ?
'array' : typeof configObject[option]
);

if (optionType !== expectedType) {
throw new UsageError(`The config file at ${configFileName} specified ` +
`the type of "${option}" incorrectly as "${optionType}"` +
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test.config.js
Expand Up @@ -277,6 +277,25 @@ describe('config', () => {
assert.strictEqual(argv.filePath, secondConfigObject.filePath);
});

it('recognizes array config values as array types', () => {
const params = makeArgv({
userCmd: ['fakecommand'],
globalOpt: {
'ignore-files': {
demand: false,
type: 'array',
},
},
});

const configObject = {
ignoreFiles: ['file1', 'file2'],
};

const argv = applyConf({...params, configObject});
assert.strictEqual(argv.ignoreFiles, configObject.ignoreFiles);
});

it('uses CLI option over undefined configured option and default', () => {
const cmdLineSrcDir = '/user/specified/source/dir/';
const params = makeArgv({
Expand Down

0 comments on commit 854c82c

Please sign in to comment.