markdownlint-cli 0.29.0 → 0.30.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 +10 -5
- package/markdownlint.js +56 -43
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -26,18 +26,20 @@ markdownlint --help
|
|
|
26
26
|
MarkdownLint Command Line Interface
|
|
27
27
|
|
|
28
28
|
Options:
|
|
29
|
-
|
|
30
|
-
-h, --help output usage information
|
|
31
29
|
-V, --version output the version number
|
|
32
30
|
-c, --config [configFile] configuration file (JSON, JSONC, JS, or YAML)
|
|
33
31
|
-d, --dot include files/folders with a dot (for example `.github`)
|
|
34
32
|
-f, --fix fix basic errors (does not work with STDIN)
|
|
35
|
-
-i, --ignore [file|directory|glob] file(s) to ignore/exclude
|
|
33
|
+
-i, --ignore [file|directory|glob] file(s) to ignore/exclude (default: [])
|
|
36
34
|
-j, --json write issues in json format
|
|
37
35
|
-o, --output [outputFile] write issues to file (no console)
|
|
38
36
|
-p, --ignore-path [file] path to file with ignore pattern(s)
|
|
39
|
-
-
|
|
37
|
+
-q, --quiet do not write issues to STDOUT
|
|
38
|
+
-r, --rules [file|directory|glob|package] include custom rule files (default: [])
|
|
40
39
|
-s, --stdin read from STDIN (does not work with files)
|
|
40
|
+
--enable [rules...] Enable certain rules, e.g. --enable MD013 MD041
|
|
41
|
+
--disable [rules...] Disable certain rules, e.g. --disable MD013 MD041
|
|
42
|
+
-h, --help display help for command
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
### Globbing
|
|
@@ -100,6 +102,9 @@ If the `--config` argument is provided, the file must be valid JSON, JSONC, JS,
|
|
|
100
102
|
JS configuration files contain JavaScript code, must have the `.js` extension, and must export (via `module.exports = ...`) a configuration object of the form shown above.
|
|
101
103
|
A JS configuration file may internally `require` one or more npm packages as a way of reusing configuration across projects.
|
|
102
104
|
|
|
105
|
+
`--enable` and `--disable` override configuration files; if a configuration file disables `MD002` and you pass `--enable MD002`, it will be enabled.
|
|
106
|
+
If a rule is passed to both `--enable` and `--disable`, it will be disabled.
|
|
107
|
+
|
|
103
108
|
> JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
|
|
104
109
|
|
|
105
110
|
## Exit codes
|
|
@@ -117,7 +122,7 @@ To run `markdownlint-cli` as part of a [pre-commit][pre-commit] workflow, add so
|
|
|
117
122
|
|
|
118
123
|
```yaml
|
|
119
124
|
- repo: https://github.com/igorshubovych/markdownlint-cli
|
|
120
|
-
rev: v0.
|
|
125
|
+
rev: v0.30.0
|
|
121
126
|
hooks:
|
|
122
127
|
- id: markdownlint
|
|
123
128
|
```
|
package/markdownlint.js
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const Module = require('module');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
const process = require('process');
|
|
8
10
|
const program = require('commander');
|
|
11
|
+
|
|
9
12
|
const options = program.opts();
|
|
10
13
|
const differenceWith = require('lodash.differencewith');
|
|
11
14
|
const flatten = require('lodash.flatten');
|
|
@@ -14,8 +17,7 @@ const rc = require('run-con');
|
|
|
14
17
|
const glob = require('glob');
|
|
15
18
|
const minimatch = require('minimatch');
|
|
16
19
|
const minimist = require('minimist');
|
|
17
|
-
const pkg = require('./package');
|
|
18
|
-
const os = require('os');
|
|
20
|
+
const pkg = require('./package.json');
|
|
19
21
|
|
|
20
22
|
function jsoncParse(text) {
|
|
21
23
|
return JSON.parse(require('jsonc-parser').stripComments(text));
|
|
@@ -61,14 +63,15 @@ function readConfiguration(userConfigFile) {
|
|
|
61
63
|
// from .markdownlint.{json,yaml,yml}.
|
|
62
64
|
if (userConfigFile) {
|
|
63
65
|
try {
|
|
64
|
-
const userConfig = jsConfigFile
|
|
66
|
+
const userConfig = jsConfigFile
|
|
65
67
|
// Evaluate .js configuration file as code
|
|
66
|
-
require(path.resolve(processCwd, userConfigFile))
|
|
68
|
+
? require(path.resolve(processCwd, userConfigFile))
|
|
67
69
|
// Load JSON/YAML configuration as data
|
|
68
|
-
markdownlint.readConfigSync(userConfigFile, configFileParsers);
|
|
70
|
+
: markdownlint.readConfigSync(userConfigFile, configFileParsers);
|
|
69
71
|
config = require('deep-extend')(config, userConfig);
|
|
70
72
|
} catch (error) {
|
|
71
|
-
console.
|
|
73
|
+
console.error(`Cannot read or parse config file '${userConfigFile}': ${error.message}`);
|
|
74
|
+
process.exitCode = 1;
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
|
|
@@ -131,41 +134,34 @@ function prepareFileList(files, fileExtensions, previousResults) {
|
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
function printResult(lintResult) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
(result.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
}));
|
|
155
|
-
|
|
137
|
+
const results = flatten(Object.keys(lintResult).map(file => lintResult[file].map(result => {
|
|
138
|
+
if (options.json) {
|
|
139
|
+
return {
|
|
140
|
+
fileName: file,
|
|
141
|
+
...result
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
file: file,
|
|
147
|
+
lineNumber: result.lineNumber,
|
|
148
|
+
column: (result.errorRange && result.errorRange[0]) || 0,
|
|
149
|
+
names: result.ruleNames.join('/'),
|
|
150
|
+
description: result.ruleDescription
|
|
151
|
+
+ (result.errorDetail ? ' [' + result.errorDetail + ']' : '')
|
|
152
|
+
+ (result.errorContext ? ' [Context: "' + result.errorContext + '"]' : '')
|
|
153
|
+
};
|
|
154
|
+
})));
|
|
155
|
+
|
|
156
156
|
let lintResultString = '';
|
|
157
157
|
if (results.length > 0) {
|
|
158
158
|
if (options.json) {
|
|
159
|
-
results.sort((a, b) =>
|
|
160
|
-
|
|
161
|
-
a.ruleDescription.localeCompare(b.ruleDescription);
|
|
162
|
-
});
|
|
159
|
+
results.sort((a, b) => a.fileName.localeCompare(b.fileName) || a.lineNumber - b.lineNumber
|
|
160
|
+
|| a.ruleDescription.localeCompare(b.ruleDescription));
|
|
163
161
|
lintResultString = JSON.stringify(results, null, 2);
|
|
164
162
|
} else {
|
|
165
|
-
results.sort((a, b) =>
|
|
166
|
-
|
|
167
|
-
a.names.localeCompare(b.names) || a.description.localeCompare(b.description);
|
|
168
|
-
});
|
|
163
|
+
results.sort((a, b) => a.file.localeCompare(b.file) || a.lineNumber - b.lineNumber
|
|
164
|
+
|| a.names.localeCompare(b.names) || a.description.localeCompare(b.description));
|
|
169
165
|
|
|
170
166
|
lintResultString = results.map(result => {
|
|
171
167
|
const {file, lineNumber, column, names, description} = result;
|
|
@@ -173,6 +169,7 @@ function printResult(lintResult) {
|
|
|
173
169
|
return `${file}:${lineNumber}${columnText} ${names} ${description}`;
|
|
174
170
|
}).join('\n');
|
|
175
171
|
}
|
|
172
|
+
|
|
176
173
|
// Note: process.exit(1) will end abruptly, interrupting asynchronous IO
|
|
177
174
|
// streams (e.g., when the output is being piped). Just set the exit code
|
|
178
175
|
// and let the program terminate normally.
|
|
@@ -182,16 +179,16 @@ function printResult(lintResult) {
|
|
|
182
179
|
}
|
|
183
180
|
|
|
184
181
|
if (options.output) {
|
|
185
|
-
lintResultString = lintResultString.length > 0
|
|
186
|
-
lintResultString + os.EOL
|
|
187
|
-
lintResultString;
|
|
182
|
+
lintResultString = lintResultString.length > 0
|
|
183
|
+
? lintResultString + os.EOL
|
|
184
|
+
: lintResultString;
|
|
188
185
|
try {
|
|
189
186
|
fs.writeFileSync(options.output, lintResultString);
|
|
190
187
|
} catch (error) {
|
|
191
188
|
console.warn('Cannot write to output file ' + options.output + ': ' + error.message);
|
|
192
189
|
process.exitCode = 2;
|
|
193
190
|
}
|
|
194
|
-
} else if (lintResultString) {
|
|
191
|
+
} else if (lintResultString && !options.quiet) {
|
|
195
192
|
console.error(lintResultString);
|
|
196
193
|
}
|
|
197
194
|
}
|
|
@@ -212,8 +209,11 @@ program
|
|
|
212
209
|
.option('-j, --json', 'write issues in json format')
|
|
213
210
|
.option('-o, --output [outputFile]', 'write issues to file (no console)')
|
|
214
211
|
.option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
|
|
215
|
-
.option('-
|
|
216
|
-
.option('-
|
|
212
|
+
.option('-q, --quiet', 'do not write issues to STDOUT')
|
|
213
|
+
.option('-r, --rules [file|directory|glob|package]', 'include custom rule files', concatArray, [])
|
|
214
|
+
.option('-s, --stdin', 'read from STDIN (does not work with files)')
|
|
215
|
+
.option('--enable [rules...]', 'Enable certain rules, e.g. --enable MD013 MD041')
|
|
216
|
+
.option('--disable [rules...]', 'Disable certain rules, e.g. --disable MD013 MD041');
|
|
217
217
|
|
|
218
218
|
program.parse(process.argv);
|
|
219
219
|
|
|
@@ -254,7 +254,7 @@ function loadCustomRules(rules) {
|
|
|
254
254
|
return fileList;
|
|
255
255
|
} catch (error) {
|
|
256
256
|
console.error('Cannot load custom rule ' + rule + ': ' + error.message);
|
|
257
|
-
process.exit(3);
|
|
257
|
+
return process.exit(3);
|
|
258
258
|
}
|
|
259
259
|
}));
|
|
260
260
|
}
|
|
@@ -287,6 +287,18 @@ const diff = differenceWith(files, ignores, function (a, b) {
|
|
|
287
287
|
function lintAndPrint(stdin, files) {
|
|
288
288
|
files = files || [];
|
|
289
289
|
const config = readConfiguration(options.config);
|
|
290
|
+
|
|
291
|
+
for (const rule of options.enable || []) {
|
|
292
|
+
// Leave default values in place if rule is an object
|
|
293
|
+
if (!config[rule]) {
|
|
294
|
+
config[rule] = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
for (const rule of options.disable || []) {
|
|
299
|
+
config[rule] = false;
|
|
300
|
+
}
|
|
301
|
+
|
|
290
302
|
const lintOptions = {
|
|
291
303
|
config,
|
|
292
304
|
customRules,
|
|
@@ -297,6 +309,7 @@ function lintAndPrint(stdin, files) {
|
|
|
297
309
|
stdin
|
|
298
310
|
};
|
|
299
311
|
}
|
|
312
|
+
|
|
300
313
|
if (options.json) {
|
|
301
314
|
lintOptions.resultVersion = 3;
|
|
302
315
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdownlint-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "MarkdownLint Command Line Interface",
|
|
5
5
|
"main": "markdownlint.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"commander": "~8.
|
|
40
|
+
"commander": "~8.3.0",
|
|
41
41
|
"deep-extend": "~0.6.0",
|
|
42
42
|
"get-stdin": "~8.0.0",
|
|
43
43
|
"glob": "~7.2.0",
|
|
44
|
-
"ignore": "~5.1.
|
|
44
|
+
"ignore": "~5.1.9",
|
|
45
45
|
"js-yaml": "^4.1.0",
|
|
46
46
|
"jsonc-parser": "~3.0.0",
|
|
47
47
|
"lodash.differencewith": "~4.5.0",
|
|
@@ -55,19 +55,21 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"ava": "^3.15.0",
|
|
57
57
|
"execa": "^5.1.1",
|
|
58
|
-
"husky": "^7.0.
|
|
58
|
+
"husky": "^7.0.4",
|
|
59
59
|
"tap-growl": "^3.0.0",
|
|
60
60
|
"test-rule-package": "./test/custom-rules/test-rule-package",
|
|
61
|
-
"xo": "^0.
|
|
61
|
+
"xo": "^0.46.4"
|
|
62
62
|
},
|
|
63
63
|
"xo": {
|
|
64
64
|
"space": true,
|
|
65
65
|
"rules": {
|
|
66
|
+
"comma-dangle": 0,
|
|
66
67
|
"linebreak-style": 0,
|
|
67
68
|
"no-var": 0,
|
|
68
69
|
"prefer-arrow-callback": 0,
|
|
69
70
|
"promise/prefer-await-to-then": 0,
|
|
70
71
|
"object-shorthand": 0,
|
|
72
|
+
"unicorn/prefer-module": 0,
|
|
71
73
|
"unicorn/prefer-ternary": 0
|
|
72
74
|
}
|
|
73
75
|
},
|