Skip to content

Commit b6309f0

Browse files
committed
Fix literal URL and blank lines detection
1 parent a81e82b commit b6309f0

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

lib/rules/no-consecutive-blank-lines.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,19 @@ function noConsecutiveBlankLines(ast, file, preferred, done) {
6969

7070
visit(ast, function (node) {
7171
var children = node.children;
72+
var head = children && children[0];
73+
var tail = children && children[children.length - 1];
7274

7375
if (position.generated(node)) {
7476
return;
7577
}
7678

77-
if (children && children[0]) {
79+
if (head && !position.generated(head)) {
7880
/*
7981
* Compare parent and first child.
8082
*/
8183

82-
compare(position.start(node), position.start(children[0]), 0);
84+
compare(position.start(node), position.start(head), 0);
8385

8486
/*
8587
* Compare between each child.
@@ -118,7 +120,9 @@ function noConsecutiveBlankLines(ast, file, preferred, done) {
118120
* Compare parent and last child.
119121
*/
120122

121-
compare(position.end(node), position.end(children[children.length - 1]), 1);
123+
if (tail !== head && !position.generated(tail)) {
124+
compare(position.end(node), position.end(tail), 1);
125+
}
122126
}
123127
});
124128

lib/rules/no-literal-urls.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
var visit = require('unist-util-visit');
25+
var toString = require('mdast-util-to-string');
2526
var position = require('mdast-util-position');
2627

2728
/*
@@ -31,6 +32,12 @@ var position = require('mdast-util-position');
3132
var start = position.start;
3233
var end = position.end;
3334

35+
/*
36+
* Constants.
37+
*/
38+
39+
var MAILTO = 'mailto:';
40+
3441
/**
3542
* Warn for literal URLs without angle-brackets.
3643
*
@@ -45,12 +52,17 @@ function noLiteralURLs(ast, file, preferred, done) {
4552
var tail = end(node.children[node.children.length - 1]).column;
4653
var initial = start(node).column;
4754
var final = end(node).column;
55+
var value = toString(node);
4856

4957
if (position.generated(node)) {
5058
return;
5159
}
5260

53-
if (initial === head && final === tail) {
61+
if (
62+
initial === head &&
63+
final === tail &&
64+
(value === node.href || value == MAILTO + node.href)
65+
) {
5466
file.warn('Don’t use literal URLs without angle brackets', node);
5567
}
5668
});

test/fixtures/remark-github.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
A user @wooorm.
2+
3+
A commit 1234567.
4+
5+
And an issue GH-1.

test/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var assert = require('assert');
1616
var remark = require('remark');
1717
var File = require('vfile');
1818
var toc = require('remark-toc');
19+
var github = require('remark-github');
1920
var lint = require('..');
2021
var plural = require('plur');
2122
var clean = require('./clean');
@@ -302,6 +303,24 @@ describe('Gaps', function () {
302303
});
303304
});
304305

306+
/*
307+
* Validate only “real” links are warned about.
308+
*/
309+
310+
describe('GitHub', function () {
311+
it('should supports gaps in a document', function (done) {
312+
var file = toFile('remark-github.md');
313+
var processor = remark().use(github).use(lint);
314+
315+
file.quiet = true;
316+
317+
processor.process(file, function (err) {
318+
assert(file.messages.length === 0);
319+
done(err);
320+
});
321+
});
322+
});
323+
305324
/*
306325
* Validate inline en- and disabling.
307326
*/

0 commit comments

Comments
 (0)