1
- import fs from 'fs';
1
+ import * as fs from 'fs';
2
+ import fs__default from 'fs';
2
3
import path$1 from 'path';
3
4
import { fileURLToPath, pathToFileURL, URL as URL$1 } from 'url';
4
5
import process$1 from 'process';
@@ -19485,7 +19486,7 @@ function validateLinks(tree, vfile) {
19485
19486
for (const node of getLinksRecursively(tree)) {
19486
19487
if (node.url[0] !== "#") {
19487
19488
const targetURL = new URL(node.url, currentFileURL);
19488
- if (targetURL.protocol === "file:" && !fs .existsSync(targetURL)) {
19489
+ if (targetURL.protocol === "file:" && !fs__default .existsSync(targetURL)) {
19489
19490
vfile.message("Broken link", node);
19490
19491
} else if (targetURL.pathname === currentFileURL.pathname) {
19491
19492
const expected = node.url.includes("#")
@@ -28313,7 +28314,7 @@ function toVFile(options) {
28313
28314
*/
28314
28315
function readSync(description, options) {
28315
28316
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);
28317
28318
return file
28318
28319
}
28319
28320
@@ -28326,7 +28327,7 @@ function readSync(description, options) {
28326
28327
*/
28327
28328
function writeSync(description, options) {
28328
28329
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);
28330
28331
return file
28331
28332
}
28332
28333
@@ -28381,7 +28382,7 @@ const read =
28381
28382
return reject(error)
28382
28383
}
28383
28384
28384
- fs .readFile(fp, options, done);
28385
+ fs__default .readFile(fp, options, done);
28385
28386
28386
28387
/**
28387
28388
* @param {Error} error
@@ -28451,7 +28452,7 @@ const write =
28451
28452
return reject(error)
28452
28453
}
28453
28454
28454
- fs .writeFile(fp, file.value || '', options, done);
28455
+ fs__default .writeFile(fp, file.value || '', options, done);
28455
28456
28456
28457
/**
28457
28458
* @param {Error} error
@@ -28936,7 +28937,7 @@ function reporter(files, options = {}) {
28936
28937
files = [files];
28937
28938
}
28938
28939
28939
- return format(transform(files, options), one, options)
28940
+ return format$1 (transform(files, options), one, options)
28940
28941
}
28941
28942
28942
28943
/**
@@ -29013,7 +29014,7 @@ function transform(files, options) {
29013
29014
* @param {Options} options
29014
29015
*/
29015
29016
// eslint-disable-next-line complexity
29016
- function format(map, one, options) {
29017
+ function format$1 (map, one, options) {
29017
29018
/** @type {boolean} */
29018
29019
const enabled =
29019
29020
options.color === undefined || options.color === null
@@ -29155,6 +29156,18 @@ function size(value) {
29155
29156
29156
29157
const paths = process.argv.slice(2);
29157
29158
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
+
29158
29171
const linter = unified()
29159
29172
.use(remarkParse)
29160
29173
.use(remarkGfm)
@@ -29164,9 +29177,10 @@ const linter = unified()
29164
29177
paths.forEach(async (path) => {
29165
29178
const file = await read(path);
29166
29179
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) {
29168
29183
process.exitCode = 1;
29169
29184
console.error(reporter(result));
29170
29185
}
29171
- // TODO: allow reformatting by writing `String(result)` to the input file
29172
29186
});
0 commit comments