1- import fs from 'fs';
1+ import * as fs from 'fs';
2+ import fs__default from 'fs';
23import path$1 from 'path';
34import { fileURLToPath, pathToFileURL, URL as URL$1 } from 'url';
45import process$1 from 'process';
@@ -19485,7 +19486,7 @@ function validateLinks(tree, vfile) {
1948519486 for (const node of getLinksRecursively(tree)) {
1948619487 if (node.url[0] !== "#") {
1948719488 const targetURL = new URL(node.url, currentFileURL);
19488- if (targetURL.protocol === "file:" && !fs .existsSync(targetURL)) {
19489+ if (targetURL.protocol === "file:" && !fs__default .existsSync(targetURL)) {
1948919490 vfile.message("Broken link", node);
1949019491 } else if (targetURL.pathname === currentFileURL.pathname) {
1949119492 const expected = node.url.includes("#")
@@ -28313,7 +28314,7 @@ function toVFile(options) {
2831328314 */
2831428315function readSync(description, options) {
2831528316 const file = toVFile(description);
28316- file.value = fs .readFileSync(path$1.resolve(file.cwd, file.path), options);
28317+ file.value = fs__default .readFileSync(path$1.resolve(file.cwd, file.path), options);
2831728318 return file
2831828319}
2831928320
@@ -28326,7 +28327,7 @@ function readSync(description, options) {
2832628327 */
2832728328function writeSync(description, options) {
2832828329 const file = toVFile(description);
28329- fs .writeFileSync(path$1.resolve(file.cwd, file.path), file.value || '', options);
28330+ fs__default .writeFileSync(path$1.resolve(file.cwd, file.path), file.value || '', options);
2833028331 return file
2833128332}
2833228333
@@ -28381,7 +28382,7 @@ const read =
2838128382 return reject(error)
2838228383 }
2838328384
28384- fs .readFile(fp, options, done);
28385+ fs__default .readFile(fp, options, done);
2838528386
2838628387 /**
2838728388 * @param {Error} error
@@ -28451,7 +28452,7 @@ const write =
2845128452 return reject(error)
2845228453 }
2845328454
28454- fs .writeFile(fp, file.value || '', options, done);
28455+ fs__default .writeFile(fp, file.value || '', options, done);
2845528456
2845628457 /**
2845728458 * @param {Error} error
@@ -28936,7 +28937,7 @@ function reporter(files, options = {}) {
2893628937 files = [files];
2893728938 }
2893828939
28939- return format(transform(files, options), one, options)
28940+ return format$1 (transform(files, options), one, options)
2894028941}
2894128942
2894228943/**
@@ -29013,7 +29014,7 @@ function transform(files, options) {
2901329014 * @param {Options} options
2901429015 */
2901529016// eslint-disable-next-line complexity
29016- function format(map, one, options) {
29017+ function format$1 (map, one, options) {
2901729018 /** @type {boolean} */
2901829019 const enabled =
2901929020 options.color === undefined || options.color === null
@@ -29155,6 +29156,18 @@ function size(value) {
2915529156
2915629157const paths = process.argv.slice(2);
2915729158
29159+ if (!paths.length) {
29160+ console.error('Usage: lint-md.mjs <path> [<path> ...]');
29161+ process.exit(1);
29162+ }
29163+
29164+ let format = false;
29165+
29166+ if (paths[0] === '--format') {
29167+ paths.shift();
29168+ format = true;
29169+ }
29170+
2915829171const linter = unified()
2915929172 .use(remarkParse)
2916029173 .use(remarkGfm)
@@ -29164,9 +29177,10 @@ const linter = unified()
2916429177paths.forEach(async (path) => {
2916529178 const file = await read(path);
2916629179 const result = await linter.process(file);
29167- if (result.messages.length) {
29180+ if (format) {
29181+ fs.writeFileSync(path, String(result));
29182+ } else if (result.messages.length) {
2916829183 process.exitCode = 1;
2916929184 console.error(reporter(result));
2917029185 }
29171- // TODO: allow reformatting by writing `String(result)` to the input file
2917229186});
0 commit comments