Skip to content

Commit

Permalink
fix: pass ignores from configuration in @commitlint/cli (#668)
Browse files Browse the repository at this point in the history
pass ignores from configuration to the linter
  • Loading branch information
zbanalagay authored and marionebl committed Jun 1, 2019
1 parent 19a4455 commit da99aaa
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
@@ -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
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
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 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');
Expand Down

0 comments on commit da99aaa

Please sign in to comment.