markdownlint-cli 0.43.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +24 -21
  2. package/markdownlint.js +34 -34
  3. package/package.json +18 -12
package/README.md CHANGED
@@ -21,26 +21,29 @@ brew install markdownlint-cli
21
21
  ```bash
22
22
  markdownlint --help
23
23
 
24
- Usage: markdownlint [options] <files|directories|globs>
25
-
26
- MarkdownLint Command Line Interface
27
-
28
- Options:
29
- -V, --version output the version number
30
- -c, --config <configFile> configuration file (JSON, JSONC, JS, YAML, or TOML)
31
- --configPointer <pointer> JSON Pointer to object within configuration file (default: "")
32
- -d, --dot include files/folders with a dot (for example `.github`)
33
- -f, --fix fix basic errors (does not work with STDIN)
34
- -i, --ignore <file|directory|glob> file(s) to ignore/exclude (default: [])
35
- -j, --json write issues in json format
36
- -o, --output <outputFile> write issues to file (no console)
37
- -p, --ignore-path <file> path to file with ignore pattern(s)
38
- -q, --quiet do not write issues to STDOUT
39
- -r, --rules <file|directory|glob|package> include custom rule files (default: [])
40
- -s, --stdin read from STDIN (does not work with files)
41
- --enable <rules...> Enable certain rules, e.g. --enable MD013 MD041 --
42
- --disable <rules...> Disable certain rules, e.g. --disable MD013 MD041 --
43
- -h, --help display help for command
24
+ Usage: markdownlint [options] [files|directories|globs...]
25
+
26
+ MarkdownLint Command Line Interface
27
+
28
+ Arguments:
29
+ files|directories|globs files, directories, and/or globs to lint
30
+
31
+ Options:
32
+ -V, --version output the version number
33
+ -c, --config <configFile> configuration file (JSON, JSONC, JS, YAML, or TOML)
34
+ --configPointer <pointer> JSON Pointer to object within configuration file (default: "")
35
+ -d, --dot include files/folders with a dot (for example `.github`)
36
+ -f, --fix fix basic errors (does not work with STDIN)
37
+ -i, --ignore <file|directory|glob> file(s) to ignore/exclude (default: [])
38
+ -j, --json write issues in json format
39
+ -o, --output <outputFile> write issues to file (no console)
40
+ -p, --ignore-path <file> path to file with ignore pattern(s)
41
+ -q, --quiet do not write issues to STDOUT
42
+ -r, --rules <file|directory|glob|package> include custom rule files (default: [])
43
+ -s, --stdin read from STDIN (does not work with files)
44
+ --enable <rules...> Enable certain rules, e.g. --enable MD013 MD041 --
45
+ --disable <rules...> Disable certain rules, e.g. --disable MD013 MD041 --
46
+ -h, --help display help for command
44
47
  ```
45
48
 
