Skip to content

Commit 57f8244

Browse files
committed
Convert from CommonJS module to ECMAScript module.
1 parent 0d9fcb5 commit 57f8244

File tree

12 files changed

+767
-65
lines changed

12 files changed

+767
-65
lines changed

.editorconfig

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ charset = utf-8
88
trim_trailing_whitespace = true
99

1010
[*.js]
11-
insert_final_newline = true
11+
insert_final_newline = true
12+
13+
[*.cjs]
14+
insert_final_newline = true
15+
16+
[*.mjs]
17+
insert_final_newline = true

markdownlint.js

+20-26
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
#!/usr/bin/env node
22

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);
1816
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';
1920

2021
function posixPath(p) {
2122
return p.split(path.sep).join(path.posix.sep);
@@ -195,8 +196,8 @@ function concatArray(item, array) {
195196
}
196197

197198
program
198-
.version(pkg.version)
199-
.description(pkg.description)
199+
.version(version)
200+
.description(description)
200201
.usage('[options] <files|directories|globs>')
201202
.option('-c, --config <configFile>', 'configuration file (JSON, JSONC, JS, YAML, or TOML)')
202203
.option('--configPointer <pointer>', 'JSON Pointer to object within configuration file', '')
@@ -241,7 +242,7 @@ function loadCustomRules(rules) {
241242
return rules.flatMap(rule => {
242243
try {
243244
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));
245246
if (fileList.length === 0) {
246247
throw new Error('No such rule');
247248
}
@@ -300,15 +301,8 @@ function lintAndPrint(stdin, files) {
300301
};
301302
}
302303

303-
if (options.json) {
304-
lintOptions.resultVersion = 3;
305-
}
306-
307304
if (options.fix) {
308-
const fixOptions = {
309-
...lintOptions,
310-
resultVersion: 3
311-
};
305+
const fixOptions = {...lintOptions};
312306
for (const file of files) {
313307
fixOptions.files = [file];
314308
const fixResult = markdownlint.sync(fixOptions);

0 commit comments

Comments
 (0)