Replace remark-range with vfile-location

This commit is contained in:
Titus Wormer 2016-02-14 11:15:39 +01:00
parent e55fb3af31
commit aa1863f75c
8 changed files with 31 additions and 16 deletions

View File

@ -23,7 +23,6 @@ var SOURCE = 'remark-lint';
var decamelize = require('decamelize');
var sort = require('vfile-sort');
var range = require('remark-range');
var control = require('remark-message-control');
var internals = require('./rules');
var npmPrefix = require('npm-prefix')();
@ -256,12 +255,6 @@ function lint(remark, options) {
var setting;
var id;
/*
* Ensure offset information is added.
*/
remark.use(range);
/*
* Add each rule as a seperate plugin.
*/

View File

@ -52,6 +52,7 @@
* Dependencies.
*/
var vfileLocation = require('vfile-location');
var visit = require('unist-util-visit');
var position = require('mdast-util-position');
@ -85,6 +86,7 @@ var UNCHECKED = {
*/
function checkboxCharacterStyle(ast, file, preferred, done) {
var contents = file.toString();
var location = vfileLocation(file);
if (preferred === 'consistent' || typeof preferred !== 'object') {
preferred = {};
@ -169,8 +171,8 @@ function checkboxCharacterStyle(ast, file, preferred, done) {
type.charAt(0).toUpperCase() + type.slice(1) +
' checkboxes should use `' + style + '` as a marker',
{
'start': file.offsetToPosition(stop - 1),
'end': file.offsetToPosition(stop)
'start': location.toPosition(stop - 1),
'end': location.toPosition(stop)
}
);
}

View File

@ -27,6 +27,7 @@
* Dependencies.
*/
var vfileLocation = require('vfile-location');
var visit = require('unist-util-visit');
var position = require('mdast-util-position');
@ -47,6 +48,7 @@ var end = position.end;
*/
function checkboxContentIndent(ast, file, preferred, done) {
var contents = file.toString();
var location = vfileLocation(file);
visit(ast, 'listItem', function (node) {
var initial;
@ -85,8 +87,8 @@ function checkboxContentIndent(ast, file, preferred, done) {
}
file.warn('Checkboxes should be followed by a single character', {
'start': file.offsetToPosition(final - value.length + 1),
'end': file.offsetToPosition(final)
'start': location.toPosition(final - value.length + 1),
'end': location.toPosition(final)
});
});

View File

@ -39,6 +39,7 @@
* Dependencies.
*/
var vfileLocation = require('vfile-location');
var visit = require('unist-util-visit');
var position = require('mdast-util-position');
@ -70,6 +71,7 @@ var end = position.end;
*/
function linkTitleStyle(ast, file, preferred, done) {
var contents = file.toString();
var location = vfileLocation(file);
preferred = typeof preferred !== 'string' || preferred === 'consistent' ? null : preferred;
@ -123,7 +125,7 @@ function linkTitleStyle(ast, file, preferred, done) {
if (!preferred) {
preferred = character;
} else if (preferred !== character) {
pos = file.offsetToPosition(last + 1);
pos = location.toPosition(last + 1);
file.warn('Titles should use `' + (preferred === ')' ? '()' : preferred) + '` as a quote', pos);
}
}

View File

@ -25,6 +25,7 @@
* Dependencies.
*/
var vfileLocation = require('vfile-location');
var visit = require('unist-util-visit');
var position = require('mdast-util-position');
@ -39,6 +40,7 @@ var position = require('mdast-util-position');
*/
function noBlockquoteWithoutCaret(ast, file, preferred, done) {
var contents = file.toString();
var location = vfileLocation(file);
var last = contents.length;
visit(ast, 'blockquote', function (node) {
@ -52,7 +54,7 @@ function noBlockquoteWithoutCaret(ast, file, preferred, done) {
indent.forEach(function (column, n) {
var character;
var line = start + n + 1;
var offset = file.positionToOffset({
var offset = location.toOffset({
'line': line,
'column': column
}) - 1;

View File

@ -22,6 +22,12 @@
/* eslint-env commonjs */
/*
* Dependencies.
*/
var vfileLocation = require('vfile-location');
/**
* Warn when hard-tabs instead of spaces are used.
*
@ -32,12 +38,13 @@
*/
function noTabs(ast, file, preferred, done) {
var content = file.toString();
var location = vfileLocation(file);
var index = -1;
var length = content.length;
while (++index < length) {
if (content.charAt(index) === '\t') {
file.warn('Use spaces instead of hard-tabs', file.offsetToPosition(index));
file.warn('Use spaces instead of hard-tabs', location.toPosition(index));
}
}

View File

@ -26,8 +26,8 @@
"npm-prefix": "^1.1.1",
"plur": "^2.0.0",
"remark-message-control": "^1.0.1",
"remark-range": "^2.0.0",
"unist-util-visit": "^1.0.0",
"vfile-location": "^2.0.0",
"vfile-sort": "^1.0.0"
},
"files": [

View File

@ -17,6 +17,12 @@
/* eslint-env commonjs */
/*
* Dependencies.
*/
var vfileLocation = require('vfile-location');
/**
* Warn when `lorem` is used in a document.
*
@ -28,9 +34,10 @@
function noLorem(ast, file, preferred, done) {
var content = file.toString();
var expression = /\blorem\b/gi;
var location = vfileLocation(file);
while (expression.exec(content)) {
file.warn('Do not use lorem', file.offsetToPosition(expression.lastIndex));
file.warn('Do not use lorem', location.toPosition(expression.lastIndex));
}
done();