Skip to content

Commit

Permalink
fix: pass ignores from configuration in @commitlint/cli
Browse files Browse the repository at this point in the history
pass ignores from configuration to the linter
  • Loading branch information
zbanalagay committed May 30, 2019
1 parent 7a75626 commit fa9963b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions @commitlint/cli/fixtures/ignores/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -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');
}
]
};
6 changes: 5 additions & 1 deletion @commitlint/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,18 @@ async function main(options) {
const parserOpts = selectParserOpts(loaded.parserPreset);
const opts = {
parserOpts: {},
plugins: {}
plugins: {},
ignores: []
};
if (parserOpts) {
opts.parserOpts = parserOpts;
}
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`
Expand Down
12 changes: 12 additions & 0 deletions @commitlint/cli/src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit fa9963b

Please sign in to comment.