Skip to content

Commit

Permalink
Update vfile, @types/unist, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 22, 2023
1 parent 2fe546e commit d487864
Show file tree
Hide file tree
Showing 3 changed files with 474 additions and 379 deletions.
15 changes: 9 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ import {visit} from 'unist-util-visit'
const own = {}.hasOwnProperty

/**
* @type {import('unified').Plugin<[Options]>}
* @returns {(tree: Node, file: VFile) => void}
* @param {Options} options
* @returns {(tree: Node, file: VFile) => undefined}
*/
export default function messageControl(options) {
if (!options || typeof options !== 'object' || !options.name) {
Expand Down Expand Up @@ -106,6 +106,7 @@ export default function messageControl(options) {
/**
* @param {Node} tree
* @param {VFile} file
* @returns {undefined}
*/
function transformer(tree, file) {
const toOffset = location(file).toOffset
Expand All @@ -122,8 +123,8 @@ export default function messageControl(options) {

/**
* @param {Node} node
* @param {number|null} position
* @param {Parent|null} parent
* @param {number|undefined} position
* @param {Parent|undefined} parent
*/
function visitor(node, position, parent) {
/** @type {Marker|null} */
Expand All @@ -136,7 +137,7 @@ export default function messageControl(options) {
const ruleIds = mark.attributes.split(/\s/g)
const point = mark.node.position && mark.node.position.start
const next =
(parent && position !== null && parent.children[position + 1]) ||
(parent && position !== undefined && parent.children[position + 1]) ||
undefined
const tail = (next && next.position && next.position.end) || undefined
let index = -1
Expand Down Expand Up @@ -200,9 +201,11 @@ export default function messageControl(options) {
}

// Check whether the warning is inside a gap.
// @ts-expect-error: we just normalized `null` to `number`s.
const offset = toOffset(message)

// To do: check.
if (offset === undefined) return false

while (gapIndex--) {
if (gaps[gapIndex][0] <= offset && gaps[gapIndex][1] > offset) {
return false
Expand Down
36 changes: 20 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,33 @@
"index.js"
],
"dependencies": {
"@types/unist": "^2.0.0",
"unist-util-is": "^5.0.0",
"unist-util-visit": "^4.0.0",
"vfile": "^5.0.0",
"vfile-location": "^4.0.0",
"vfile-message": "^3.0.0"
"@types/unist": "^3.0.0",
"unist-util-is": "^6.0.0",
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.0",
"vfile-location": "^5.0.0",
"vfile-message": "^4.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"mdast-comment-marker": "^2.0.0",
"prettier": "^2.0.0",
"@types/mdast": "^4.0.0",
"@types/tape": "^5.0.0",
"c8": "^8.0.0",
"mdast-comment-marker": "^3.0.0",
"prettier": "^3.0.0",
"remark": "^14.0.0",
"remark-cli": "^10.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"remark-toc": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unified": "^10.0.0",
"xo": "^0.50.0"
"typescript": "^5.0.0",
"unified": "^11.0.0",
"xo": "^0.56.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test.js",
"test": "npm run build && npm run format && npm run test-coverage"
Expand All @@ -71,7 +72,10 @@
"trailingComma": "none"
},
"xo": {
"prettier": true
"prettier": true,
"rules": {
"unicorn/prefer-at": "off"
}
},
"remarkConfig": {
"plugins": [
Expand Down
Loading

0 comments on commit d487864

Please sign in to comment.