diff --git a/lib/rules/line-after-title.js b/lib/rules/line-after-title.js index 02ef6c6..d976479 100644 --- a/lib/rules/line-after-title.js +++ b/lib/rules/line-after-title.js @@ -12,7 +12,7 @@ module.exports = { , options: {} , validate: (context, rule) => { // all commits should have a body and a blank line after the title - if (!context.body.length || context.body[0]) { + if (context.body[0]) { context.report({ id: id , message: 'blank line expected after title' diff --git a/test/rules/line-after-title.js b/test/rules/line-after-title.js new file mode 100644 index 0000000..4b99afd --- /dev/null +++ b/test/rules/line-after-title.js @@ -0,0 +1,82 @@ +'use strict' + +const test = require('tap').test +const Rule = require('../../lib/rules/line-after-title') +const Commit = require('gitlint-parser-node') +const Validator = require('../../') + +test('rule: line-after-title', (t) => { + t.test('no blank line', (tt) => { + tt.plan(7) + const v = new Validator() + const context = new Commit({ + sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea' + , author: { + name: 'Evan Lucas' + , email: 'evanlucas@me.com' + , date: '2016-04-12T19:42:23Z' + } + , message: 'test: fix something\nfhqwhgads' + }, v) + + context.report = (opts) => { + tt.pass('called report') + tt.equal(opts.id, 'line-after-title', 'id') + tt.equal(opts.message, 'blank line expected after title', 'message') + tt.equal(opts.string, 'fhqwhgads', 'string') + tt.equal(opts.line, 1, 'line') + tt.equal(opts.column, 0, 'column') + tt.equal(opts.level, 'fail', 'level') + } + + Rule.validate(context) + }) + + t.test('blank line', (tt) => { + tt.plan(4) + const v = new Validator() + const context = new Commit({ + sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea' + , author: { + name: 'Evan Lucas' + , email: 'evanlucas@me.com' + , date: '2016-04-12T19:42:23Z' + } + , message: 'test: fix something\n\nfhqwhgads' + }, v) + + context.report = (opts) => { + tt.pass('called report') + tt.equal(opts.id, 'line-after-title', 'id') + tt.equal(opts.message, 'blank line after title', 'message') + tt.equal(opts.level, 'pass', 'level') + } + + Rule.validate(context) + }) + + t.test('just one line', (tt) => { + tt.plan(4) + const v = new Validator() + const context = new Commit({ + sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea' + , author: { + name: 'Evan Lucas' + , email: 'evanlucas@me.com' + , date: '2016-04-12T19:42:23Z' + } + , message: 'test: fix something' + }, v) + + context.report = (opts) => { + tt.pass('called report') + tt.equal(opts.id, 'line-after-title', 'id') + tt.equal(opts.message, 'blank line after title', 'message') + tt.equal(opts.level, 'pass', 'level') + } + + Rule.validate(context) + }) + + t.end() +})