From 3ecfe9d7eec80f374ec41366b69096a7d7ea2a41 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 29 Jun 2021 22:00:59 -0700 Subject: [PATCH] tools: update remark-preset-lint-node to 2.4.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/39201 Reviewed-By: Michaƫl Zasso Reviewed-By: Antoine du Hamel --- tools/lint-md.js | 50 ++++++++++++++++++- .../node-lint-md-cli-rollup/package-lock.json | 20 +++++--- 2 files changed, 61 insertions(+), 9 deletions(-) diff --git a/tools/lint-md.js b/tools/lint-md.js index 9dfa33e9614366..3089d1deb9d7bf 100644 --- a/tools/lint-md.js +++ b/tools/lint-md.js @@ -12,6 +12,7 @@ var tty = require('tty'); var fs$1 = require('fs'); var events = require('events'); var assert = require('assert'); +var require$$0$4 = require('url'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } @@ -24,6 +25,7 @@ var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty); var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$1); var events__default = /*#__PURE__*/_interopDefaultLegacy(events); var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert); +var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$4); var vfileStatistics = statistics; @@ -45048,6 +45050,51 @@ function noTrailingSpaces(ast, file) { } } +const { pathToFileURL } = require$$0__default$1['default']; + + + +function* getLinksRecursively(node) { + if (node.url) { + yield node; + } + for (const child of node.children || []) { + yield* getLinksRecursively(child); + } +} + +function validateLinks(tree, vfile) { + const currentFileURL = pathToFileURL(path__default['default'].join(vfile.cwd, vfile.path)); + let previousDefinitionLabel; + for (const node of getLinksRecursively(tree)) { + if (node.url[0] !== "#") { + const targetURL = new URL(node.url, currentFileURL); + if (targetURL.protocol === "file:" && !fs__default['default'].existsSync(targetURL)) { + vfile.message("Broken link", node); + } else if (targetURL.pathname === currentFileURL.pathname) { + const expected = node.url.includes("#") + ? node.url.slice(node.url.indexOf("#")) + : "#"; + vfile.message( + `Self-reference must start with hash (expected "${expected}", got "${node.url}")`, + node + ); + } + } + if (node.type === "definition") { + if (previousDefinitionLabel && previousDefinitionLabel > node.label) { + vfile.message( + `Unordered reference ("${node.label}" should be before "${previousDefinitionLabel}")`, + node + ); + } + previousDefinitionLabel = node.label; + } + } +} + +var remarkLintNodejsLinks = unifiedLintRule("remark-lint:nodejs-links", validateLinks); + function isNothing$1(subject) { return (typeof subject === 'undefined') || (subject === null); } @@ -49632,7 +49679,7 @@ function validateMeta(node, file, meta) { case kWrongKeyOrder: file.message( - "YAML dictionary keys should be respect this order: " + + "YAML dictionary keys should be in this order: " + allowedKeys.join(", "), node ); @@ -50527,6 +50574,7 @@ var plugins$2 = [ remarkLintNoTableIndentation, remarkLintNoTabs, remarkLintNoTrailingSpaces, + remarkLintNodejsLinks, remarkLintNodejsYamlComments, [ remarkLintProhibitedStrings, diff --git a/tools/node-lint-md-cli-rollup/package-lock.json b/tools/node-lint-md-cli-rollup/package-lock.json index 70cf0ee00459dd..6f13ecea4c2cc9 100644 --- a/tools/node-lint-md-cli-rollup/package-lock.json +++ b/tools/node-lint-md-cli-rollup/package-lock.json @@ -2111,9 +2111,9 @@ } }, "node_modules/remark-preset-lint-node": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.3.0.tgz", - "integrity": "sha512-k2whtqbZ0/RRH2ffumvsNEkpKrbrcYLA2K8bZ5bnPeM/jahmJukas0uk9cYXUmsfDLzV6kuJHaO0EAzaYmVvMg==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.4.1.tgz", + "integrity": "sha512-lNRqQulYuu8ADd4lSNhjOnZck/iDzLVY8oWA9U4BptfHQcDVwFm3bkNDfsVuEA7iJAFJzF7QuuHIcxzPV5VeFg==", "dependencies": { "js-yaml": "^4.0.0", "remark-lint": "^8.0.0", @@ -2147,7 +2147,9 @@ "remark-lint-table-pipes": "^3.0.0", "remark-lint-unordered-list-marker-style": "^2.0.0", "remark-preset-lint-recommended": "^5.0.0", - "semver": "^7.3.2" + "semver": "^7.3.2", + "unified-lint-rule": "^1.0.6", + "unist-util-visit": "^2.0.3" } }, "node_modules/remark-preset-lint-node/node_modules/argparse": { @@ -4226,9 +4228,9 @@ } }, "remark-preset-lint-node": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.3.0.tgz", - "integrity": "sha512-k2whtqbZ0/RRH2ffumvsNEkpKrbrcYLA2K8bZ5bnPeM/jahmJukas0uk9cYXUmsfDLzV6kuJHaO0EAzaYmVvMg==", + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.4.1.tgz", + "integrity": "sha512-lNRqQulYuu8ADd4lSNhjOnZck/iDzLVY8oWA9U4BptfHQcDVwFm3bkNDfsVuEA7iJAFJzF7QuuHIcxzPV5VeFg==", "requires": { "js-yaml": "^4.0.0", "remark-lint": "^8.0.0", @@ -4262,7 +4264,9 @@ "remark-lint-table-pipes": "^3.0.0", "remark-lint-unordered-list-marker-style": "^2.0.0", "remark-preset-lint-recommended": "^5.0.0", - "semver": "^7.3.2" + "semver": "^7.3.2", + "unified-lint-rule": "^1.0.6", + "unist-util-visit": "^2.0.3" }, "dependencies": { "argparse": {