Skip to content

Commit

Permalink
Fix literal URL and blank lines detection
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jan 24, 2016
1 parent a81e82b commit b6309f0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/rules/no-consecutive-blank-lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
});

Expand Down
14 changes: 13 additions & 1 deletion lib/rules/no-literal-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

var visit = require('unist-util-visit');
var toString = require('mdast-util-to-string');
var position = require('mdast-util-position');

/*
Expand All @@ -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.
*
Expand All @@ -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);
}
});
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/remark-github.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A user @wooorm.

A commit 1234567.

And an issue GH-1.
19 changes: 19 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit b6309f0

Please sign in to comment.