From 95f912738b5a97c5d1483018b203a6c6ff7e53b6 Mon Sep 17 00:00:00 2001 From: Lizz Banalagay Date: Thu, 30 May 2019 17:30:11 -0500 Subject: [PATCH] fix: pass ignores from configuration in @commitlint/cli pass ignores from configuration to the linter --- .../cli/fixtures/ignores/commitlint.config.js | 12 ++++++++++++ @commitlint/cli/src/cli.js | 6 +++++- @commitlint/cli/src/cli.test.js | 12 ++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 @commitlint/cli/fixtures/ignores/commitlint.config.js diff --git a/@commitlint/cli/fixtures/ignores/commitlint.config.js b/@commitlint/cli/fixtures/ignores/commitlint.config.js new file mode 100644 index 0000000000..9599060831 --- /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 27e408d5df..0e21fd94c6 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 170c592e1e..1ee4610941 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 matches ignores config', 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 does not match ignores config', 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');