diff --git a/index.js b/index.js index 2051fa0..232a19d 100644 --- a/index.js +++ b/index.js @@ -72,7 +72,7 @@ export default function retextSpell(options = {}) { normalizeApostrophes, personal } = options - /** @type {Array<[Root, VFile, Config, (error?: Error|null|undefined) => void]>} */ + /** @type {Array<[Root, VFile, Config, import('unified').TransformCallback]>} */ const queue = [] /** @type {Error|null|undefined} */ let loadError @@ -128,7 +128,8 @@ export default function retextSpell(options = {}) { all(...parameters) } - queue[index][3](error) + // To do: `dictionary`s should not pass `null`. + queue[index][3](error || undefined) } queue.length = 0 @@ -175,7 +176,7 @@ function all(tree, file, config) { if ( !parent || - position === null || + position === undefined || (ignoreLiteral && isLiteral(parent, position)) ) { return diff --git a/package.json b/package.json index f12dbc9..5810c04 100644 --- a/package.json +++ b/package.json @@ -37,35 +37,35 @@ "index.js" ], "dependencies": { - "@types/nlcst": "^1.0.0", - "nlcst-is-literal": "^2.0.0", - "nlcst-to-string": "^3.0.0", + "@types/nlcst": "^2.0.0", + "nlcst-is-literal": "^3.0.0", + "nlcst-to-string": "^4.0.0", "nspell": "^2.0.0", "quotation": "^2.0.0", - "unified": "^10.0.0", - "unist-util-visit": "^4.0.0" + "unified": "^11.0.0", + "unist-util-visit": "^5.0.0" }, "devDependencies": { "@types/tape": "^5.0.0", - "@types/unist": "^2.0.0", + "@types/unist": "^3.0.0", "c8": "^8.0.0", "dictionary-en": "^3.0.0", "dictionary-en-gb": "^2.0.0", "prettier": "^3.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", - "retext": "^8.0.0", - "retext-emoji": "^8.0.0", + "retext": "^9.0.0", + "retext-emoji": "^9.0.0", "rimraf": "^3.0.0", "tape": "^5.0.0", "type-coverage": "^2.0.0", "typescript": "^5.0.0", - "vfile": "^5.0.0", + "vfile": "^6.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" diff --git a/test.js b/test.js index 51f1ea3..f96ef21 100644 --- a/test.js +++ b/test.js @@ -54,26 +54,25 @@ test('should warn for misspelt words', async (t) => { const file = await retext().use(retextSpell, enGb).process('color') t.deepEqual( - JSON.parse(JSON.stringify(file.messages)), - [ - { - name: '1:1-1:6', - message: '`color` is misspelt; did you mean `colon`, `colour`, `Colo`?', - reason: '`color` is misspelt; did you mean `colon`, `colour`, `Colo`?', - line: 1, - column: 1, - source: 'retext-spell', - ruleId: 'color', - position: { - start: {line: 1, column: 1, offset: 0}, - end: {line: 1, column: 6, offset: 5} - }, - fatal: false, - actual: 'color', - expected: ['colon', 'colour', 'Colo'], - url: 'https://github.com/retextjs/retext-spell#readme' - } - ], + JSON.parse(JSON.stringify({...file.messages[0], ancestors: []})), + { + ancestors: [], + column: 1, + fatal: false, + message: '`color` is misspelt; did you mean `colon`, `colour`, `Colo`?', + line: 1, + name: '1:1-1:6', + place: { + start: {line: 1, column: 1, offset: 0}, + end: {line: 1, column: 6, offset: 5} + }, + reason: '`color` is misspelt; did you mean `colon`, `colour`, `Colo`?', + ruleId: 'color', + source: 'retext-spell', + actual: 'color', + expected: ['colon', 'colour', 'Colo'], + url: 'https://github.com/retextjs/retext-spell#readme' + }, 'should emit messages' )