unified-message-control
Advanced tools
Comparing version 3.0.1 to 3.0.2
134
index.js
@@ -10,21 +10,19 @@ 'use strict' | ||
var settings = options || {} | ||
var name = settings.name | ||
var marker = settings.marker | ||
var test = settings.test | ||
var enable = settings.enable || [] | ||
var disable = settings.disable || [] | ||
var sources = settings.source | ||
var known = settings.known | ||
var reset = settings.reset | ||
var enable = settings.enable || [] | ||
var disable = settings.disable || [] | ||
if (!name) { | ||
throw new Error('Expected `name` in `options`, got `' + name + '`') | ||
if (!settings.name) { | ||
throw new Error('Expected `name` in `options`, got `' + settings.name + '`') | ||
} | ||
if (!marker) { | ||
throw new Error('Expected `marker` in `options`, got `' + marker + '`') | ||
if (!settings.marker) { | ||
throw new Error( | ||
'Expected `marker` in `options`, got `' + settings.marker + '`' | ||
) | ||
} | ||
if (!sources) { | ||
sources = [name] | ||
sources = [settings.name] | ||
} else if (typeof sources === 'string') { | ||
@@ -43,3 +41,3 @@ sources = [sources] | ||
visit(tree, test, visitor) | ||
visit(tree, settings.test, visitor) | ||
@@ -49,13 +47,11 @@ file.messages = file.messages.filter(filter) | ||
function visitor(node, position, parent) { | ||
var mark = marker(node) | ||
var mark = settings.marker(node) | ||
var ruleIds | ||
var ruleId | ||
var verb | ||
var index | ||
var length | ||
var next | ||
var pos | ||
var tail | ||
var index | ||
var ruleId | ||
if (!mark || mark.name !== name) { | ||
if (!mark || mark.name !== settings.name) { | ||
return | ||
@@ -66,5 +62,8 @@ } | ||
verb = ruleIds.shift() | ||
next = parent.children[position + 1] | ||
pos = mark.node.position && mark.node.position.start | ||
tail = next && next.position && next.position.end | ||
tail = | ||
parent.children[position + 1] && | ||
parent.children[position + 1].position && | ||
parent.children[position + 1].position.end | ||
index = -1 | ||
@@ -81,16 +80,5 @@ if (verb !== 'enable' && verb !== 'disable' && verb !== 'ignore') { | ||
length = ruleIds.length | ||
index = -1 | ||
// Apply to all rules. | ||
if (length === 0) { | ||
if (verb === 'ignore') { | ||
toggle(pos, false) | ||
toggle(tail, true) | ||
} else { | ||
toggle(pos, verb === 'enable') | ||
reset = verb !== 'enable' | ||
} | ||
} else { | ||
while (++index < length) { | ||
if (ruleIds.length) { | ||
while (++index < ruleIds.length) { | ||
ruleId = ruleIds[index] | ||
@@ -106,2 +94,8 @@ | ||
} | ||
} else if (verb === 'ignore') { | ||
toggle(pos, false) | ||
toggle(tail, true) | ||
} else { | ||
toggle(pos, verb === 'enable') | ||
reset = verb !== 'enable' | ||
} | ||
@@ -112,4 +106,2 @@ } | ||
var gapIndex = gaps.length | ||
var ruleId = message.ruleId | ||
var ranges = scope[ruleId] | ||
var pos | ||
@@ -142,3 +134,6 @@ | ||
// Check whether allowed by specific and global states. | ||
return check(message, ranges, ruleId) && check(message, globals) | ||
return ( | ||
check(message, scope[message.ruleId], message.ruleId) && | ||
check(message, globals) | ||
) | ||
} | ||
@@ -148,3 +143,3 @@ | ||
function isKnown(ruleId, verb, pos) { | ||
var result = known ? known.indexOf(ruleId) !== -1 : true | ||
var result = settings.known ? settings.known.indexOf(ruleId) !== -1 : true | ||
@@ -166,3 +161,3 @@ if (!result) { | ||
if (ranges && ranges.length !== 0) { | ||
if (ranges && ranges.length) { | ||
return ranges[ranges.length - 1].state | ||
@@ -175,7 +170,3 @@ } | ||
if (reset) { | ||
return enable.indexOf(ruleId) !== -1 | ||
} | ||
return disable.indexOf(ruleId) === -1 | ||
return reset ? enable.indexOf(ruleId) > -1 : disable.indexOf(ruleId) < 0 | ||
} | ||
@@ -208,22 +199,16 @@ | ||
// Check all `ranges` for `message`. | ||
function check(message, ranges, id) { | ||
function check(message, ranges, ruleId) { | ||
// Check the state at the message’s position. | ||
var index = ranges && ranges.length | ||
var length = -1 | ||
var range | ||
while (--index > length) { | ||
range = ranges[index] | ||
/* istanbul ignore if - Generated marker. */ | ||
if (!range.position || !range.position.line || !range.position.column) { | ||
continue | ||
} | ||
while (index--) { | ||
if ( | ||
range.position.line < message.line || | ||
(range.position.line === message.line && | ||
range.position.column <= message.column) | ||
ranges[index].position && | ||
ranges[index].position.line && | ||
ranges[index].position.column && | ||
(ranges[index].position.line < message.line || | ||
(ranges[index].position.line === message.line && | ||
ranges[index].position.column <= message.column)) | ||
) { | ||
return range.state === true | ||
return ranges[index].state === true | ||
} | ||
@@ -234,7 +219,7 @@ } | ||
// initial state. | ||
if (!id) { | ||
if (!ruleId) { | ||
return initial || reset | ||
} | ||
return reset ? enable.indexOf(id) !== -1 : disable.indexOf(id) === -1 | ||
return reset ? enable.indexOf(ruleId) > -1 : disable.indexOf(ruleId) < 0 | ||
} | ||
@@ -248,4 +233,4 @@ } | ||
var offset = 0 | ||
var isGap = false | ||
var gaps = [] | ||
var gap | ||
@@ -276,8 +261,6 @@ // Find all gaps. | ||
function one(node) { | ||
var pos = node.position | ||
update(node.position && node.position.start && node.position.start.offset) | ||
update(pos && pos.start && pos.start.offset) | ||
if (!node.children) { | ||
update(pos && pos.end && pos.end.offset) | ||
update(node.position && node.position.end && node.position.end.offset) | ||
} | ||
@@ -289,16 +272,11 @@ } | ||
if (latest === null || latest === undefined) { | ||
isGap = true | ||
return | ||
} | ||
gap = true | ||
} else if (offset < latest) { | ||
if (gap) { | ||
gaps.push({start: offset, end: latest}) | ||
gap = null | ||
} | ||
if (offset >= latest) { | ||
return | ||
offset = latest | ||
} | ||
if (isGap) { | ||
gaps.push({start: offset, end: latest}) | ||
isGap = false | ||
} | ||
offset = latest | ||
} | ||
@@ -308,3 +286,3 @@ } | ||
function trim(value) { | ||
return value.replace(/^\s*|\s*$/g, '') | ||
return value.replace(/^\s+|\s+$/g, '') | ||
} |
{ | ||
"name": "unified-message-control", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Enable, disable, and ignore messages from unified processors", | ||
@@ -38,21 +38,21 @@ "license": "MIT", | ||
"@types/unist": "^2.0.0", | ||
"browserify": "^16.0.0", | ||
"dtslint": "^3.0.0", | ||
"esmangle": "^1.0.0", | ||
"browserify": "^17.0.0", | ||
"dtslint": "^4.0.0", | ||
"mdast-comment-marker": "^1.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^2.0.0", | ||
"remark": "^11.0.0", | ||
"remark-cli": "^7.0.0", | ||
"remark-preset-wooorm": "^6.0.0", | ||
"remark": "^13.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-toc": "^7.0.0", | ||
"tape": "^4.0.0", | ||
"unified": "^8.0.0", | ||
"tape": "^5.0.0", | ||
"tinyify": "^3.0.0", | ||
"unified": "^9.0.0", | ||
"unist-util-is": "^4.0.0", | ||
"xo": "^0.28.0" | ||
"xo": "^0.36.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write '**/*.{js,ts}' && 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", | ||
"format": "remark . -qfo && prettier . --write && xo --fix", | ||
"build-bundle": "browserify index.js -s unifiedMessageControl -o unified-message-control.js", | ||
"build-mangle": "browserify index.js -s unifiedMessageControl -p tinyify -o unified-message-control.min.js", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
@@ -82,8 +82,10 @@ "test-api": "node test", | ||
"rules": { | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"unicorn/string-content": "off", | ||
"guard-for-in": "off", | ||
"unicorn/explicit-length-check": "off", | ||
"unicorn/no-fn-reference-in-iterator": "off", | ||
"unicorn/prefer-includes": "off", | ||
"guard-for-in": "off" | ||
"unicorn/string-content": "off" | ||
}, | ||
"ignores": [ | ||
"*.ts", | ||
"unified-message-control.js" | ||
@@ -90,0 +92,0 @@ ] |
@@ -185,5 +185,5 @@ # unified-message-control | ||
[build-badge]: https://img.shields.io/travis/unifiedjs/unified-message-control.svg | ||
[build-badge]: https://github.com/unifiedjs/unified-message-control/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/unifiedjs/unified-message-control | ||
[build]: https://github.com/unifiedjs/unified-message-control/actions | ||
@@ -208,5 +208,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/unifiedjs/unified-message-control.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified | ||
[chat]: https://github.com/unifiedjs/unified/discussions | ||
@@ -217,7 +217,7 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[contributing]: https://github.com/unifiedjs/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/unifiedjs/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/unifiedjs/.github/blob/master/support.md | ||
[support]: https://github.com/unifiedjs/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/unifiedjs/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/unifiedjs/.github/blob/HEAD/code-of-conduct.md | ||
@@ -224,0 +224,0 @@ [license]: license |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18465
319