From ea280c923031005a1dceee2cdf91949500110175 Mon Sep 17 00:00:00 2001 From: ResDiaryLewis Date: Wed, 31 Jul 2019 13:11:50 +0100 Subject: [PATCH 1/2] fix: pass defaultIgnores from configuration in @commitlint/cli pass defaultIgnores from configuration to the linter --- .../default-ignores-false/commitlint.config.js | 6 ++++++ .../default-ignores-true/commitlint.config.js | 6 ++++++ @commitlint/cli/src/cli.js | 6 +++++- @commitlint/cli/src/cli.test.js | 12 ++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 @commitlint/cli/fixtures/default-ignores-false/commitlint.config.js create mode 100644 @commitlint/cli/fixtures/default-ignores-true/commitlint.config.js diff --git a/@commitlint/cli/fixtures/default-ignores-false/commitlint.config.js b/@commitlint/cli/fixtures/default-ignores-false/commitlint.config.js new file mode 100644 index 0000000000..e738f076ff --- /dev/null +++ b/@commitlint/cli/fixtures/default-ignores-false/commitlint.config.js @@ -0,0 +1,6 @@ +module.exports = { + defaultIgnores: false, + rules: { + 'subject-empty': [2, 'never'] + } +}; diff --git a/@commitlint/cli/fixtures/default-ignores-true/commitlint.config.js b/@commitlint/cli/fixtures/default-ignores-true/commitlint.config.js new file mode 100644 index 0000000000..7cbab979de --- /dev/null +++ b/@commitlint/cli/fixtures/default-ignores-true/commitlint.config.js @@ -0,0 +1,6 @@ +module.exports = { + defaultIgnores: true, + rules: { + 'subject-empty': [2, 'never'] + } +}; diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index 0e21fd94c6..c6b7eda573 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -147,7 +147,8 @@ async function main(options) { const opts = { parserOpts: {}, plugins: {}, - ignores: [] + ignores: [], + defaultIgnores: false }; if (parserOpts) { opts.parserOpts = parserOpts; @@ -158,6 +159,9 @@ async function main(options) { if (loaded.ignores) { opts.ignores = loaded.ignores; } + if (loaded.defaultIgnores) { + opts.defaultIgnores = loaded.defaultIgnores; + } 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 1ee4610941..fd1b153a26 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.js @@ -318,6 +318,18 @@ test('should not skip linting if message does not match ignores config', async t t.is(actual.code, 1); }); +test('should not skip linting if defaultIgnores is false', async t => { + const cwd = await git.bootstrap('fixtures/default-ignores-false'); + const actual = await cli([], {cwd})('fixup! foo: bar'); + t.is(actual.code, 0); +}); + +test('should skip linting if defaultIgnores is true', async t => { + const cwd = await git.bootstrap('fixtures/default-ignores-false'); + const actual = await cli([], {cwd})('fixup! foo: bar'); + 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'); From 8903ef5d69904bf1494646f8e8fb28ee4160fbee Mon Sep 17 00:00:00 2001 From: ResDiaryLewis Date: Thu, 1 Aug 2019 09:17:01 +0100 Subject: [PATCH 2/2] fixup! fix: pass defaultIgnores from configuration in @commitlint/cli --- .../default-ignores-unset/commitlint.config.js | 5 +++++ @commitlint/cli/src/cli.js | 6 +++--- @commitlint/cli/src/cli.test.js | 12 +++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 @commitlint/cli/fixtures/default-ignores-unset/commitlint.config.js diff --git a/@commitlint/cli/fixtures/default-ignores-unset/commitlint.config.js b/@commitlint/cli/fixtures/default-ignores-unset/commitlint.config.js new file mode 100644 index 0000000000..426da89d6a --- /dev/null +++ b/@commitlint/cli/fixtures/default-ignores-unset/commitlint.config.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + 'subject-empty': [2, 'never'] + } +}; diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index c6b7eda573..cad49f191f 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -148,7 +148,7 @@ async function main(options) { parserOpts: {}, plugins: {}, ignores: [], - defaultIgnores: false + defaultIgnores: true }; if (parserOpts) { opts.parserOpts = parserOpts; @@ -159,8 +159,8 @@ async function main(options) { if (loaded.ignores) { opts.ignores = loaded.ignores; } - if (loaded.defaultIgnores) { - opts.defaultIgnores = loaded.defaultIgnores; + if (loaded.defaultIgnores === false) { + opts.defaultIgnores = false; } const format = loadFormatter(loaded, flags); diff --git a/@commitlint/cli/src/cli.test.js b/@commitlint/cli/src/cli.test.js index fd1b153a26..692497064e 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.js @@ -321,13 +321,19 @@ test('should not skip linting if message does not match ignores config', async t test('should not skip linting if defaultIgnores is false', async t => { const cwd = await git.bootstrap('fixtures/default-ignores-false'); const actual = await cli([], {cwd})('fixup! foo: bar'); - t.is(actual.code, 0); + t.is(actual.code, 1); }); test('should skip linting if defaultIgnores is true', async t => { - const cwd = await git.bootstrap('fixtures/default-ignores-false'); + const cwd = await git.bootstrap('fixtures/default-ignores-true'); const actual = await cli([], {cwd})('fixup! foo: bar'); - t.is(actual.code, 1); + t.is(actual.code, 0); +}); + +test('should skip linting if defaultIgnores is unset', async t => { + const cwd = await git.bootstrap('fixtures/default-ignores-unset'); + const actual = await cli([], {cwd})('fixup! foo: bar'); + t.is(actual.code, 0); }); test('should fail for invalid formatters from flags', async t => {