diff --git a/lib/rules/no-consecutive-blank-lines.js b/lib/rules/no-consecutive-blank-lines.js index a8ab06d4..99162043 100644 --- a/lib/rules/no-consecutive-blank-lines.js +++ b/lib/rules/no-consecutive-blank-lines.js @@ -69,17 +69,19 @@ function noConsecutiveBlankLines(ast, file, preferred, done) { visit(ast, function (node) { var children = node.children; + var head = children && children[0]; + var tail = children && children[children.length - 1]; if (position.generated(node)) { return; } - if (children && children[0]) { + if (head && !position.generated(head)) { /* * Compare parent and first child. */ - compare(position.start(node), position.start(children[0]), 0); + compare(position.start(node), position.start(head), 0); /* * Compare between each child. @@ -118,7 +120,9 @@ function noConsecutiveBlankLines(ast, file, preferred, done) { * Compare parent and last child. */ - compare(position.end(node), position.end(children[children.length - 1]), 1); + if (tail !== head && !position.generated(tail)) { + compare(position.end(node), position.end(tail), 1); + } } }); diff --git a/lib/rules/no-literal-urls.js b/lib/rules/no-literal-urls.js index 46c8dfe9..2ec32e96 100644 --- a/lib/rules/no-literal-urls.js +++ b/lib/rules/no-literal-urls.js @@ -22,6 +22,7 @@ */ var visit = require('unist-util-visit'); +var toString = require('mdast-util-to-string'); var position = require('mdast-util-position'); /* @@ -31,6 +32,12 @@ var position = require('mdast-util-position'); var start = position.start; var end = position.end; +/* + * Constants. + */ + +var MAILTO = 'mailto:'; + /** * Warn for literal URLs without angle-brackets. * @@ -45,12 +52,17 @@ function noLiteralURLs(ast, file, preferred, done) { var tail = end(node.children[node.children.length - 1]).column; var initial = start(node).column; var final = end(node).column; + var value = toString(node); if (position.generated(node)) { return; } - if (initial === head && final === tail) { + if ( + initial === head && + final === tail && + (value === node.href || value == MAILTO + node.href) + ) { file.warn('Don’t use literal URLs without angle brackets', node); } }); diff --git a/test/fixtures/remark-github.md b/test/fixtures/remark-github.md new file mode 100644 index 00000000..ba0b1e7e --- /dev/null +++ b/test/fixtures/remark-github.md @@ -0,0 +1,5 @@ +A user @wooorm. + +A commit 1234567. + +And an issue GH-1. diff --git a/test/index.js b/test/index.js index 9ae2f42e..1297b7aa 100644 --- a/test/index.js +++ b/test/index.js @@ -16,6 +16,7 @@ var assert = require('assert'); var remark = require('remark'); var File = require('vfile'); var toc = require('remark-toc'); +var github = require('remark-github'); var lint = require('..'); var plural = require('plur'); var clean = require('./clean'); @@ -302,6 +303,24 @@ describe('Gaps', function () { }); }); +/* + * Validate only “real” links are warned about. + */ + +describe('GitHub', function () { + it('should supports gaps in a document', function (done) { + var file = toFile('remark-github.md'); + var processor = remark().use(github).use(lint); + + file.quiet = true; + + processor.process(file, function (err) { + assert(file.messages.length === 0); + done(err); + }); + }); +}); + /* * Validate inline en- and disabling. */