Skip to content

Commit da99aaa

Browse files
zbanalagaymarionebl
authored andcommitted
fix: pass ignores from configuration in @commitlint/cli (#668)
pass ignores from configuration to the linter
1 parent 19a4455 commit da99aaa

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
rules: {
3+
'type-enum': [2, 'always', ['type']],
4+
'scope-enum': [2, 'always', ['scope']],
5+
'subject-empty': [2, 'never']
6+
},
7+
ignores: [
8+
commit => {
9+
return commit.includes('WIP');
10+
}
11+
]
12+
};

@commitlint/cli/src/cli.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,18 @@ async function main(options) {
146146
const parserOpts = selectParserOpts(loaded.parserPreset);
147147
const opts = {
148148
parserOpts: {},
149-
plugins: {}
149+
plugins: {},
150+
ignores: []
150151
};
151152
if (parserOpts) {
152153
opts.parserOpts = parserOpts;
153154
}
154155
if (loaded.plugins) {
155156
opts.plugins = loaded.plugins;
156157
}
158+
if (loaded.ignores) {
159+
opts.ignores = loaded.ignores;
160+
}
157161
const format = loadFormatter(loaded, flags);
158162

159163
// Strip comments if reading from `.git/COMMIT_EDIT_MSG`

@commitlint/cli/src/cli.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,18 @@ test('should fail for invalid formatters from configuration', async t => {
306306
t.is(actual.code, 1);
307307
});
308308

309+
test('should skip linting if message matches ignores config', async t => {
310+
const cwd = await git.bootstrap('fixtures/ignores');
311+
const actual = await cli([], {cwd})('WIP');
312+
t.is(actual.code, 0);
313+
});
314+
315+
test('should not skip linting if message does not match ignores config', async t => {
316+
const cwd = await git.bootstrap('fixtures/ignores');
317+
const actual = await cli([], {cwd})('foo');
318+
t.is(actual.code, 1);
319+
});
320+
309321
test('should fail for invalid formatters from flags', async t => {
310322
const cwd = await git.bootstrap('fixtures/custom-formatter');
311323
const actual = await cli(['--format', 'through-flag'], {cwd})('foo: bar');

0 commit comments

Comments
 (0)