diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1a44efb --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +unified-message-control.js +unified-message-control.min.js diff --git a/index.js b/index.js index 0a97982..704a5b8 100644 --- a/index.js +++ b/index.js @@ -1,107 +1,107 @@ -'use strict'; +'use strict' -var trim = require('trim'); -var location = require('vfile-location'); -var visit = require('unist-util-visit'); +var trim = require('trim') +var location = require('vfile-location') +var visit = require('unist-util-visit') /* Map of allowed verbs. */ var ALLOWED_VERBS = { enable: true, disable: true, ignore: true -}; +} -module.exports = messageControl; +module.exports = messageControl function messageControl(options) { - var name = options && options.name; - var marker = options && options.marker; - var test = options && options.test; - var sources; - var known; - var reset; - var enable; - var disable; + var name = options && options.name + var marker = options && options.marker + var test = options && options.test + var sources + var known + var reset + var enable + var disable if (!name) { - throw new Error('Expected `name` in `options`, got `' + name + '`'); + throw new Error('Expected `name` in `options`, got `' + name + '`') } if (!marker) { - throw new Error('Expected `name` in `options`, got `' + name + '`'); + throw new Error('Expected `name` in `options`, got `' + name + '`') } if (!test) { - throw new Error('Expected `test` in `options`, got `' + test + '`'); + throw new Error('Expected `test` in `options`, got `' + test + '`') } - known = options.known; - reset = options.reset; - enable = options.enable || []; - disable = options.disable || []; - sources = options.source; + known = options.known + reset = options.reset + enable = options.enable || [] + disable = options.disable || [] + sources = options.source if (!sources) { - sources = [name]; + sources = [name] } else if (typeof sources === 'string') { - sources = [sources]; + sources = [sources] } - return transformer; + return transformer function transformer(tree, file) { - var toOffset = location(file).toOffset; - var initial = !reset; - var gaps = detectGaps(tree, file); - var scope = {}; - var globals = []; + var toOffset = location(file).toOffset + var initial = !reset + var gaps = detectGaps(tree, file) + var scope = {} + var globals = [] - visit(tree, test, visitor); + visit(tree, test, visitor) - file.messages = file.messages.filter(filter); + file.messages = file.messages.filter(filter) function visitor(node, position, parent) { - var mark = marker(node); - var ruleIds; - var ruleId; - var verb; - var index; - var length; - var next; - var pos; - var tail; + var mark = marker(node) + var ruleIds + var ruleId + var verb + var index + var length + var next + var pos + var tail if (!mark || mark.name !== options.name) { - return; + return } - ruleIds = mark.attributes.split(/\s/g); - verb = ruleIds.shift(); - next = parent.children[position + 1]; - pos = mark.node.position && mark.node.position.start; - tail = next && next.position && next.position.end; + ruleIds = mark.attributes.split(/\s/g) + verb = ruleIds.shift() + next = parent.children[position + 1] + pos = mark.node.position && mark.node.position.start + tail = next && next.position && next.position.end if (!verb || !ALLOWED_VERBS[verb] === true) { file.fail( 'Unknown keyword `' + verb + '`: expected ' + - '`\'enable\'`, `\'disable\'`, or `\'ignore\'`', + "`'enable'`, `'disable'`, or `'ignore'`", mark.node - ); + ) } - length = ruleIds.length; - index = -1; + length = ruleIds.length + index = -1 while (++index < length) { - ruleId = ruleIds[index]; + ruleId = ruleIds[index] if (isKnown(ruleId, verb, mark.node)) { - toggle(pos, verb === 'enable', ruleId); + toggle(pos, verb === 'enable', ruleId) if (verb === 'ignore') { - toggle(tail, true, ruleId); + toggle(tail, true, ruleId) } } } @@ -109,101 +109,101 @@ function messageControl(options) { /* Apply to all rules. */ if (!length) { if (verb === 'ignore') { - toggle(pos, false); - toggle(tail, true); + toggle(pos, false) + toggle(tail, true) } else { - toggle(pos, verb === 'enable'); - reset = verb !== 'enable'; + toggle(pos, verb === 'enable') + reset = verb !== 'enable' } } } function filter(message) { - var gapIndex = gaps.length; - var ruleId = message.ruleId; - var ranges = scope[ruleId]; - var pos; + var gapIndex = gaps.length + var ruleId = message.ruleId + var ranges = scope[ruleId] + var pos /* Keep messages from a different source. */ if (!message.source || sources.indexOf(message.source) === -1) { - return true; + return true } /* We only ignore messages if they‘re disabled, * *not* when they’re not in the document. */ if (!message.line) { - message.line = 1; + message.line = 1 } if (!message.column) { - message.column = 1; + message.column = 1 } /* Check whether the warning is inside a gap. */ - pos = toOffset(message); + pos = toOffset(message) while (gapIndex--) { if (gaps[gapIndex].start <= pos && gaps[gapIndex].end > pos) { - return false; + return false } } /* Check whether allowed by specific and global states. */ - return check(message, ranges, ruleId) && check(message, globals); + return check(message, ranges, ruleId) && check(message, globals) } /* Helper to check (and possibly warn) if a ruleId is unknown. */ function isKnown(ruleId, verb, pos) { - var result = known ? known.indexOf(ruleId) !== -1 : true; + var result = known ? known.indexOf(ruleId) !== -1 : true if (!result) { - file.warn('Unknown rule: cannot ' + verb + ' `\'' + ruleId + '\'`', pos); + file.warn('Unknown rule: cannot ' + verb + " `'" + ruleId + "'`", pos) } - return result; + return result } /* Get the latest state of a rule. When without `ruleId`, gets global state. */ function getState(ruleId) { - var ranges = ruleId ? scope[ruleId] : globals; + var ranges = ruleId ? scope[ruleId] : globals if (ranges && ranges.length !== 0) { - return ranges[ranges.length - 1].state; + return ranges[ranges.length - 1].state } if (!ruleId) { - return !reset; + return !reset } if (reset) { - return enable.indexOf(ruleId) !== -1; + return enable.indexOf(ruleId) !== -1 } - return disable.indexOf(ruleId) === -1; + return disable.indexOf(ruleId) === -1 } /* Handle a rule. */ function toggle(pos, state, ruleId) { - var markers = ruleId ? scope[ruleId] : globals; - var currentState; - var previousState; + var markers = ruleId ? scope[ruleId] : globals + var currentState + var previousState if (!markers) { - markers = []; - scope[ruleId] = markers; + markers = [] + scope[ruleId] = markers } - previousState = getState(ruleId); - currentState = state; + previousState = getState(ruleId) + currentState = state if (currentState !== previousState) { - markers.push({state: currentState, position: pos}); + markers.push({state: currentState, position: pos}) } /* Toggle all known rules. */ if (!ruleId) { for (ruleId in scope) { - toggle(pos, state, ruleId); + toggle(pos, state, ruleId) } } } @@ -211,16 +211,16 @@ function messageControl(options) { /* Check all `ranges` for `message`. */ function check(message, ranges, id) { /* Check the state at the message's position. */ - var index = ranges && ranges.length; - var length = -1; - var range; + var index = ranges && ranges.length + var length = -1 + var range while (--index > length) { - range = ranges[index]; + range = ranges[index] /* istanbul ignore if - generated marker. */ if (!range.position || !range.position.line || !range.position.column) { - continue; + continue } if ( @@ -228,30 +228,30 @@ function messageControl(options) { (range.position.line === message.line && range.position.column < message.column) ) { - return range.state === true; + return range.state === true } } /* The first marker ocurred after the first * message, so we check the initial state. */ if (!id) { - return initial || reset; + return initial || reset } - return reset ? enable.indexOf(id) !== -1 : disable.indexOf(id) === -1; + return reset ? enable.indexOf(id) !== -1 : disable.indexOf(id) === -1 } } } /* Detect gaps in `ast`. */ function detectGaps(tree, file) { - var lastNode = tree.children[tree.children.length - 1]; - var offset = 0; - var isGap = false; - var gaps = []; + var lastNode = tree.children[tree.children.length - 1] + var offset = 0 + var isGap = false + var gaps = [] /* Find all gaps. */ - visit(tree, one); + visit(tree, one) /* Get the end of the document. * This detects if the last node was the last node. @@ -264,41 +264,41 @@ function detectGaps(tree, file) { offset === lastNode.position.end.offset && trim(file.toString().slice(offset)) !== '' ) { - update(); + update() update( tree && tree.position && tree.position.end && tree.position.end.offset - 1 - ); + ) } - return gaps; + return gaps function one(node) { - var pos = node.position; + var pos = node.position - update(pos && pos.start && pos.start.offset); + update(pos && pos.start && pos.start.offset) if (!node.children) { - update(pos && pos.end && pos.end.offset); + update(pos && pos.end && pos.end.offset) } } /* Detect a new position. */ function update(latest) { if (latest === null || latest === undefined) { - isGap = true; - return; + isGap = true + return } if (offset >= latest) { - return; + return } if (isGap) { - gaps.push({start: offset, end: latest}); - isGap = false; + gaps.push({start: offset, end: latest}) + isGap = false } - offset = latest; + offset = latest } } diff --git a/package.json b/package.json index 85a9d1a..b2883eb 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "esmangle": "^1.0.0", "mdast-comment-marker": "^1.0.2", "nyc": "^11.0.0", + "prettier": "^1.12.1", "remark": "^9.0.0", "remark-cli": "^5.0.0", "remark-preset-wooorm": "^4.0.0", @@ -38,17 +39,24 @@ "xo": "^0.21.0" }, "scripts": { - "build-md": "remark . -qfo", + "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", "build-bundle": "browserify index.js --bare -s unifiedMessageControl > unified-message-control.js", "build-mangle": "esmangle unified-message-control.js > unified-message-control.min.js", - "build": "npm run build-md && npm run build-bundle && npm run build-mangle", - "lint": "xo", - "test-api": "node test.js", + "build": "npm run build-bundle && npm run build-mangle", + "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run build && npm run lint && npm run test-coverage" + "test": "npm run format && npm run build && npm run test-coverage" + }, + "prettier": { + "tabWidth": 2, + "useTabs": false, + "singleQuote": true, + "bracketSpacing": false, + "semi": false, + "trailingComma": "none" }, "xo": { - "space": true, + "prettier": true, "esnext": false, "rules": { "no-var": "off", diff --git a/readme.md b/readme.md index b6dc9bf..598d2b9 100644 --- a/readme.md +++ b/readme.md @@ -23,23 +23,23 @@ Say we have the following file, `example.md`: And our script, `example.js`, looks as follows: ```javascript -var vfile = require('to-vfile'); -var report = require('vfile-reporter'); -var remark = require('remark'); -var control = require('unified-message-control'); -var mdastMarker = require('mdast-comment-marker'); +var vfile = require('to-vfile') +var report = require('vfile-reporter') +var remark = require('remark') +var control = require('unified-message-control') +var mdastMarker = require('mdast-comment-marker') remark() .use(warn) .use(control, {name: 'foo', marker: mdastMarker, test: 'html'}) - .process(vfile.readSync('example.md'), function (err, file) { - console.error(report(err || file)); - }); + .process(vfile.readSync('example.md'), function(err, file) { + console.error(report(err || file)) + }) function warn() { - return function (tree, file) { - file.message('Whoops!', tree.children[1], 'foo:thing'); - }; + return function(tree, file) { + file.message('Whoops!', tree.children[1], 'foo:thing') + } } ``` diff --git a/test.js b/test.js index 5ec216f..2de5dc4 100644 --- a/test.js +++ b/test.js @@ -1,86 +1,82 @@ -'use strict'; +'use strict' -var test = require('tape'); -var remark = require('remark'); -var toc = require('remark-toc'); -var mdastMarker = require('mdast-comment-marker'); -var control = require('.'); +var test = require('tape') +var remark = require('remark') +var toc = require('remark-toc') +var mdastMarker = require('mdast-comment-marker') +var control = require('.') -test('control()', function (t) { - t.throws(function () { +test('control()', function(t) { + t.throws(function() { remark() .use(control) - .freeze(); - }, /Expected `name` in `options`, got `undefined`/); + .freeze() + }, /Expected `name` in `options`, got `undefined`/) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); - transformer(tree, file); - }; + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') + transformer(tree, file) + } }) .process( ['', '', 'This is a paragraph.'].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') - t.deepEqual( - file.messages.map(String), - [], - 'should “disable” a message' - ); + t.deepEqual(file.messages.map(String), [], 'should “disable” a message') } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( ['', '', 'This is a paragraph.'].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), [], 'should “disable” all message without `ruleId`s' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', reset: true, marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[0], 'foo:bar'); - file.message('Error', tree.children[2], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[0], 'foo:bar') + file.message('Error', tree.children[2], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -90,59 +86,59 @@ test('control()', function (t) { '', 'This is a paragraph.' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['5:1-5:21: Error'], 'should support `reset`' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', reset: true, marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( ['', '', 'This is a paragraph.'].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['3:1-3:21: Error'], 'should enable with a marker, when `reset`' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); - file.message('Error', tree.children[3], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') + file.message('Error', tree.children[3], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -154,31 +150,31 @@ test('control()', function (t) { '', 'This is a paragraph.' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['7:1-7:21: Error'], 'should enable a message' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); - file.message('Error', tree.children[3], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') + file.message('Error', tree.children[3], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -190,31 +186,31 @@ test('control()', function (t) { '', 'This is a paragraph.' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['7:1-7:21: Error'], 'should enable all message without `ruleId`s' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); - file.message('Error', tree.children[2], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') + file.message('Error', tree.children[2], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -224,31 +220,31 @@ test('control()', function (t) { '', 'This is a paragraph.' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['5:1-5:21: Error'], 'should ignore a message' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); - file.message('Error', tree.children[2], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') + file.message('Error', tree.children[2], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -258,73 +254,73 @@ test('control()', function (t) { '', 'This is a paragraph.' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['5:1-5:21: Error'], 'should ignore all message without `ruleId`s' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); - file.message('Error', tree.children[1], 'foo:baz'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') + file.message('Error', tree.children[1], 'foo:baz') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( ['', '', 'This is a paragraph.'].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), [], 'should ignore multiple rules' - ); + ) } - ); + ) remark() - .use(function () { - return control({name: 'foo', marker: mdastMarker, test: 'html'}); + .use(function() { + return control({name: 'foo', marker: mdastMarker, test: 'html'}) }) - .process('', function (err) { + .process('', function(err) { t.equal( String(err), '1:1-1:16: Unknown keyword `test`: ' + - 'expected `\'enable\'`, `\'disable\'`, or `\'ignore\'`', + "expected `'enable'`, `'disable'`, or `'ignore'`", 'should fail on invalid verbs' - ); - }); + ) + }) remark() .use(toc) - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', {line: 5, column: 1}, 'foo:bar'); - file.message('Error', {line: 7, column: 1}, 'foo:bar'); + return function(tree, file) { + file.message('Error', {line: 5, column: 1}, 'foo:bar') + file.message('Error', {line: 7, column: 1}, 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -336,34 +332,34 @@ test('control()', function (t) { '', '## Another header' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['7:1: Error'], 'should ignore gaps' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', {line: 5, column: 1}, 'foo:bar'); - file.message('Error', {line: 5, column: 1}, 'foo:bar'); + return function(tree, file) { + file.message('Error', {line: 5, column: 1}, 'foo:bar') + file.message('Error', {line: 5, column: 1}, 'foo:bar') /* Remove list. */ - tree.children.pop(); + tree.children.pop() - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -373,99 +369,99 @@ test('control()', function (t) { '', '* [This is removed](#this-is-removed)' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') - t.deepEqual(file.messages.map(String), [], 'should ignore final gaps'); + t.deepEqual(file.messages.map(String), [], 'should ignore final gaps') } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', 'foo:bar'); + return function(tree, file) { + file.message('Error', 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) - .process('', function (err, file) { - t.ifError(err, 'should not fail'); + .process('', function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['1:1: Error'], 'should support empty documents' - ); - }); + ) + }) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.position.end, 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.position.end, 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) - .process(['# README', ''].join('\n'), function (err, file) { - t.ifError(err, 'should not fail'); + .process(['# README', ''].join('\n'), function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['2:1: Error'], 'should message at the end of the document' - ); - }); + ) + }) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1].position.end, 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1].position.end, 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) - .process(['# README', '', '* List'].join('\n'), function (err, file) { - t.ifError(err, 'should not fail'); + .process(['# README', '', '* List'].join('\n'), function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['3:9: Error'], 'should message at the end of the document' - ); - }); + ) + }) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'foo:bar'); - file.message('Error', tree.children[3], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'foo:bar') + file.message('Error', tree.children[3], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -477,119 +473,119 @@ test('control()', function (t) { '', 'This is a paragraph.' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), [], 'should ignore double disables' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', 'foo:bar'); + return function(tree, file) { + file.message('Error', 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) - .process(['Foo'].join('\n'), function (err, file) { - t.ifError(err, 'should not fail'); + .process(['Foo'].join('\n'), function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['1:1: Error'], 'should not ignore messages without location information' - ); - }); + ) + }) remark() - .use(function () { - return control({name: 'foo', marker: mdastMarker, test: 'html'}); + .use(function() { + return control({name: 'foo', marker: mdastMarker, test: 'html'}) }) - .process(['', '', ''].join('\n'), function ( + .process(['', '', ''].join('\n'), function( err, file ) { - t.ifError(err, 'should not fail'); + t.ifError(err, 'should not fail') - t.deepEqual(file.messages.map(String), [], 'should ignore non-markers'); - }); + t.deepEqual(file.messages.map(String), [], 'should ignore non-markers') + }) remark() - .use(function () { + .use(function() { return control({ name: 'foo', known: ['known'], marker: mdastMarker, test: 'html' - }); + }) }) .process( ['', '', ''].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), - ['3:1-3:26: Unknown rule: cannot ignore `\'unknown\'`'], + ["3:1-3:26: Unknown rule: cannot ignore `'unknown'`"], 'should support a list of `known` values, and warn on unknowns' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', source: 'baz', marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'baz:bar'); + return function(tree, file) { + file.message('Error', tree.children[1], 'baz:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) - .process(['', '', 'Foo'].join('\n'), function ( + .process(['', '', 'Foo'].join('\n'), function( err, file ) { - t.ifError(err, 'should not fail'); + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), [], 'should ignore by `source`, when given as a string' - ); - }); + ) + }) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'alpha', source: ['bravo', 'charlie'], marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[1], 'bravo:delta'); - file.message('Error', tree.children[3], 'charlie:echo'); + return function(tree, file) { + file.message('Error', tree.children[1], 'bravo:delta') + file.message('Error', tree.children[3], 'charlie:echo') - transformer(tree, file); - }; + transformer(tree, file) + } }) .process( [ @@ -601,67 +597,67 @@ test('control()', function (t) { '', 'Golf' ].join('\n'), - function (err, file) { - t.ifError(err, 'should not fail'); + function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), [], 'should ignore by `source`, when given as an array' - ); + ) } - ); + ) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', disable: ['bar'], marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[0], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[0], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) - .process(['This is a paragraph.'].join('\n'), function (err, file) { - t.ifError(err, 'should not fail'); + .process(['This is a paragraph.'].join('\n'), function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), [], 'should support initial `disable`s' - ); - }); + ) + }) remark() - .use(function () { + .use(function() { var transformer = control({ name: 'foo', reset: true, enable: ['bar'], marker: mdastMarker, test: 'html' - }); + }) - return function (tree, file) { - file.message('Error', tree.children[0], 'foo:bar'); + return function(tree, file) { + file.message('Error', tree.children[0], 'foo:bar') - transformer(tree, file); - }; + transformer(tree, file) + } }) - .process(['This is a paragraph.'].join('\n'), function (err, file) { - t.ifError(err, 'should not fail'); + .process(['This is a paragraph.'].join('\n'), function(err, file) { + t.ifError(err, 'should not fail') t.deepEqual( file.messages.map(String), ['1:1-1:21: Error'], 'should support initial `enable`s' - ); - }); + ) + }) - t.end(); -}); + t.end() +})