diff --git a/@commitlint/core/src/lint.js b/@commitlint/core/src/lint.js index 3b937e45f3..5987f91fff 100644 --- a/@commitlint/core/src/lint.js +++ b/@commitlint/core/src/lint.js @@ -41,14 +41,6 @@ export default async (message, rules = {}, opts = {}) => { ); } - if (config.length !== 2 && config.length !== 3) { - return new Error( - `config for rule ${name} must be 2 or 3 items long, received ${util.inspect( - config - )} of length ${config.length}` - ); - } - const [level, when] = config; if (typeof level !== 'number' || isNaN(level)) { @@ -59,6 +51,18 @@ export default async (message, rules = {}, opts = {}) => { ); } + if (level === 0 && config.length === 1) { + return null; + } + + if (config.length !== 2 && config.length !== 3) { + return new Error( + `config for rule ${name} must be 2 or 3 items long, received ${util.inspect( + config + )} of length ${config.length}` + ); + } + if (level < 0 || level > 2) { return new RangeError( `level for rule ${name} must be between 0 and 2, received ${util.inspect( diff --git a/@commitlint/core/src/lint.test.js b/@commitlint/core/src/lint.test.js index f845b1d623..3b1eb303dd 100644 --- a/@commitlint/core/src/lint.test.js +++ b/@commitlint/core/src/lint.test.js @@ -73,12 +73,15 @@ test('throws for invalid rule config', async t => { t.true(error.message.indexOf('scope-enum must be array') > -1); }); +test('allows disable shorthand', async t => { + await t.notThrows(lint('foo', {'type-enum': [0], 'scope-enum': [0]})); +}); + test('throws for rule with invalid length', async t => { const error = await t.throws( - lint('type(scope): foo', {'type-enum': [], 'scope-enum': [1, 2, 3, 4]}) + lint('type(scope): foo', {'scope-enum': [1, 2, 3, 4]}) ); - t.true(error.message.indexOf('type-enum must be 2 or 3 items long') > -1); t.true(error.message.indexOf('scope-enum must be 2 or 3 items long') > -1); });