diff --git a/@commitlint/cli/cli.js b/@commitlint/cli/cli.js index d0959716c1..919ef5c40b 100755 --- a/@commitlint/cli/cli.js +++ b/@commitlint/cli/cli.js @@ -16,8 +16,8 @@ const help = require('./help'); */ const rules = { fromStdin: (input, flags) => input.length === 0 && - flags.from === null && - flags.to === null && + typeof flags.from !== 'string' && + typeof flags.to !== 'string' && !flags.edit }; @@ -62,7 +62,8 @@ const cli = meow({ const load = seed => core.load(seed); function main(options) { - const {input: raw, flags} = options; + const raw = options.input; + const flags = options.flags; const fromStdin = rules.fromStdin(raw, flags); const range = pick(flags, 'edit', 'from', 'to'); @@ -93,8 +94,10 @@ function main(options) { )); } -function getSeed({extends: e}) { - return e ? {extends: e.split(', ')} : {}; +function getSeed(seed) { + const e = Array.isArray(seed.extends) ? seed.extends : [seed.extends]; + const n = e.filter(i => typeof i === 'string'); + return n.length > 0 ? {extends: n} : {}; } // Start the engine diff --git a/@commitlint/cli/help.js b/@commitlint/cli/help.js index 0fe8542d98..dbe2471527 100644 --- a/@commitlint/cli/help.js +++ b/@commitlint/cli/help.js @@ -1,7 +1,8 @@ module.exports = configuration => { const lines = Object.entries(configuration.description) .map(entry => { - const [name, desc] = entry; + const name = entry[0]; + const desc = entry[1]; const alias = Object.entries(configuration.alias) .find(entry => entry[1] === name) .map(entry => entry[0])[0]; @@ -11,14 +12,16 @@ module.exports = configuration => { const longest = lines .map(line => { - const [flags] = line; + const flags = line[0]; return flags.reduce((sum, flag) => sum + flag.length, 0); }) .sort(Number)[0]; return lines .map(line => { - const [flags, desc, defaults] = line; + const flags = line[0]; + const desc = line[1]; + const defaults = line[2]; const fs = flags.map(flag => flag.length > 1 ? `--${flag}` : `-${flag}`); const ds = defaults ? `, defaults to: ${defaults}` : ''; const length = flags.reduce((sum, flag) => sum + flag.length, 0); diff --git a/@commitlint/core/src/library/resolve-extends.js b/@commitlint/core/src/library/resolve-extends.js index afcfab36f2..f81d473de4 100644 --- a/@commitlint/core/src/library/resolve-extends.js +++ b/@commitlint/core/src/library/resolve-extends.js @@ -1,6 +1,6 @@ import path from 'path'; import from from 'resolve-from'; -import {merge, omit, values} from 'lodash'; +import {merge, omit} from 'lodash'; // Resolve extend configs export default function resolveExtends(config = {}, context = {}) { @@ -18,8 +18,7 @@ export default function resolveExtends(config = {}, context = {}) { // (any, string, string, Function) => any[]; function loadExtends(config = {}, context = {}) { - const toExtend = values(config.extends || []); - return toExtend.reduce((configs, raw) => { + return (config.extends || []).reduce((configs, raw) => { const id = getId(raw, context.prefix); const resolve = context.resolve || resolveId; const resolved = resolve(id, context); @@ -46,7 +45,6 @@ function getId(raw = '', prefix = '') { return (scoped || relative) ? raw : [prefix, raw].filter(String).join('-'); } -function resolveId(id, context) { - const cwd = context.cwd || process.cwd(); - return from(cwd, id); +function resolveId(id, context = {}) { + return from(context.cwd || process.cwd(), id); }