Add en- and disabling multiple rules in one comment

Why:

*   Disabling more than one rule currently needs multiple HTML
    comments. Those are often added, after each other. But markdown
    needs blank lines between HTML to distinguish it, thus when
    lint-comments were adjacent without black-lines they were
    ignored.

How:

*    Space-delimit the ruleId’s in `lint disable` and `lint-enable`
     comments, and toggle each ruleId.
This commit is contained in:
Titus Wormer 2015-08-31 14:26:50 +02:00
parent c1136a1d10
commit 29976d097c
5 changed files with 84 additions and 31 deletions

View File

@ -267,29 +267,19 @@ function lint(mdast, options) {
}
/**
* Handle a new-found marker.
* Handle a rule.
*
* @param {VFile} file - Virtual file.
* @param {Object} marker - Marker context.
* @param {Object} parser - Parser instance.
* @param {string} type - Type to toggle to.
* @param {*} ruleId - Rule to toggle.
*/
function onparse(marker, parser) {
var file = parser.file;
function toggle(file, marker, type, ruleId) {
var scope = file.namespace('mdast-lint');
var attributes = marker.attributes.split(' ');
var type = attributes[0];
var ruleId = attributes[1];
var markers;
var currentState;
var previousState;
store(file);
if (type !== 'disable' && type !== 'enable') {
file.fail('Unknown lint keyword `' + type + '`: use either `\'enable\'` or `\'disable\'`', marker.node);
return;
}
if (!(ruleId in rules)) {
file.fail('Unknown rule: cannot ' + type + ' `\'' + ruleId + '\'`', marker.node);
@ -309,6 +299,33 @@ function lint(mdast, options) {
}
}
/**
* Handle a new-found marker.
*
* @param {Object} marker - Marker context.
* @param {Object} parser - Parser instance.
*/
function onparse(marker, parser) {
var file = parser.file;
var attributes = marker.attributes.split(' ');
var type = attributes[0];
var ids = attributes.slice(1);
var length = ids.length;
var index = -1;
if (type !== 'disable' && type !== 'enable') {
file.fail('Unknown lint keyword `' + type + '`: use either `\'enable\'` or `\'disable\'`', marker.node);
return;
}
store(file);
while (++index < length) {
toggle(file, marker, type, ids[index]);
}
}
mdast.use(zone({
'name': 'lint',
'onparse': onparse

View File

@ -420,29 +420,19 @@ function lint(mdast, options) {
}
/**
* Handle a new-found marker.
* Handle a rule.
*
* @param {VFile} file - Virtual file.
* @param {Object} marker - Marker context.
* @param {Object} parser - Parser instance.
* @param {string} type - Type to toggle to.
* @param {*} ruleId - Rule to toggle.
*/
function onparse(marker, parser) {
var file = parser.file;
function toggle(file, marker, type, ruleId) {
var scope = file.namespace('mdast-lint');
var attributes = marker.attributes.split(' ');
var type = attributes[0];
var ruleId = attributes[1];
var markers;
var currentState;
var previousState;
store(file);
if (type !== 'disable' && type !== 'enable') {
file.fail('Unknown lint keyword `' + type + '`: use either `\'enable\'` or `\'disable\'`', marker.node);
return;
}
if (!(ruleId in rules)) {
file.fail('Unknown rule: cannot ' + type + ' `\'' + ruleId + '\'`', marker.node);
@ -462,6 +452,33 @@ function lint(mdast, options) {
}
}
/**
* Handle a new-found marker.
*
* @param {Object} marker - Marker context.
* @param {Object} parser - Parser instance.
*/
function onparse(marker, parser) {
var file = parser.file;
var attributes = marker.attributes.split(' ');
var type = attributes[0];
var ids = attributes.slice(1);
var length = ids.length;
var index = -1;
if (type !== 'disable' && type !== 'enable') {
file.fail('Unknown lint keyword `' + type + '`: use either `\'enable\'` or `\'disable\'`', marker.node);
return;
}
store(file);
while (++index < length) {
toggle(file, marker, type, ids[index]);
}
}
mdast.use(zone({
'name': 'lint',
'onparse': onparse

2
mdast-lint.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,13 @@
# Hello
<!--lint disable no-duplicate-headings maximum-line-length-->
## Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello.
<!--lint enable no-duplicate-headings-->
### Hello
Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello.

View File

@ -309,6 +309,12 @@ describe('Comments', function () {
});
});
describe('Disable multiple rules at once', function () {
assertFile('comments-disable-multiple.md', [
'comments-disable-multiple.md:11:1-11:10: Do not use headings with similar content (5:1)'
], null, {});
});
describe('Inline comments', function () {
assertFile('comments-inline.md', [
'comments-inline.md:1:32-1:38: Do not use HTML in markdown',