Skip to content

Commit 3032b71

Browse files
authored
tests and bugfix for line-after-title (#29)
* add basic tests for line-after-title rule * fix line-after-title for commits without a body
1 parent 3977e00 commit 3032b71

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

lib/rules/line-after-title.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
, options: {}
1313
, validate: (context, rule) => {
1414
// all commits should have a body and a blank line after the title
15-
if (!context.body.length || context.body[0]) {
15+
if (context.body[0]) {
1616
context.report({
1717
id: id
1818
, message: 'blank line expected after title'

test/rules/line-after-title.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
'use strict'
2+
3+
const test = require('tap').test
4+
const Rule = require('../../lib/rules/line-after-title')
5+
const Commit = require('gitlint-parser-node')
6+
const Validator = require('../../')
7+
8+
test('rule: line-after-title', (t) => {
9+
t.test('no blank line', (tt) => {
10+
tt.plan(7)
11+
const v = new Validator()
12+
const context = new Commit({
13+
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
14+
, author: {
15+
name: 'Evan Lucas'
16+
, email: '[email protected]'
17+
, date: '2016-04-12T19:42:23Z'
18+
}
19+
, message: 'test: fix something\nfhqwhgads'
20+
}, v)
21+
22+
context.report = (opts) => {
23+
tt.pass('called report')
24+
tt.equal(opts.id, 'line-after-title', 'id')
25+
tt.equal(opts.message, 'blank line expected after title', 'message')
26+
tt.equal(opts.string, 'fhqwhgads', 'string')
27+
tt.equal(opts.line, 1, 'line')
28+
tt.equal(opts.column, 0, 'column')
29+
tt.equal(opts.level, 'fail', 'level')
30+
}
31+
32+
Rule.validate(context)
33+
})
34+
35+
t.test('blank line', (tt) => {
36+
tt.plan(4)
37+
const v = new Validator()
38+
const context = new Commit({
39+
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
40+
, author: {
41+
name: 'Evan Lucas'
42+
, email: '[email protected]'
43+
, date: '2016-04-12T19:42:23Z'
44+
}
45+
, message: 'test: fix something\n\nfhqwhgads'
46+
}, v)
47+
48+
context.report = (opts) => {
49+
tt.pass('called report')
50+
tt.equal(opts.id, 'line-after-title', 'id')
51+
tt.equal(opts.message, 'blank line after title', 'message')
52+
tt.equal(opts.level, 'pass', 'level')
53+
}
54+
55+
Rule.validate(context)
56+
})
57+
58+
t.test('just one line', (tt) => {
59+
tt.plan(4)
60+
const v = new Validator()
61+
const context = new Commit({
62+
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
63+
, author: {
64+
name: 'Evan Lucas'
65+
, email: '[email protected]'
66+
, date: '2016-04-12T19:42:23Z'
67+
}
68+
, message: 'test: fix something'
69+
}, v)
70+
71+
context.report = (opts) => {
72+
tt.pass('called report')
73+
tt.equal(opts.id, 'line-after-title', 'id')
74+
tt.equal(opts.message, 'blank line after title', 'message')
75+
tt.equal(opts.level, 'pass', 'level')
76+
}
77+
78+
Rule.validate(context)
79+
})
80+
81+
t.end()
82+
})

0 commit comments

Comments
 (0)