Skip to content

Commit 84cf938

Browse files
committed
fix: allow [0] shorthand
1 parent edf7187 commit 84cf938

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

@commitlint/core/src/lint.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,6 @@ export default async (message, rules = {}, opts = {}) => {
4141
);
4242
}
4343

44-
if (config.length !== 2 && config.length !== 3) {
45-
return new Error(
46-
`config for rule ${name} must be 2 or 3 items long, received ${util.inspect(
47-
config
48-
)} of length ${config.length}`
49-
);
50-
}
51-
5244
const [level, when] = config;
5345

5446
if (typeof level !== 'number' || isNaN(level)) {
@@ -59,6 +51,18 @@ export default async (message, rules = {}, opts = {}) => {
5951
);
6052
}
6153

54+
if (level === 0 && config.length === 1) {
55+
return null;
56+
}
57+
58+
if (config.length !== 2 && config.length !== 3) {
59+
return new Error(
60+
`config for rule ${name} must be 2 or 3 items long, received ${util.inspect(
61+
config
62+
)} of length ${config.length}`
63+
);
64+
}
65+
6266
if (level < 0 || level > 2) {
6367
return new RangeError(
6468
`level for rule ${name} must be between 0 and 2, received ${util.inspect(

@commitlint/core/src/lint.test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,15 @@ test('throws for invalid rule config', async t => {
7373
t.true(error.message.indexOf('scope-enum must be array') > -1);
7474
});
7575

76+
test('allows disable shorthand', async t => {
77+
await t.notThrows(lint('foo', {'type-enum': [0], 'scope-enum': [0]}));
78+
});
79+
7680
test('throws for rule with invalid length', async t => {
7781
const error = await t.throws(
78-
lint('type(scope): foo', {'type-enum': [], 'scope-enum': [1, 2, 3, 4]})
82+
lint('type(scope): foo', {'scope-enum': [1, 2, 3, 4]})
7983
);
8084

81-
t.true(error.message.indexOf('type-enum must be 2 or 3 items long') > -1);
8285
t.true(error.message.indexOf('scope-enum must be 2 or 3 items long') > -1);
8386
});
8487

0 commit comments

Comments
 (0)