Skip to content

Commit 6acb930

Browse files
committed
feat: add footer rules
1 parent c6714a4 commit 6acb930

File tree

5 files changed

+124
-52
lines changed

5 files changed

+124
-52
lines changed

documentation/rules.md

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,51 +33,70 @@ Rule configurations are either of type `array` residing on a key with the rule's
3333

3434

3535
### Available rules
36-
#### type-enum
37-
* **condition**: `type` is found in value
36+
#### body-leading-blank
37+
* **condition**: `body` begins with blank line
38+
* **rule**: `always`
39+
40+
#### body-max-length
41+
* **condition**: `body` has `value` or less characters
3842
* **rule**: `always`
3943
* **value**
40-
```js
41-
[
42-
'feat',
43-
'fix',
44-
'docs',
45-
'style',
46-
'refactor',
47-
'test',
48-
'chore',
49-
'revert'
50-
]
51-
```
44+
```js
45+
Infinity
46+
```
5247

53-
#### type-case
54-
* **description**: `type` is in case `value`
48+
#### body-min-length
49+
* **condition**: `body` has `value` or more characters
5550
* **rule**: `always`
5651
* **value**
57-
```js
58-
'lowerCase'
59-
```
52+
```js
53+
0
54+
```
6055

61-
#### type-empty
62-
* **condition**: `type` is empty
63-
* **rule**: `never`
56+
#### footer-leading-blank
57+
* **condition**: `footer` begins with blank line
58+
* **rule**: `always`
6459

65-
#### type-max-length
66-
* **condition**: `type` has `value` or less characters
60+
#### footer-max-length
61+
* **condition**: `footer` has `value` or less characters
6762
* **rule**: `always`
6863
* **value**
6964
```js
7065
Infinity
7166
```
7267

73-
#### type-min-length
74-
* **condition**: `type` has `value` or more characters
68+
#### footer-min-length
69+
* **condition**: `footer` has `value` or more characters
70+
* **rule**: `always`
71+
* **value**
72+
```js
73+
0
74+
```
75+
76+
#### header-max-length
77+
* **condition**: `header` has `value` or less characters
78+
* **rule**: `always`
79+
* **value**
80+
```js
81+
72
82+
```
83+
84+
#### header-min-length
85+
* **condition**: `header` has `value` or more characters
7586
* **rule**: `always`
7687
* **value**
7788
```js
7889
0
7990
```
8091

92+
#### lang
93+
* **condition**: `subject` is of language `value`
94+
* **rule**: `always`
95+
* **value**
96+
```js
97+
eng
98+
```
99+
81100
#### scope-enum
82101
* **condition**: `scope` is found in value
83102
* **rule**: `always`
@@ -148,49 +167,51 @@ Rule configurations are either of type `array` residing on a key with the rule's
148167
'.'
149168
```
150169

151-
#### body-leading-blank
152-
* **condition**: `body` begins with blank line
153-
* **rule**: `always`
154-
155-
#### body-max-length
156-
* **condition**: `body` has `value` or less characters
170+
#### type-enum
171+
* **condition**: `type` is found in value
157172
* **rule**: `always`
158173
* **value**
159-
```js
160-
Infinity
161-
```
174+
```js
175+
[
176+
'feat',
177+
'fix',
178+
'docs',
179+
'style',
180+
'refactor',
181+
'test',
182+
'chore',
183+
'revert'
184+
]
185+
```
162186

163-
#### body-min-length
164-
* **condition**: `body` has `value` or more characters
187+
#### type-case
188+
* **description**: `type` is in case `value`
165189
* **rule**: `always`
166190
* **value**
167-
```js
168-
0
169-
```
191+
```js
192+
'lowerCase'
193+
```
170194

171-
#### header-max-length
172-
* **condition**: `header` has `value` or less characters
195+
#### type-empty
196+
* **condition**: `type` is empty
197+
* **rule**: `never`
198+
199+
#### type-max-length
200+
* **condition**: `type` has `value` or less characters
173201
* **rule**: `always`
174202
* **value**
175203
```js
176-
72
204+
Infinity
177205
```
178206

179-
#### header-min-length
180-
* **condition**: `header` has `value` or more characters
207+
#### type-min-length
208+
* **condition**: `type` has `value` or more characters
181209
* **rule**: `always`
182210
* **value**
183211
```js
184212
0
185213
```
186214

187-
#### lang
188-
* **condition**: `subject` is of language `value`
189-
* **rule**: `always`
190-
* **value**
191-
```js
192-
eng
193-
```
194215

195216
### Wildcards
196217
The following rules identify commits that pass linting by skipping all other rules.

source/rules/footer-empty.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import ensureNotEmpty from '../library/ensure-not-empty';
2+
3+
export default (parsed, when) => {
4+
const negated = when === 'never';
5+
return [
6+
ensureNotEmpty(parsed.footer),
7+
[
8+
'footer',
9+
negated ? 'may not' : 'must',
10+
'be empty'
11+
]
12+
.filter(Boolean)
13+
.join(' ')
14+
];
15+
};

source/rules/footer-leading-blank.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default (parsed, when) => {
2+
const negated = when === 'never';
3+
// get complete body split into lines
4+
const lines = (parsed.raw || '').split('\n').slice(2);
5+
// check if the first line of body (if any) is empty
6+
const leadingBlank =
7+
lines.length > 0 ?
8+
lines[0].length === 0 :
9+
true;
10+
return [
11+
negated ? !leadingBlank : leadingBlank,
12+
[
13+
'footer',
14+
negated ? 'may not' : 'must',
15+
'have leading blank line'
16+
]
17+
.filter(Boolean)
18+
.join(' ')
19+
];
20+
};

source/rules/footer-max-length.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import ensureMaxLength from '../library/ensure-max-length';
2+
3+
export default (parsed, when, value) => {
4+
return [
5+
ensureMaxLength(parsed.footer, value),
6+
`footer must not be longer than ${value} characters`
7+
];
8+
};

source/rules/footer-min-length.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import ensureMinLength from '../library/ensure-min-length';
2+
3+
export default (parsed, when, value) => {
4+
return [
5+
ensureMinLength(parsed.footer, value),
6+
`footer must not be shorter than ${value} characters`
7+
];
8+
};

0 commit comments

Comments
 (0)