diff --git a/.remarkrc.js b/.remarkrc.js index f1635aac..c3391323 100644 --- a/.remarkrc.js +++ b/.remarkrc.js @@ -1,5 +1,6 @@ import remarkPresetLintRecommended from './packages/remark-preset-lint-recommended/index.js' import remarkPresetLintConsistent from './packages/remark-preset-lint-consistent/index.js' +import remarkLintListItemIndent from './packages/remark-lint-list-item-indent/index.js' import remarkToc from 'remark-toc' import remarkCommentConfig from 'remark-comment-config' import remarkGfm from 'remark-gfm' @@ -11,6 +12,8 @@ import listOfRules from './script/plugin/list-of-rules.js' const plugins = [ remarkPresetLintRecommended, remarkPresetLintConsistent, + // To do: change. + [remarkLintListItemIndent, 'tab-size'], [remarkToc, {tight: true, maxDepth: 3, heading: 'contents'}], remarkCommentConfig, [remarkGfm, {tablePipeAlign: false}], @@ -20,6 +23,10 @@ const plugins = [ listOfRules ] -const preset = {plugins} +const preset = { + plugins, + // To do: change. + settings: {listItemIndent: 'tab'} +} export default preset diff --git a/package.json b/package.json index 59493aa1..a90b912e 100644 --- a/package.json +++ b/package.json @@ -110,29 +110,29 @@ "packages/unified-lint-rule" ], "devDependencies": { - "@types/mdast": "^3.0.0", + "@types/mdast": "^4.0.0", "@types/parse-author": "^2.0.0", "@types/pluralize": "^0.0.33", "c8": "^8.0.0", "comment-parser": "^1.0.0", "github-slugger": "^2.0.0", - "mdast-zone": "^5.0.0", + "mdast-zone": "^6.0.0", "parse-author": "^2.0.0", "prettier": "^3.0.0", - "remark": "^14.0.0", - "remark-cli": "^11.0.0", - "remark-comment-config": "^7.0.0", - "remark-gfm": "^3.0.0", - "remark-github": "^11.0.0", - "remark-toc": "^8.0.0", - "remark-validate-links": "^12.0.0", + "remark": "^15.0.0", + "remark-cli": "^12.0.0", + "remark-comment-config": "^8.0.0", + "remark-gfm": "^4.0.0", + "remark-github": "^12.0.0", + "remark-toc": "^9.0.0", + "remark-validate-links": "^13.0.0", "strip-indent": "^4.0.0", - "to-vfile": "^7.0.0", + "to-vfile": "^8.0.0", "type-coverage": "^2.0.0", "type-fest": "^4.0.0", "typescript": "^5.0.0", - "unist-builder": "^3.0.0", - "unist-util-remove-position": "^4.0.0", + "unist-builder": "^4.0.0", + "unist-util-remove-position": "^5.0.0", "xo": "^0.56.0" }, "scripts": { diff --git a/packages/remark-lint-blockquote-indentation/index.js b/packages/remark-lint-blockquote-indentation/index.js index 28dd35cc..9d679f1c 100644 --- a/packages/remark-lint-blockquote-indentation/index.js +++ b/packages/remark-lint-blockquote-indentation/index.js @@ -106,23 +106,30 @@ const remarkLintBlockquoteIndentation = lintRule( return } - if (option === 'consistent') { - option = check(node) - } else { - const diff = option - check(node) + const start = pointStart(node) + const head = pointStart(node.children[0]) + /* c8 ignore next -- we get here if we have offsets. */ + const count = head && start ? head.column - start.column : undefined - if (diff !== 0) { - const abs = Math.abs(diff) + if (typeof count === 'number') { + if (option === 'consistent') { + option = count + } else { + const diff = option - count - file.message( - (diff > 0 ? 'Add' : 'Remove') + - ' ' + - abs + - ' ' + - plural('space', abs) + - ' between block quote and content', - pointStart(node.children[0]) - ) + if (diff !== 0) { + const abs = Math.abs(diff) + + file.message( + (diff > 0 ? 'Add' : 'Remove') + + ' ' + + abs + + ' ' + + plural('space', abs) + + ' between block quote and content', + pointStart(node.children[0]) + ) + } } } }) @@ -130,11 +137,3 @@ const remarkLintBlockquoteIndentation = lintRule( ) export default remarkLintBlockquoteIndentation - -/** - * @param {Blockquote} node - * @returns {number} - */ -function check(node) { - return pointStart(node.children[0]).column - pointStart(node).column -} diff --git a/packages/remark-lint-blockquote-indentation/package.json b/packages/remark-lint-blockquote-indentation/package.json index e1ee486a..87fa8eba 100644 --- a/packages/remark-lint-blockquote-indentation/package.json +++ b/packages/remark-lint-blockquote-indentation/package.json @@ -35,13 +35,13 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", + "@types/mdast": "^4.0.0", "pluralize": "^8.0.0", - "unified": "^10.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-generated": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-generated": "^3.0.0", + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-checkbox-character-style/index.js b/packages/remark-lint-checkbox-character-style/index.js index 21979ff7..86f662ac 100644 --- a/packages/remark-lint-checkbox-character-style/index.js +++ b/packages/remark-lint-checkbox-character-style/index.js @@ -148,6 +148,7 @@ const remarkLintCheckboxCharacterStyle = lintRule( // Exit early for items without checkbox. // A list item cannot be checked and empty, according to GFM. if ( + !point || typeof node.checked !== 'boolean' || !head || typeof point.offset !== 'number' diff --git a/packages/remark-lint-checkbox-character-style/package.json b/packages/remark-lint-checkbox-character-style/package.json index c32e9969..46194aae 100644 --- a/packages/remark-lint-checkbox-character-style/package.json +++ b/packages/remark-lint-checkbox-character-style/package.json @@ -36,11 +36,11 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-checkbox-content-indent/index.js b/packages/remark-lint-checkbox-content-indent/index.js index e70f1f52..3a19ca7a 100644 --- a/packages/remark-lint-checkbox-content-indent/index.js +++ b/packages/remark-lint-checkbox-content-indent/index.js @@ -87,6 +87,7 @@ const remarkLintCheckboxContentIndent = lintRule( // Exit early for items without checkbox. // A list item cannot be checked and empty, according to GFM. if ( + !point || typeof node.checked !== 'boolean' || !head || typeof point.offset !== 'number' @@ -110,11 +111,14 @@ const remarkLintCheckboxContentIndent = lintRule( while (/[\t ]/.test(value.charAt(final))) final++ if (final - initial > 0) { - // @ts-expect-error: assume we have a correct point. - file.message('Checkboxes should be followed by a single character', { - start: loc.toPoint(initial), - end: loc.toPoint(final) - }) + const start = loc.toPoint(initial) + const end = loc.toPoint(final) + + file.message( + 'Checkboxes should be followed by a single character', + /* c8 ignore next -- we get here if we have offsets. */ + start && end ? {start, end} : undefined + ) } }) } diff --git a/packages/remark-lint-checkbox-content-indent/package.json b/packages/remark-lint-checkbox-content-indent/package.json index 401d12bc..7471d1ec 100644 --- a/packages/remark-lint-checkbox-content-indent/package.json +++ b/packages/remark-lint-checkbox-content-indent/package.json @@ -36,12 +36,12 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0", - "vfile-location": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0", + "vfile-location": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-code-block-style/index.js b/packages/remark-lint-code-block-style/index.js index ae3f575d..ce71701e 100644 --- a/packages/remark-lint-code-block-style/index.js +++ b/packages/remark-lint-code-block-style/index.js @@ -140,7 +140,6 @@ import {lintRule} from 'unified-lint-rule' import {visit} from 'unist-util-visit' import {pointStart, pointEnd} from 'unist-util-position' -import {generated} from 'unist-util-generated' const remarkLintCodeBlockStyle = lintRule( { @@ -164,15 +163,21 @@ const remarkLintCodeBlockStyle = lintRule( } visit(tree, 'code', (node) => { - if (generated(node)) { + const initial = pointStart(node) + const final = pointEnd(node) + + if ( + !initial || + !final || + typeof initial.offset !== 'number' || + typeof final.offset !== 'number' + ) { return } - const initial = pointStart(node).offset - const final = pointEnd(node).offset - const current = - node.lang || /^\s*([~`])\1{2,}/.test(value.slice(initial, final)) + node.lang || + /^\s*([~`])\1{2,}/.test(value.slice(initial.offset, final.offset)) ? 'fenced' : 'indented' diff --git a/packages/remark-lint-code-block-style/package.json b/packages/remark-lint-code-block-style/package.json index cc2fd6b3..d073ceb6 100644 --- a/packages/remark-lint-code-block-style/package.json +++ b/packages/remark-lint-code-block-style/package.json @@ -34,12 +34,11 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-generated": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-definition-case/index.js b/packages/remark-lint-definition-case/index.js index e1a626d0..1c0207eb 100644 --- a/packages/remark-lint-definition-case/index.js +++ b/packages/remark-lint-definition-case/index.js @@ -58,11 +58,16 @@ const remarkLintDefinitionCase = lintRule( visit(tree, (node) => { if (node.type === 'definition' || node.type === 'footnoteDefinition') { - const start = pointStart(node).offset - const end = pointEnd(node).offset + const start = pointStart(node) + const end = pointEnd(node) - if (typeof start === 'number' && typeof end === 'number') { - const match = value.slice(start, end).match(label) + if ( + start && + end && + typeof start.offset === 'number' && + typeof end.offset === 'number' + ) { + const match = value.slice(start.offset, end.offset).match(label) if (match && match[1] !== match[1].toLowerCase()) { file.message( diff --git a/packages/remark-lint-definition-case/package.json b/packages/remark-lint-definition-case/package.json index e51394c1..8fb1dd94 100644 --- a/packages/remark-lint-definition-case/package.json +++ b/packages/remark-lint-definition-case/package.json @@ -34,11 +34,11 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-definition-spacing/index.js b/packages/remark-lint-definition-spacing/index.js index a3403768..3e31393f 100644 --- a/packages/remark-lint-definition-spacing/index.js +++ b/packages/remark-lint-definition-spacing/index.js @@ -60,11 +60,16 @@ const remarkLintDefinitionSpacing = lintRule( visit(tree, (node) => { if (node.type === 'definition' || node.type === 'footnoteDefinition') { - const start = pointStart(node).offset - const end = pointEnd(node).offset + const start = pointStart(node) + const end = pointEnd(node) - if (typeof start === 'number' && typeof end === 'number') { - const match = value.slice(start, end).match(label) + if ( + start && + end && + typeof start.offset === 'number' && + typeof end.offset === 'number' + ) { + const match = value.slice(start.offset, end.offset).match(label) if (match && /[ \t\n]{2,}/.test(match[1])) { file.message( diff --git a/packages/remark-lint-definition-spacing/package.json b/packages/remark-lint-definition-spacing/package.json index bc4a71f2..fef3adc8 100644 --- a/packages/remark-lint-definition-spacing/package.json +++ b/packages/remark-lint-definition-spacing/package.json @@ -34,11 +34,11 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-emphasis-marker/index.js b/packages/remark-lint-emphasis-marker/index.js index 83cd99ec..3bcc5abb 100644 --- a/packages/remark-lint-emphasis-marker/index.js +++ b/packages/remark-lint-emphasis-marker/index.js @@ -119,10 +119,10 @@ const remarkLintEmphasisMarker = lintRule( } visit(tree, 'emphasis', (node) => { - const start = pointStart(node).offset + const start = pointStart(node) - if (typeof start === 'number') { - const marker = /** @type {Marker} */ (value.charAt(start)) + if (start && typeof start.offset === 'number') { + const marker = /** @type {Marker} */ (value.charAt(start.offset)) if (option === 'consistent') { option = marker diff --git a/packages/remark-lint-emphasis-marker/package.json b/packages/remark-lint-emphasis-marker/package.json index c3442643..62303fb7 100644 --- a/packages/remark-lint-emphasis-marker/package.json +++ b/packages/remark-lint-emphasis-marker/package.json @@ -34,11 +34,11 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-fenced-code-flag/index.js b/packages/remark-lint-fenced-code-flag/index.js index b9bc716e..5b9e52e5 100644 --- a/packages/remark-lint-fenced-code-flag/index.js +++ b/packages/remark-lint-fenced-code-flag/index.js @@ -117,7 +117,6 @@ import {lintRule} from 'unified-lint-rule' import {visit} from 'unist-util-visit' import {pointStart, pointEnd} from 'unist-util-position' -import {generated} from 'unist-util-generated' const fence = /^ {0,3}([~`])\1{2,}/ @@ -146,16 +145,21 @@ const remarkLintFencedCodeFlag = lintRule( } visit(tree, 'code', (node) => { - if (!generated(node)) { + const start = pointStart(node) + const end = pointEnd(node) + + if ( + start && + end && + typeof start.offset === 'number' && + typeof end.offset === 'number' + ) { if (node.lang) { if (allowed.length > 0 && !allowed.includes(node.lang)) { file.message('Incorrect code language flag', node) } } else { - const slice = value.slice( - pointStart(node).offset, - pointEnd(node).offset - ) + const slice = value.slice(start.offset, end.offset) if (!allowEmpty && fence.test(slice)) { file.message('Missing code language flag', node) diff --git a/packages/remark-lint-fenced-code-flag/package.json b/packages/remark-lint-fenced-code-flag/package.json index 5da89b19..1be236bc 100644 --- a/packages/remark-lint-fenced-code-flag/package.json +++ b/packages/remark-lint-fenced-code-flag/package.json @@ -36,12 +36,11 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-generated": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-fenced-code-marker/index.js b/packages/remark-lint-fenced-code-marker/index.js index 0ac2e0eb..adbd0022 100644 --- a/packages/remark-lint-fenced-code-marker/index.js +++ b/packages/remark-lint-fenced-code-marker/index.js @@ -133,11 +133,11 @@ const remarkLintFencedCodeMarker = lintRule( } visit(tree, 'code', (node) => { - const start = pointStart(node).offset + const start = pointStart(node) - if (typeof start === 'number') { + if (start && typeof start.offset === 'number') { const marker = contents - .slice(start, start + 4) + .slice(start.offset, start.offset + 4) .replace(/^\s+/, '') .charAt(0) diff --git a/packages/remark-lint-fenced-code-marker/package.json b/packages/remark-lint-fenced-code-marker/package.json index 6c64fce6..d3200747 100644 --- a/packages/remark-lint-fenced-code-marker/package.json +++ b/packages/remark-lint-fenced-code-marker/package.json @@ -35,11 +35,11 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0", - "unist-util-position": "^4.0.0", - "unist-util-visit": "^4.0.0" + "unist-util-position": "^5.0.0", + "unist-util-visit": "^5.0.0" }, "scripts": {}, "xo": { diff --git a/packages/remark-lint-file-extension/package.json b/packages/remark-lint-file-extension/package.json index 94f288fe..75050d54 100644 --- a/packages/remark-lint-file-extension/package.json +++ b/packages/remark-lint-file-extension/package.json @@ -35,8 +35,8 @@ "index.js" ], "dependencies": { - "@types/mdast": "^3.0.0", - "unified": "^10.0.0", + "@types/mdast": "^4.0.0", + "unified": "^11.0.0", "unified-lint-rule": "^2.0.0" }, "scripts": {}, diff --git a/packages/remark-lint-final-definition/index.js b/packages/remark-lint-final-definition/index.js index 5e93e3c1..3ee95667 100644 --- a/packages/remark-lint-final-definition/index.js +++ b/packages/remark-lint-final-definition/index.js @@ -61,7 +61,6 @@ import {lintRule} from 'unified-lint-rule' import {visit} from 'unist-util-visit' import {pointStart} from 'unist-util-position' -import {generated} from 'unist-util-generated' const remarkLintFinalDefinition = lintRule( { @@ -75,16 +74,18 @@ const remarkLintFinalDefinition = lintRule( visit( tree, (node) => { + const start = pointStart(node) + // Ignore generated and HTML comment nodes. if ( node.type === 'root' || - generated(node) || + !start || (node.type === 'html' && /^\s*