|
1 | 1 | #!/usr/bin/env node
|
2 | 2 |
|
3 |
| -'use strict'; |
4 |
| - |
5 |
| -const fs = require('node:fs'); |
6 |
| -const path = require('node:path'); |
7 |
| -const Module = require('node:module'); |
8 |
| -const os = require('node:os'); |
9 |
| -const process = require('node:process'); |
10 |
| -const {program} = require('commander'); |
11 |
| -const glob = require('glob'); |
12 |
| -const markdownlint = require('markdownlint'); |
13 |
| -const rc = require('run-con'); |
14 |
| -const minimatch = require('minimatch'); |
15 |
| -const jsonpointer = require('jsonpointer'); |
16 |
| -const pkg = require('./package.json'); |
17 |
| - |
| 3 | +import fs from 'node:fs'; |
| 4 | +import path from 'node:path'; |
| 5 | +import Module from 'node:module'; |
| 6 | +import os from 'node:os'; |
| 7 | +import process from 'node:process'; |
| 8 | +import {program} from 'commander'; |
| 9 | +import {glob} from 'glob'; |
| 10 | +import markdownlint from 'markdownlint'; |
| 11 | +import rc from 'run-con'; |
| 12 | +import {minimatch} from 'minimatch'; |
| 13 | +import jsonpointer from 'jsonpointer'; |
| 14 | + |
| 15 | +const require = Module.createRequire(import.meta.url); |
18 | 16 | const options = program.opts();
|
| 17 | +// The following two values are copied from package.json (and validated by tests) |
| 18 | +const version = '0.43.0'; |
| 19 | +const description = 'MarkdownLint Command Line Interface'; |
19 | 20 |
|
20 | 21 | function posixPath(p) {
|
21 | 22 | return p.split(path.sep).join(path.posix.sep);
|
@@ -195,8 +196,8 @@ function concatArray(item, array) {
|
195 | 196 | }
|
196 | 197 |
|
197 | 198 | program
|
198 |
| - .version(pkg.version) |
199 |
| - .description(pkg.description) |
| 199 | + .version(version) |
| 200 | + .description(description) |
200 | 201 | .usage('[options] <files|directories|globs>')
|
201 | 202 | .option('-c, --config <configFile>', 'configuration file (JSON, JSONC, JS, YAML, or TOML)')
|
202 | 203 | .option('--configPointer <pointer>', 'JSON Pointer to object within configuration file', '')
|
@@ -241,7 +242,7 @@ function loadCustomRules(rules) {
|
241 | 242 | return rules.flatMap(rule => {
|
242 | 243 | try {
|
243 | 244 | const resolvedPath = [tryResolvePath(rule)];
|
244 |
| - const fileList = prepareFileList(resolvedPath, ['js']).flatMap(filepath => require(filepath.absolute)); |
| 245 | + const fileList = prepareFileList(resolvedPath, ['js', 'cjs', 'mjs']).flatMap(filepath => require(filepath.absolute)); |
245 | 246 | if (fileList.length === 0) {
|
246 | 247 | throw new Error('No such rule');
|
247 | 248 | }
|
@@ -300,15 +301,8 @@ function lintAndPrint(stdin, files) {
|
300 | 301 | };
|
301 | 302 | }
|
302 | 303 |
|
303 |
| - if (options.json) { |
304 |
| - lintOptions.resultVersion = 3; |
305 |
| - } |
306 |
| - |
307 | 304 | if (options.fix) {
|
308 |
| - const fixOptions = { |
309 |
| - ...lintOptions, |
310 |
| - resultVersion: 3 |
311 |
| - }; |
| 305 | + const fixOptions = {...lintOptions}; |
312 | 306 | for (const file of files) {
|
313 | 307 | fixOptions.files = [file];
|
314 | 308 | const fixResult = markdownlint.sync(fixOptions);
|
|
0 commit comments