Skip to content

Commit

Permalink
tools: update remark-preset-lint-node to 2.4.1
Browse files Browse the repository at this point in the history
PR-URL: #39201
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
Trott authored and targos committed Jul 11, 2021
1 parent 81d52d7 commit dfe5d11
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
50 changes: 49 additions & 1 deletion tools/lint-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }; }

Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -50532,6 +50579,7 @@ var plugins$2 = [
remarkLintNoTableIndentation,
remarkLintNoTabs,
remarkLintNoTrailingSpaces,
remarkLintNodejsLinks,
remarkLintNodejsYamlComments,
[
remarkLintProhibitedStrings,
Expand Down
20 changes: 12 additions & 8 deletions tools/node-lint-md-cli-rollup/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dfe5d11

Please sign in to comment.