Fix literal URL and blank lines detection

This commit is contained in:
Titus Wormer 2016-01-24 12:26:50 +01:00
parent a81e82ba52
commit b6309f0c09
4 changed files with 44 additions and 4 deletions

View File

@ -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);
}
}
});

View File

@ -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('Dont use literal URLs without angle brackets', node);
}
});

5
test/fixtures/remark-github.md vendored Normal file
View File

@ -0,0 +1,5 @@
A user @wooorm.
A commit 1234567.
And an issue GH-1.

View File

@ -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.
*/