Skip to content

Commit 7448b7e

Browse files
committed
feat(rules): create header-full-stop rule
This is a simplified version of the subject-full-stop rule. Headers are always present, so we don’t need to check for empty-ness. If headers are not defined, the parser will throw with an error “expecting raw commit”.
1 parent fa6168a commit 7448b7e

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import message from '@commitlint/message';
2+
3+
export default (parsed, when, value) => {
4+
const {header} = parsed;
5+
const negated = when === 'never';
6+
const hasStop = header[header.length - 1] === value;
7+
8+
return [
9+
negated ? !hasStop : hasStop,
10+
message(['header', negated ? 'may not' : 'must', 'end with full stop'])
11+
];
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import test from 'ava';
2+
import parse from '@commitlint/parse';
3+
import check from './header-full-stop';
4+
5+
const messages = {
6+
with: `header.\n`,
7+
without: `header\n`
8+
};
9+
10+
const parsed = {
11+
with: parse(messages.with),
12+
without: parse(messages.without)
13+
};
14+
15+
test('with against "always ." should succeed', async t => {
16+
const [actual] = check(await parsed.with, 'always', '.');
17+
const expected = true;
18+
t.is(actual, expected);
19+
});
20+
21+
test('with against "never ." should fail', async t => {
22+
const [actual] = check(await parsed.with, 'never', '.');
23+
const expected = false;
24+
t.is(actual, expected);
25+
});
26+
27+
test('without against "always ." should fail', async t => {
28+
const [actual] = check(await parsed.without, 'always', '.');
29+
const expected = false;
30+
t.is(actual, expected);
31+
});
32+
33+
test('without against "never ." should succeed', async t => {
34+
const [actual] = check(await parsed.without, 'never', '.');
35+
const expected = true;
36+
t.is(actual, expected);
37+
});

@commitlint/rules/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
'footer-max-length': require('./footer-max-length'),
1111
'footer-max-line-length': require('./footer-max-line-length'),
1212
'footer-min-length': require('./footer-min-length'),
13+
'header-full-stop': require('./header-full-stop'),
1314
'header-max-length': require('./header-max-length'),
1415
'header-min-length': require('./header-min-length'),
1516
'references-empty': require('./references-empty'),

0 commit comments

Comments
 (0)