46
49
  Or run using [Docker](https://www.docker.com) and [GitHub Packages](https://github.com/features/packages):
@@ -139,7 +142,7 @@ To run `markdownlint-cli` as part of a [pre-commit][pre-commit] workflow, add so
139
142
 
140
143
  ```yaml
141
144
  - repo: https://github.com/igorshubovych/markdownlint-cli
142
- rev: v0.43.0
145
+ rev: v0.45.0
143
146
  hooks:
144
147
  - id: markdownlint
145
148
  ```
package/markdownlint.js CHANGED
@@ -1,21 +1,27 @@
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 {applyFixes} from 'markdownlint';
11
+ import {lint, readConfig} from 'markdownlint/sync';
12
+ import rc from 'run-con';
13
+ import {minimatch} from 'minimatch';
14
+ import jsonpointer from 'jsonpointer';
15
+
16
+ const require = Module.createRequire(import.meta.url);
18
17
  const options = program.opts();
18
+ // The following two values are copied from package.json (and validated by tests)
19
+ const version = '0.45.0';
20
+ const description = 'MarkdownLint Command Line Interface';
21
+
22
+ function markdownItFactory() {
23
+ return require('markdown-it')({html: true});
24
+ }
19
25
 
20
26
  function posixPath(p) {
21
27
  return p.split(path.sep).join(path.posix.sep);
@@ -59,8 +65,8 @@ function readConfiguration(userConfigFile) {
59
65
  let config = rc('markdownlint', {});
60
66
  for (const projectConfigFile of projectConfigFiles) {
61
67
  try {
62
- fs.accessSync(projectConfigFile, fs.R_OK);
63
- const projectConfig = markdownlint.readConfigSync(projectConfigFile, configParsers);
68
+ fs.accessSync(projectConfigFile);
69
+ const projectConfig = readConfig(projectConfigFile, configParsers);
64
70
  config = {...config, ...projectConfig};
65
71
  break;
66
72
  } catch {
@@ -73,7 +79,7 @@ function readConfiguration(userConfigFile) {
73
79
  if (userConfigFile) {
74
80
  try {
75
81
  const jsConfigFile = /\.c?js$/i.test(userConfigFile);
76
- const userConfig = jsConfigFile ? require(path.resolve(processCwd, userConfigFile)) : markdownlint.readConfigSync(userConfigFile, configParsers);
82
+ const userConfig = jsConfigFile ? require(path.resolve(processCwd, userConfigFile)) : readConfig(userConfigFile, configParsers);
77
83
  config = require('deep-extend')(config, userConfig);
78
84
  } catch (error) {
79
85
  console.error(`Cannot read or parse config file '${userConfigFile}': ${error.message}`);
@@ -195,9 +201,8 @@ function concatArray(item, array) {
195
201
  }
196
202
 
197
203
  program
198
- .version(pkg.version)
199
- .description(pkg.description)
200
- .usage('[options] <files|directories|globs>')
204
+ .version(version)
205
+ .description(description)
201
206
  .option('-c, --config <configFile>', 'configuration file (JSON, JSONC, JS, YAML, or TOML)')
202
207
  .option('--configPointer <pointer>', 'JSON Pointer to object within configuration file', '')
203
208
  .option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
@@ -210,7 +215,8 @@ program
210
215
  .option('-r, --rules <file|directory|glob|package>', 'include custom rule files', concatArray, [])
211
216
  .option('-s, --stdin', 'read from STDIN (does not work with files)')
212
217
  .option('--enable <rules...>', 'Enable certain rules, e.g. --enable MD013 MD041 --')
213
- .option('--disable <rules...>', 'Disable certain rules, e.g. --disable MD013 MD041 --');
218
+ .option('--disable <rules...>', 'Disable certain rules, e.g. --disable MD013 MD041 --')
219
+ .argument('[files|directories|globs...]', 'files, directories, and/or globs to lint');
214
220
 
215
221
  program.parse(process.argv);
216
222
 
@@ -241,7 +247,7 @@ function loadCustomRules(rules) {
241
247
  return rules.flatMap(rule => {
242
248
  try {
243
249
  const resolvedPath = [tryResolvePath(rule)];
244
- const fileList = prepareFileList(resolvedPath, ['js']).flatMap(filepath => require(filepath.absolute));
250
+ const fileList = prepareFileList(resolvedPath, ['js', 'cjs', 'mjs']).flatMap(filepath => require(filepath.absolute));
245
251
  if (fileList.length === 0) {
246
252
  throw new Error('No such rule');
247
253
  }
@@ -289,6 +295,7 @@ function lintAndPrint(stdin, files) {
289
295
  }
290
296
 
291
297
  const lintOptions = {
298
+ markdownItFactory,
292
299
  config,
293
300
  configParsers,
294
301
  customRules,
@@ -300,22 +307,15 @@ function lintAndPrint(stdin, files) {
300
307
  };
301
308
  }
302
309
 
303
- if (options.json) {
304
- lintOptions.resultVersion = 3;
305
- }
306
-
307
310
  if (options.fix) {
308
- const fixOptions = {
309
- ...lintOptions,
310
- resultVersion: 3
311
- };
311
+ const fixOptions = {...lintOptions};
312
312
  for (const file of files) {
313
313
  fixOptions.files = [file];
314
- const fixResult = markdownlint.sync(fixOptions);
314
+ const fixResult = lint(fixOptions);
315
315
  const fixes = fixResult[file].filter(error => error.fixInfo);
316
316
  if (fixes.length > 0) {
317
317
  const originalText = fs.readFileSync(file, fsOptions);
318
- const fixedText = markdownlint.applyFixes(originalText, fixes);
318
+ const fixedText = applyFixes(originalText, fixes);
319
319
  if (originalText !== fixedText) {
320
320
  fs.writeFileSync(file, fixedText, fsOptions);
321
321
  }
@@ -323,7 +323,7 @@ function lintAndPrint(stdin, files) {
323
323
  }
324
324
  }
325
325
 
326
- const lintResult = markdownlint.sync(lintOptions);
326
+ const lintResult = lint(lintOptions);
327
327
  printResult(lintResult);
328
328
  }
329
329
 
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "markdownlint-cli",
3
- "version": "0.43.0",
3
+ "version": "0.45.0",
4
4
  "description": "MarkdownLint Command Line Interface",
5
+ "type": "module",
5
6
  "main": "markdownlint.js",
6
7
  "bin": {
7
8
  "markdownlint": "markdownlint.js"
8
9
  },
9
10
  "engines": {
10
- "node": ">=18"
11
+ "node": ">=20"
11
12
  },
12
13
  "scripts": {
13
14
  "invalid": "node ./markdownlint.js --config test/test-config.json -- test/incorrect.md",
@@ -37,22 +38,23 @@
37
38
  },
38
39
  "homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
39
40
  "dependencies": {
40
- "commander": "~12.1.0",
41
- "glob": "~11.0.0",
42
- "ignore": "~6.0.2",
43
- "js-yaml": "^4.1.0",
41
+ "commander": "~13.1.0",
42
+ "glob": "~11.0.2",
43
+ "ignore": "~7.0.4",
44
+ "js-yaml": "~4.1.0",
44
45
  "jsonc-parser": "~3.3.1",
45
- "jsonpointer": "5.0.1",
46
- "markdownlint": "~0.36.1",
46
+ "jsonpointer": "~5.0.1",
47
+ "markdownlint": "~0.38.0",
48
+ "markdown-it": "~14.1.0",
47
49
  "minimatch": "~10.0.1",
48
50
  "run-con": "~1.3.2",
49
- "smol-toml": "~1.3.1"
51
+ "smol-toml": "~1.3.4"
50
52
  },
51
53
  "devDependencies": {
52
54
  "ava": "^6.2.0",
53
55
  "markdownlint-cli-local-test-rule": "./test/custom-rules/markdownlint-cli-local-test-rule",
54
- "nano-spawn": "^0.2.0",
55
- "xo": "^0.59.3"
56
+ "nano-spawn": "^1.0.1",
57
+ "xo": "^0.60.0"
56
58
  },
57
59
  "xo": {
58
60
  "prettier": true,
@@ -80,8 +82,12 @@
80
82
  "ava": {
81
83
  "files": [
82
84
  "test/**/*.js",
85
+ "test/**/*.cjs",
86
+ "test/**/*.mjs",
83
87
  "!test/custom-rules/**/*.js",
84
- "!test/md043-config.js"
88
+ "!test/custom-rules/**/*.cjs",
89
+ "!test/custom-rules/**/*.mjs",
90
+ "!test/md043-config.cjs"
85
91
  ],
86
92
  "failFast": true,
87
93
  "timeout": "1m",