markdownlint-cli 0.39.0 → 0.40.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.
- package/README.md +24 -18
- package/markdownlint.js +29 -22
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -26,20 +26,21 @@ markdownlint --help
|
|
|
26
26
|
MarkdownLint Command Line Interface
|
|
27
27
|
|
|
28
28
|
Options:
|
|
29
|
-
-V, --version
|
|
30
|
-
-c, --config
|
|
31
|
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
--
|
|
41
|
-
--
|
|
42
|
-
|
|
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
|
|
43
44
|
```
|
|
44
45
|
|
|
45
46
|
Or run using [Docker](https://www.docker.com) and [GitHub Packages](https://github.com/features/packages):
|
|
@@ -88,7 +89,7 @@ Because this option makes changes to the input files, it is good to make a backu
|
|
|
88
89
|
|
|
89
90
|
`markdownlint-cli` reuses [the rules][rules] from `markdownlint` package.
|
|
90
91
|
|
|
91
|
-
Configuration is stored in JSON, JSONC, YAML, or
|
|
92
|
+
Configuration is stored in JSON, JSONC, YAML, INI, or TOML files in the same [config format][config].
|
|
92
93
|
|
|
93
94
|
A sample configuration file:
|
|
94
95
|
|
|
@@ -102,7 +103,7 @@ A sample configuration file:
|
|
|
102
103
|
}
|
|
103
104
|
```
|
|
104
105
|
|
|
105
|
-
For more examples, see [.markdownlint.jsonc][markdownlint-jsonc], [.markdownlint.yaml][markdownlint-yaml], or the [style folder][style-folder].
|
|
106
|
+
For more examples, see [.markdownlint.jsonc][markdownlint-jsonc], [.markdownlint.yaml][markdownlint-yaml], [test-config.toml](test/test-config.toml) or the [style folder][style-folder].
|
|
106
107
|
|
|
107
108
|
The CLI argument `--config` is not required.
|
|
108
109
|
If it is not provided, `markdownlint-cli` looks for the file `.markdownlint.jsonc`/`.markdownlint.json`/`.markdownlint.yaml`/`.markdownlint.yml` in current folder, or for the file `.markdownlintrc` in the current or all parent folders.
|
|
@@ -113,10 +114,14 @@ JS configuration files contain JavaScript code, must have the `.js` or `.cjs` fi
|
|
|
113
114
|
If your workspace _(project)_ is [ESM-only] _(`"type": "module"` set in the root `package.json` file)_, then the configuration file **should end with `.cjs` file extension**.
|
|
114
115
|
A JS configuration file may internally `require` one or more npm packages as a way of reusing configuration across projects.
|
|
115
116
|
|
|
117
|
+
The `--configPointer` argument allows the use of [JSON Pointer][json-pointer] syntax to identify a sub-object within the configuration object (per above).
|
|
118
|
+
This argument can be used with any configuration file type and makes it possible to nest a configuration object within another file like `package.json` or `pyproject.toml` (e.g., via `/key` or `/key/subkey`).
|
|
119
|
+
|
|
116
120
|
`--enable` and `--disable` override configuration files; if a configuration file disables `MD123` and you pass `--enable MD123`, it will be enabled.
|
|
117
121
|
If a rule is passed to both `--enable` and `--disable`, it will be disabled.
|
|
118
122
|
|
|
119
|
-
> JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
|
|
123
|
+
> - JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
|
|
124
|
+
> - TOML configuration files must be provided via the `--config` argument; they are not automatically loaded.
|
|
120
125
|
|
|
121
126
|
## Exit codes
|
|
122
127
|
|
|
@@ -134,7 +139,7 @@ To run `markdownlint-cli` as part of a [pre-commit][pre-commit] workflow, add so
|
|
|
134
139
|
|
|
135
140
|
```yaml
|
|
136
141
|
- repo: https://github.com/igorshubovych/markdownlint-cli
|
|
137
|
-
rev: v0.
|
|
142
|
+
rev: v0.40.0
|
|
138
143
|
hooks:
|
|
139
144
|
- id: markdownlint
|
|
140
145
|
```
|
|
@@ -155,6 +160,7 @@ MIT © Igor Shubovych
|
|
|
155
160
|
[actions-badge]: https://github.com/igorshubovych/markdownlint-cli/workflows/CI/badge.svg?branch=master
|
|
156
161
|
[actions-url]: https://github.com/igorshubovych/markdownlint-cli/actions?query=workflow%3ACI
|
|
157
162
|
[commander-variadic]: https://github.com/tj/commander.js#variadic-option
|
|
163
|
+
[json-pointer]: https://datatracker.ietf.org/doc/html/rfc6901
|
|
158
164
|
[markdownlint]: https://github.com/DavidAnson/markdownlint
|
|
159
165
|
[markdownlint-cli2]: https://github.com/DavidAnson/markdownlint-cli2
|
|
160
166
|
[markdownlint-jsonc]: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
|
package/markdownlint.js
CHANGED
|
@@ -7,11 +7,12 @@ const path = require('node:path');
|
|
|
7
7
|
const Module = require('node:module');
|
|
8
8
|
const os = require('node:os');
|
|
9
9
|
const process = require('node:process');
|
|
10
|
-
const program = require('commander');
|
|
10
|
+
const {program} = require('commander');
|
|
11
11
|
const glob = require('glob');
|
|
12
12
|
const markdownlint = require('markdownlint');
|
|
13
13
|
const rc = require('run-con');
|
|
14
14
|
const minimatch = require('minimatch');
|
|
15
|
+
const jsonpointer = require('jsonpointer');
|
|
15
16
|
const pkg = require('./package.json');
|
|
16
17
|
|
|
17
18
|
const options = program.opts();
|
|
@@ -36,6 +37,11 @@ function yamlParse(text) {
|
|
|
36
37
|
return require('js-yaml').load(text);
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
function tomlParse(text) {
|
|
41
|
+
// It is necessary to add the prototype manually because of https://github.com/BinaryMuse/toml-node/issues/55
|
|
42
|
+
return require('deep-extend')({}, require('toml').parse(text));
|
|
43
|
+
}
|
|
44
|
+
|
|
39
45
|
const exitCodes = {
|
|
40
46
|
lintFindings: 1,
|
|
41
47
|
failedToWriteOutputFile: 2,
|
|
@@ -44,13 +50,12 @@ const exitCodes = {
|
|
|
44
50
|
};
|
|
45
51
|
|
|
46
52
|
const projectConfigFiles = ['.markdownlint.jsonc', '.markdownlint.json', '.markdownlint.yaml', '.markdownlint.yml'];
|
|
47
|
-
|
|
53
|
+
// TOML files can be (incorrectly) read by yamlParse (but not vice versa), so tomlParse needs to go before yamlParse
|
|
54
|
+
const configParsers = [jsoncParse, tomlParse, yamlParse];
|
|
48
55
|
const fsOptions = {encoding: 'utf8'};
|
|
49
56
|
const processCwd = process.cwd();
|
|
50
57
|
|
|
51
58
|
function readConfiguration(userConfigFile) {
|
|
52
|
-
const jsConfigFile = /\.c?js$/i.test(userConfigFile);
|
|
53
|
-
|
|
54
59
|
// Load from well-known config files
|
|
55
60
|
let config = rc('markdownlint', {});
|
|
56
61
|
for (const projectConfigFile of projectConfigFiles) {
|
|
@@ -65,9 +70,10 @@ function readConfiguration(userConfigFile) {
|
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
// Normally parsing this file is not needed, because it is already parsed by rc package.
|
|
68
|
-
// However I have to do it to overwrite configuration from .markdownlint.{json,yaml,yml}.
|
|
73
|
+
// However I have to do it to overwrite configuration from .markdownlint.{jsonc,json,yaml,yml}.
|
|
69
74
|
if (userConfigFile) {
|
|
70
75
|
try {
|
|
76
|
+
const jsConfigFile = /\.c?js$/i.test(userConfigFile);
|
|
71
77
|
const userConfig = jsConfigFile ? require(path.resolve(processCwd, userConfigFile)) : markdownlint.readConfigSync(userConfigFile, configParsers);
|
|
72
78
|
config = require('deep-extend')(config, userConfig);
|
|
73
79
|
} catch (error) {
|
|
@@ -85,7 +91,10 @@ function prepareFileList(files, fileExtensions, previousResults) {
|
|
|
85
91
|
nodir: true
|
|
86
92
|
};
|
|
87
93
|
let extensionGlobPart = '*.';
|
|
88
|
-
if (fileExtensions
|
|
94
|
+
if (!fileExtensions) {
|
|
95
|
+
// Match everything
|
|
96
|
+
extensionGlobPart = '';
|
|
97
|
+
} else if (fileExtensions.length === 1) {
|
|
89
98
|
// Glob seems not to match patterns like 'foo.{js}'
|
|
90
99
|
extensionGlobPart += fileExtensions[0];
|
|
91
100
|
} else {
|
|
@@ -190,18 +199,19 @@ program
|
|
|
190
199
|
.version(pkg.version)
|
|
191
200
|
.description(pkg.description)
|
|
192
201
|
.usage('[options] <files|directories|globs>')
|
|
193
|
-
.option('-c, --config
|
|
202
|
+
.option('-c, --config <configFile>', 'configuration file (JSON, JSONC, JS, YAML, or TOML)')
|
|
203
|
+
.option('--configPointer <pointer>', 'JSON Pointer to object within configuration file', '')
|
|
194
204
|
.option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
|
|
195
205
|
.option('-f, --fix', 'fix basic errors (does not work with STDIN)')
|
|
196
|
-
.option('-i, --ignore
|
|
206
|
+
.option('-i, --ignore <file|directory|glob>', 'file(s) to ignore/exclude', concatArray, [])
|
|
197
207
|
.option('-j, --json', 'write issues in json format')
|
|
198
|
-
.option('-o, --output
|
|
199
|
-
.option('-p, --ignore-path
|
|
208
|
+
.option('-o, --output <outputFile>', 'write issues to file (no console)')
|
|
209
|
+
.option('-p, --ignore-path <file>', 'path to file with ignore pattern(s)')
|
|
200
210
|
.option('-q, --quiet', 'do not write issues to STDOUT')
|
|
201
|
-
.option('-r, --rules
|
|
211
|
+
.option('-r, --rules <file|directory|glob|package>', 'include custom rule files', concatArray, [])
|
|
202
212
|
.option('-s, --stdin', 'read from STDIN (does not work with files)')
|
|
203
|
-
.option('--enable
|
|
204
|
-
.option('--disable
|
|
213
|
+
.option('--enable <rules...>', 'Enable certain rules, e.g. --enable MD013 MD041 --')
|
|
214
|
+
.option('--disable <rules...>', 'Disable certain rules, e.g. --disable MD013 MD041 --');
|
|
205
215
|
|
|
206
216
|
program.parse(process.argv);
|
|
207
217
|
|
|
@@ -261,19 +271,18 @@ if (existsSync(ignorePath)) {
|
|
|
261
271
|
}
|
|
262
272
|
|
|
263
273
|
const files = prepareFileList(program.args, ['md', 'markdown']).filter(value => ignoreFilter(value));
|
|
264
|
-
const ignores = prepareFileList(options.ignore,
|
|
274
|
+
const ignores = prepareFileList(options.ignore, null, files);
|
|
265
275
|
const customRules = loadCustomRules(options.rules);
|
|
266
276
|
const diff = files.filter(file => !ignores.some(ignore => ignore.absolute === file.absolute)).map(paths => paths.original);
|
|
267
277
|
|
|
268
278
|
function lintAndPrint(stdin, files) {
|
|
269
|
-
files
|
|
270
|
-
const
|
|
279
|
+
files ||= [];
|
|
280
|
+
const configuration = readConfiguration(options.config);
|
|
281
|
+
const config = jsonpointer.get(configuration, options.configPointer) || {};
|
|
271
282
|
|
|
272
283
|
for (const rule of options.enable || []) {
|
|
273
284
|
// Leave default values in place if rule is an object
|
|
274
|
-
|
|
275
|
-
config[rule] = true;
|
|
276
|
-
}
|
|
285
|
+
config[rule] ||= true;
|
|
277
286
|
}
|
|
278
287
|
|
|
279
288
|
for (const rule of options.disable || []) {
|
|
@@ -324,9 +333,7 @@ try {
|
|
|
324
333
|
if (files.length > 0 && !options.stdin) {
|
|
325
334
|
lintAndPrint(null, diff);
|
|
326
335
|
} else if (files.length === 0 && options.stdin && !options.fix) {
|
|
327
|
-
import('get-stdin')
|
|
328
|
-
.then(module => module.default())
|
|
329
|
-
.then(lintAndPrint);
|
|
336
|
+
import('get-stdin').then(module => module.default()).then(lintAndPrint);
|
|
330
337
|
} else {
|
|
331
338
|
program.help();
|
|
332
339
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdownlint-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "MarkdownLint Command Line Interface",
|
|
5
5
|
"main": "markdownlint.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,21 +37,23 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"commander": "~
|
|
40
|
+
"commander": "~12.0.0",
|
|
41
41
|
"get-stdin": "~9.0.0",
|
|
42
|
-
"glob": "~10.3.
|
|
43
|
-
"ignore": "~5.3.
|
|
42
|
+
"glob": "~10.3.12",
|
|
43
|
+
"ignore": "~5.3.1",
|
|
44
44
|
"js-yaml": "^4.1.0",
|
|
45
45
|
"jsonc-parser": "~3.2.1",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
46
|
+
"jsonpointer": "5.0.1",
|
|
47
|
+
"markdownlint": "~0.34.0",
|
|
48
|
+
"minimatch": "~9.0.4",
|
|
49
|
+
"run-con": "~1.3.2",
|
|
50
|
+
"toml": "~3.0.0"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
|
-
"ava": "^6.1.
|
|
53
|
+
"ava": "^6.1.2",
|
|
52
54
|
"execa": "^8.0.1",
|
|
53
55
|
"markdownlint-cli-local-test-rule": "./test/custom-rules/markdownlint-cli-local-test-rule",
|
|
54
|
-
"xo": "^0.
|
|
56
|
+
"xo": "^0.58.0"
|
|
55
57
|
},
|
|
56
58
|
"xo": {
|
|
57
59
|
"prettier": true,
|