Skip to content

Commit e9805dc

Browse files
committed
Feat: change min/maxChar disable function to -1
1 parent a02bd55 commit e9805dc

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,13 @@ Available rules:
149149

150150
**Default:** `72`
151151

152-
If a number is set, it will not allow to commit messages **more than** the given number. If it is set to `false` the rule is deactivated
152+
If a number is set, it will not allow to commit messages **more than** the given number. If it is set to `-1` the rule is deactivated
153153

154154
Example:
155155
```json
156156
{
157157
"rules": {
158-
"max-char": false
158+
"max-char": -1
159159
}
160160
}
161161
```
@@ -166,13 +166,13 @@ Example:
166166

167167
**Default:** `10`
168168

169-
If a number is set, it will not allow to commit messages **less than** the given number. If it is set to `false` the rule is deactivated
169+
If a number is set, it will not allow to commit messages **less than** the given number. If it is set to `-1` the rule is deactivated
170170

171171
Example:
172172
```json
173173
{
174174
"rules": {
175-
"min-char": false
175+
"min-char": -1
176176
}
177177
}
178178
```

lib/rules/availableRules.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ const rules = {
1010
maxChar: (input, config) => ({
1111
message: () => `The commit message is not allowed to be longer as ${config.rules['max-char']}. Consider writing a body.`,
1212
check: () => {
13-
if (input.length > config.rules['max-char']) return false;
13+
let number = config.rules['max-char'];
14+
15+
if (number === -1) {
16+
number = Number.POSITIVE_INFINITY;
17+
}
18+
19+
if (input.length > number) return false;
1420

1521
return true;
1622
},

test/rules/availableRules.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ test('rules minChar', (t) => {
2424
t.true(minChar);
2525
});
2626

27+
test('-1 in minChar', (t) => {
28+
const rulesObj = {
29+
'min-char': -1,
30+
};
31+
const shortText = rules.minChar('n', { rules: rulesObj }).check();
32+
const longText = rules.minChar('this are more than 10 characters', { rules: rulesObj }).check();
33+
34+
t.true(shortText);
35+
t.true(longText);
36+
});
37+
2738
test('rules mxChar', (t) => {
2839
const rulesObj = {
2940
'max-char': 72,
@@ -34,3 +45,14 @@ test('rules mxChar', (t) => {
3445
t.false(moreThanMaxChar);
3546
t.true(lessThanMaxChar);
3647
});
48+
49+
test('-1 in maxChar', (t) => {
50+
const rulesObj = {
51+
'min-char': -1,
52+
};
53+
const longText = rules.maxChar('this are more than 72 characters, believe me or not but the value moreThanMaxChar will be true ;-P', { rules: rulesObj }).check();
54+
const shortText = rules.maxChar('this are less than 72 characters', { rules: rulesObj }).check();
55+
56+
t.true(longText);
57+
t.true(shortText);
58+
});

0 commit comments

Comments
 (0)