Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass ignores from configuration in @commitlint/cli #668

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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