mirror of
https://github.com/remarkjs/remark-lint.git
synced 2024-09-11 19:57:15 +03:00
Fix literal URL and blank lines detection
This commit is contained in:
parent
a81e82ba52
commit
b6309f0c09
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
5
test/fixtures/remark-github.md
vendored
Normal file
5
test/fixtures/remark-github.md
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
A user @wooorm.
|
||||
|
||||
A commit 1234567.
|
||||
|
||||
And an issue GH-1.
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user