Skip to content

Commit a86f694

Browse files
Merge pull request #1 from ChristianMurphy/refactor/unified-message-control
refactor: unified-message-control
2 parents 525dfea + 91e5338 commit a86f694

File tree

5 files changed

+659
-516
lines changed

5 files changed

+659
-516
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
.nyc_output/
44
coverage/
55
node_modules/
6-
remark-message-control.js
7-
remark-message-control.min.js
6+
unified-message-control.js
7+
unified-message-control.min.js

index.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
var trim = require('trim');
44
var location = require('vfile-location');
55
var visit = require('unist-util-visit');
6-
var marker = require('mdast-comment-marker');
76

87
/* Map of allowed verbs. */
98
var ALLOWED_VERBS = {
@@ -16,6 +15,8 @@ module.exports = messageControl;
1615

1716
function messageControl(options) {
1817
var name = options && options.name;
18+
var marker = options && options.marker;
19+
var test = options && options.test;
1920
var sources;
2021
var known;
2122
var reset;
@@ -26,6 +27,14 @@ function messageControl(options) {
2627
throw new Error('Expected `name` in `options`, got `' + name + '`');
2728
}
2829

30+
if (!marker) {
31+
throw new Error('Expected `name` in `options`, got `' + name + '`');
32+
}
33+
34+
if (!test) {
35+
throw new Error('Expected `test` in `options`, got `' + test + '`');
36+
}
37+
2938
known = options.known;
3039
reset = options.reset;
3140
enable = options.enable || [];
@@ -47,7 +56,7 @@ function messageControl(options) {
4756
var scope = {};
4857
var globals = [];
4958

50-
visit(tree, 'html', visitor);
59+
visit(tree, test, visitor);
5160

5261
file.messages = file.messages.filter(filter);
5362

@@ -74,8 +83,10 @@ function messageControl(options) {
7483

7584
if (!verb || !ALLOWED_VERBS[verb] === true) {
7685
file.fail(
77-
'Unknown keyword `' + verb + '`: expected ' +
78-
'`\'enable\'`, `\'disable\'`, or `\'ignore\'`',
86+
'Unknown keyword `' +
87+
verb +
88+
'`: expected ' +
89+
'`\'enable\'`, `\'disable\'`, or `\'ignore\'`',
7990
mark.node
8091
);
8192
}
@@ -132,10 +143,7 @@ function messageControl(options) {
132143
pos = toOffset(message);
133144

134145
while (gapIndex--) {
135-
if (
136-
gaps[gapIndex].start <= pos &&
137-
gaps[gapIndex].end > pos
138-
) {
146+
if (gaps[gapIndex].start <= pos && gaps[gapIndex].end > pos) {
139147
return false;
140148
}
141149
}
@@ -217,7 +225,8 @@ function messageControl(options) {
217225

218226
if (
219227
range.position.line < message.line ||
220-
(range.position.line === message.line && range.position.column < message.column)
228+
(range.position.line === message.line &&
229+
range.position.column < message.column)
221230
) {
222231
return range.state === true;
223232
}
@@ -258,10 +267,7 @@ function detectGaps(tree, file) {
258267
update();
259268

260269
update(
261-
tree &&
262-
tree.position &&
263-
tree.position.end &&
264-
tree.position.end.offset - 1
270+
tree && tree.position && tree.position.end && tree.position.end.offset - 1
265271
);
266272
}
267273

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
2-
"name": "remark-message-control",
3-
"version": "4.0.2",
4-
"description": "Enable, disable, and ignore messages with remark",
2+
"name": "unified-message-control",
3+
"version": "0.0.0",
4+
"description": "Enable, disable, and ignore messages from unified processors",
55
"license": "MIT",
66
"keywords": [
7-
"remark",
7+
"unified",
88
"comment",
99
"message",
1010
"marker",
@@ -20,14 +20,14 @@
2020
"index.js"
2121
],
2222
"dependencies": {
23-
"mdast-comment-marker": "^1.0.0",
2423
"trim": "0.0.1",
2524
"unist-util-visit": "^1.0.0",
2625
"vfile-location": "^2.0.0"
2726
},
2827
"devDependencies": {
2928
"browserify": "^14.0.0",
3029
"esmangle": "^1.0.0",
30+
"mdast-comment-marker": "^1.0.2",
3131
"nyc": "^11.0.0",
3232
"remark": "^8.0.0",
3333
"remark-cli": "^4.0.0",
@@ -38,8 +38,8 @@
3838
},
3939
"scripts": {
4040
"build-md": "remark . -qfo",
41-
"build-bundle": "browserify index.js --bare -s remarkMessageControl > remark-message-control.js",
42-
"build-mangle": "esmangle remark-message-control.js > remark-message-control.min.js",
41+
"build-bundle": "browserify index.js --bare -s unifiedMessageControl > unified-message-control.js",
42+
"build-mangle": "esmangle unified-message-control.js > unified-message-control.min.js",
4343
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
4444
"lint": "xo",
4545
"test-api": "node test.js",

readme.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# remark-message-control [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
1+
# unified-message-control [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
22

33
Enable, disable, and ignore messages with [**remark**][remark].
44

@@ -163,17 +163,17 @@ repository, organisation, or community you agree to abide by its terms.
163163

164164
<!-- Definitions -->
165165

166-
[build-badge]: https://img.shields.io/travis/remarkjs/remark-message-control.svg
166+
[build-badge]: https://img.shields.io/travis/unifiedjs/unified-message-control.svg
167167

168-
[build-status]: https://travis-ci.org/remarkjs/remark-message-control
168+
[build-status]: https://travis-ci.org/unifiedjs/unified-message-control
169169

170170
[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-message-control.svg
171171

172172
[coverage-status]: https://codecov.io/github/remarkjs/remark-message-control
173173

174-
[chat-badge]: https://img.shields.io/gitter/room/remarkjs/Lobby.svg
174+
[chat-badge]: https://img.shields.io/gitter/room/unifiedjs/Lobby.svg
175175

176-
[chat]: https://gitter.im/remarkjs/Lobby
176+
[chat]: https://gitter.im/unifiedjs/Lobby
177177

178178
[license]: LICENSE
179179

0 commit comments

Comments
 (0)