diff --git a/@commitlint/cli/fixtures/ignores/commitlint.config.js b/@commitlint/cli/fixtures/ignores/commitlint.config.js new file mode 100644 index 00000000000..9599060831e --- /dev/null +++ b/@commitlint/cli/fixtures/ignores/commitlint.config.js @@ -0,0 +1,12 @@ +module.exports = { + rules: { + 'type-enum': [2, 'always', ['type']], + 'scope-enum': [2, 'always', ['scope']], + 'subject-empty': [2, 'never'] + }, + ignores: [ + commit => { + return commit.includes('WIP'); + } + ] +}; diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index 27e408d5df9..0e21fd94c63 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -146,7 +146,8 @@ async function main(options) { const parserOpts = selectParserOpts(loaded.parserPreset); const opts = { parserOpts: {}, - plugins: {} + plugins: {}, + ignores: [] }; if (parserOpts) { opts.parserOpts = parserOpts; @@ -154,6 +155,9 @@ async function main(options) { if (loaded.plugins) { opts.plugins = loaded.plugins; } + if (loaded.ignores) { + opts.ignores = loaded.ignores; + } const format = loadFormatter(loaded, flags); // Strip comments if reading from `.git/COMMIT_EDIT_MSG` diff --git a/@commitlint/cli/src/cli.test.js b/@commitlint/cli/src/cli.test.js index 170c592e1e0..3cd9c4131c2 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.js @@ -306,6 +306,18 @@ test('should fail for invalid formatters from configuration', async t => { t.is(actual.code, 1); }); +test('should skip linting if message passes ignores array from configuration', async t => { + const cwd = await git.bootstrap('fixtures/ignores'); + const actual = await cli([], {cwd})('WIP'); + t.is(actual.code, 0); +}); + +test('should not skip linting if message passes ignores array from configuration', async t => { + const cwd = await git.bootstrap('fixtures/ignores'); + const actual = await cli([], {cwd})('foo'); + t.is(actual.code, 1); +}); + test('should fail for invalid formatters from flags', async t => { const cwd = await git.bootstrap('fixtures/custom-formatter'); const actual = await cli(['--format', 'through-flag'], {cwd})('foo: bar');