markdownlint-cli 0.26.0 → 0.28.1
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 -7
- package/markdownlint.js +68 -39
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -29,13 +29,15 @@ markdownlint --help
|
|
|
29
29
|
|
|
30
30
|
-h, --help output usage information
|
|
31
31
|
-V, --version output the version number
|
|
32
|
-
-f, --fix fix basic errors (does not work with STDIN)
|
|
33
|
-
-s, --stdin read from STDIN (does not work with files)
|
|
34
|
-
-o, --output [outputFile] write issues to file (no console)
|
|
35
32
|
-c, --config [configFile] configuration file (JSON, JSONC, JS, or YAML)
|
|
33
|
+
-d, --dot include files/folders with a dot (for example `.github`)
|
|
34
|
+
-f, --fix fix basic errors (does not work with STDIN)
|
|
36
35
|
-i, --ignore [file|directory|glob] file(s) to ignore/exclude
|
|
36
|
+
-j, --json write issues in json format
|
|
37
|
+
-o, --output [outputFile] write issues to file (no console)
|
|
37
38
|
-p, --ignore-path [file] path to file with ignore pattern(s)
|
|
38
39
|
-r, --rules [file|directory|glob|package] custom rule files
|
|
40
|
+
-s, --stdin read from STDIN (does not work with files)
|
|
39
41
|
```
|
|
40
42
|
|
|
41
43
|
### Globbing
|
|
@@ -77,7 +79,7 @@ Because this option makes changes to the input files, it is good to make a backu
|
|
|
77
79
|
|
|
78
80
|
Configuration is stored in JSON, JSONC, YAML, or INI files in the same [config format][config].
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
A sample configuration file:
|
|
81
83
|
|
|
82
84
|
```json
|
|
83
85
|
{
|
|
@@ -89,7 +91,7 @@ The example of configuration file:
|
|
|
89
91
|
}
|
|
90
92
|
```
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
For more examples, see [.markdownlint.jsonc][markdownlint-jsonc], [.markdownlint.yaml][markdownlint-yaml], or the [style folder][style-folder].
|
|
93
95
|
|
|
94
96
|
The CLI argument `--config` is not required.
|
|
95
97
|
If it is not provided, `markdownlint-cli` looks for the file `.markdownlint.json`/`.markdownlint.yaml`/`.markdownlint.yml` in current folder, or for the file `.markdownlintrc` in the current or all parent folders.
|
|
@@ -109,6 +111,19 @@ A JS configuration file may internally `require` one or more npm packages as a w
|
|
|
109
111
|
- `2`: Unable to write `-o`/`--output` output file
|
|
110
112
|
- `3`: Unable to load `-r`/`--rules` custom rule
|
|
111
113
|
|
|
114
|
+
## Use with pre-commit
|
|
115
|
+
|
|
116
|
+
To run `markdownlint-cli` as part of a [pre-commit][pre-commit] workflow, add something like the below to the `repos` list in the project's `.pre-commit-config.yaml`:
|
|
117
|
+
|
|
118
|
+
```yaml
|
|
119
|
+
- repo: https://github.com/igorshubovych/markdownlint-cli
|
|
120
|
+
rev: v0.28.1
|
|
121
|
+
hooks:
|
|
122
|
+
- id: markdownlint
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
> Depending on the environment this workflow runs in, it may be necessary to [override the language version of Node.js used by pre-commit][pre-commit-version].
|
|
126
|
+
|
|
112
127
|
## Related
|
|
113
128
|
|
|
114
129
|
- [markdownlint][markdownlint] - API for this module
|
|
@@ -121,14 +136,16 @@ MIT © Igor Shubovych
|
|
|
121
136
|
|
|
122
137
|
[actions-badge]: https://github.com/igorshubovych/markdownlint-cli/workflows/CI/badge.svg?branch=master
|
|
123
138
|
[actions-url]: https://github.com/igorshubovych/markdownlint-cli/actions?query=workflow%3ACI
|
|
124
|
-
|
|
125
139
|
[markdownlint]: https://github.com/DavidAnson/markdownlint
|
|
140
|
+
[markdownlint-jsonc]: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
|
|
141
|
+
[markdownlint-yaml]: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml
|
|
126
142
|
[rules]: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
|
|
127
143
|
[config]: https://github.com/DavidAnson/markdownlint#optionsconfig
|
|
128
144
|
[style-folder]: https://github.com/DavidAnson/markdownlint/tree/main/style
|
|
129
|
-
[test-config]: https://github.com/igorshubovych/markdownlint-cli/blob/master/test/test-config.json
|
|
130
145
|
[rc-standards]: https://www.npmjs.com/package/rc#standards
|
|
131
146
|
[glob]: https://github.com/isaacs/node-glob
|
|
132
147
|
[globprimer]: https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer
|
|
133
148
|
[ignore]: https://github.com/kaelzhang/node-ignore
|
|
134
149
|
[gitignore]: https://git-scm.com/docs/gitignore
|
|
150
|
+
[pre-commit]: https://pre-commit.com/
|
|
151
|
+
[pre-commit-version]: https://pre-commit.com/#overriding-language-version
|
package/markdownlint.js
CHANGED
|
@@ -6,21 +6,23 @@ const fs = require('fs');
|
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const Module = require('module');
|
|
8
8
|
const program = require('commander');
|
|
9
|
+
const options = program.opts();
|
|
9
10
|
const differenceWith = require('lodash.differencewith');
|
|
10
11
|
const flatten = require('lodash.flatten');
|
|
11
12
|
const markdownlint = require('markdownlint');
|
|
12
|
-
const rc = require('
|
|
13
|
+
const rc = require('run-con');
|
|
13
14
|
const glob = require('glob');
|
|
14
15
|
const minimatch = require('minimatch');
|
|
15
16
|
const minimist = require('minimist');
|
|
16
17
|
const pkg = require('./package');
|
|
18
|
+
const os = require('os');
|
|
17
19
|
|
|
18
20
|
function jsoncParse(text) {
|
|
19
21
|
return JSON.parse(require('jsonc-parser').stripComments(text));
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
function jsYamlSafeLoad(text) {
|
|
23
|
-
return require('js-yaml').
|
|
25
|
+
return require('js-yaml').load(text);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
const projectConfigFiles = [
|
|
@@ -32,8 +34,7 @@ const configFileParsers = [jsoncParse, jsYamlSafeLoad];
|
|
|
32
34
|
const fsOptions = {encoding: 'utf8'};
|
|
33
35
|
const processCwd = process.cwd();
|
|
34
36
|
|
|
35
|
-
function readConfiguration(
|
|
36
|
-
const userConfigFile = args.config;
|
|
37
|
+
function readConfiguration(userConfigFile) {
|
|
37
38
|
const jsConfigFile = /\.js$/i.test(userConfigFile);
|
|
38
39
|
const rcArgv = minimist(process.argv.slice(2));
|
|
39
40
|
if (jsConfigFile) {
|
|
@@ -76,6 +77,7 @@ function readConfiguration(args) {
|
|
|
76
77
|
|
|
77
78
|
function prepareFileList(files, fileExtensions, previousResults) {
|
|
78
79
|
const globOptions = {
|
|
80
|
+
dot: Boolean(options.dot),
|
|
79
81
|
nodir: true
|
|
80
82
|
};
|
|
81
83
|
let extensionGlobPart = '*.';
|
|
@@ -129,30 +131,48 @@ function prepareFileList(files, fileExtensions, previousResults) {
|
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
function printResult(lintResult) {
|
|
134
|
+
|
|
132
135
|
const results = flatten(Object.keys(lintResult).map(file => {
|
|
133
136
|
return lintResult[file].map(result => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
137
|
+
if (options.json) {
|
|
138
|
+
return {
|
|
139
|
+
fileName: file,
|
|
140
|
+
...result
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
return {
|
|
144
|
+
file: file,
|
|
145
|
+
lineNumber: result.lineNumber,
|
|
146
|
+
column: (result.errorRange && result.errorRange[0]) || 0,
|
|
147
|
+
names: result.ruleNames.join('/'),
|
|
148
|
+
description: result.ruleDescription +
|
|
149
|
+
(result.errorDetail ? ' [' + result.errorDetail + ']' : '') +
|
|
150
|
+
(result.errorContext ? ' [Context: "' + result.errorContext + '"]' : '')
|
|
151
|
+
};
|
|
152
|
+
}
|
|
143
153
|
});
|
|
144
154
|
}));
|
|
155
|
+
|
|
145
156
|
let lintResultString = '';
|
|
146
157
|
if (results.length > 0) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
a.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
if (options.json) {
|
|
159
|
+
results.sort((a, b) => {
|
|
160
|
+
return a.fileName.localeCompare(b.fileName) || a.lineNumber - b.lineNumber ||
|
|
161
|
+
a.ruleDescription.localeCompare(b.ruleDescription);
|
|
162
|
+
});
|
|
163
|
+
lintResultString = JSON.stringify(results, null, 2);
|
|
164
|
+
} else {
|
|
165
|
+
results.sort((a, b) => {
|
|
166
|
+
return a.file.localeCompare(b.file) || a.lineNumber - b.lineNumber ||
|
|
167
|
+
a.names.localeCompare(b.names) || a.description.localeCompare(b.description);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
lintResultString = results.map(result => {
|
|
171
|
+
const {file, lineNumber, column, names, description} = result;
|
|
172
|
+
const columnText = column ? `:${column}` : '';
|
|
173
|
+
return `${file}:${lineNumber}${columnText} ${names} ${description}`;
|
|
174
|
+
}).join('\n');
|
|
175
|
+
}
|
|
156
176
|
// Note: process.exit(1) will end abruptly, interrupting asynchronous IO
|
|
157
177
|
// streams (e.g., when the output is being piped). Just set the exit code
|
|
158
178
|
// and let the program terminate normally.
|
|
@@ -161,11 +181,14 @@ function printResult(lintResult) {
|
|
|
161
181
|
process.exitCode = 1;
|
|
162
182
|
}
|
|
163
183
|
|
|
164
|
-
if (
|
|
184
|
+
if (options.output) {
|
|
185
|
+
lintResultString = lintResultString.length > 0 ?
|
|
186
|
+
lintResultString + os.EOL :
|
|
187
|
+
lintResultString;
|
|
165
188
|
try {
|
|
166
|
-
fs.writeFileSync(
|
|
189
|
+
fs.writeFileSync(options.output, lintResultString);
|
|
167
190
|
} catch (error) {
|
|
168
|
-
console.warn('Cannot write to output file ' +
|
|
191
|
+
console.warn('Cannot write to output file ' + options.output + ': ' + error.message);
|
|
169
192
|
process.exitCode = 2;
|
|
170
193
|
}
|
|
171
194
|
} else if (lintResultString) {
|
|
@@ -182,13 +205,15 @@ program
|
|
|
182
205
|
.version(pkg.version)
|
|
183
206
|
.description(pkg.description)
|
|
184
207
|
.usage('[options] <files|directories|globs>')
|
|
185
|
-
.option('-f, --fix', 'fix basic errors (does not work with STDIN)')
|
|
186
|
-
.option('-s, --stdin', 'read from STDIN (does not work with files)')
|
|
187
|
-
.option('-o, --output [outputFile]', 'write issues to file (no console)')
|
|
188
208
|
.option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)')
|
|
209
|
+
.option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
|
|
210
|
+
.option('-f, --fix', 'fix basic errors (does not work with STDIN)')
|
|
189
211
|
.option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
|
|
212
|
+
.option('-j, --json', 'write issues in json format')
|
|
213
|
+
.option('-o, --output [outputFile]', 'write issues to file (no console)')
|
|
190
214
|
.option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
|
|
191
|
-
.option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, [])
|
|
215
|
+
.option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, [])
|
|
216
|
+
.option('-s, --stdin', 'read from STDIN (does not work with files)');
|
|
192
217
|
|
|
193
218
|
program.parse(process.argv);
|
|
194
219
|
|
|
@@ -198,6 +223,7 @@ function tryResolvePath(filepath) {
|
|
|
198
223
|
// Looks like a package name, resolve it relative to cwd
|
|
199
224
|
// Get list of directories, where requested module can be.
|
|
200
225
|
let paths = Module._nodeModulePaths(processCwd);
|
|
226
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
201
227
|
paths = paths.concat(Module.globalPaths);
|
|
202
228
|
if (require.resolve.paths) {
|
|
203
229
|
// Node >= 8.9.0
|
|
@@ -235,8 +261,8 @@ function loadCustomRules(rules) {
|
|
|
235
261
|
|
|
236
262
|
let ignorePath = '.markdownlintignore';
|
|
237
263
|
let {existsSync} = fs;
|
|
238
|
-
if (
|
|
239
|
-
ignorePath =
|
|
264
|
+
if (options.ignorePath) {
|
|
265
|
+
ignorePath = options.ignorePath;
|
|
240
266
|
existsSync = () => true;
|
|
241
267
|
}
|
|
242
268
|
|
|
@@ -250,8 +276,8 @@ if (existsSync(ignorePath)) {
|
|
|
250
276
|
|
|
251
277
|
const files = prepareFileList(program.args, ['md', 'markdown'])
|
|
252
278
|
.filter(value => ignoreFilter(value));
|
|
253
|
-
const ignores = prepareFileList(
|
|
254
|
-
const customRules = loadCustomRules(
|
|
279
|
+
const ignores = prepareFileList(options.ignore, ['md', 'markdown'], files);
|
|
280
|
+
const customRules = loadCustomRules(options.rules);
|
|
255
281
|
const diff = differenceWith(files, ignores, function (a, b) {
|
|
256
282
|
return a.absolute === b.absolute;
|
|
257
283
|
}).map(function (paths) {
|
|
@@ -260,7 +286,7 @@ const diff = differenceWith(files, ignores, function (a, b) {
|
|
|
260
286
|
|
|
261
287
|
function lintAndPrint(stdin, files) {
|
|
262
288
|
files = files || [];
|
|
263
|
-
const config = readConfiguration(
|
|
289
|
+
const config = readConfiguration(options.config);
|
|
264
290
|
const lintOptions = {
|
|
265
291
|
config,
|
|
266
292
|
customRules,
|
|
@@ -271,14 +297,17 @@ function lintAndPrint(stdin, files) {
|
|
|
271
297
|
stdin
|
|
272
298
|
};
|
|
273
299
|
}
|
|
300
|
+
if (options.json) {
|
|
301
|
+
lintOptions.resultVersion = 3;
|
|
302
|
+
}
|
|
274
303
|
|
|
275
|
-
if (
|
|
304
|
+
if (options.fix) {
|
|
276
305
|
const fixOptions = {
|
|
277
306
|
...lintOptions,
|
|
278
307
|
resultVersion: 3
|
|
279
308
|
};
|
|
280
309
|
const markdownlintRuleHelpers = require('markdownlint-rule-helpers');
|
|
281
|
-
|
|
310
|
+
for (const file of files) {
|
|
282
311
|
fixOptions.files = [file];
|
|
283
312
|
const fixResult = markdownlint.sync(fixOptions);
|
|
284
313
|
const fixes = fixResult[file].filter(error => error.fixInfo);
|
|
@@ -289,16 +318,16 @@ function lintAndPrint(stdin, files) {
|
|
|
289
318
|
fs.writeFileSync(file, fixedText, fsOptions);
|
|
290
319
|
}
|
|
291
320
|
}
|
|
292
|
-
}
|
|
321
|
+
}
|
|
293
322
|
}
|
|
294
323
|
|
|
295
324
|
const lintResult = markdownlint.sync(lintOptions);
|
|
296
325
|
printResult(lintResult);
|
|
297
326
|
}
|
|
298
327
|
|
|
299
|
-
if ((files.length > 0) && !
|
|
328
|
+
if ((files.length > 0) && !options.stdin) {
|
|
300
329
|
lintAndPrint(null, diff);
|
|
301
|
-
} else if ((files.length === 0) &&
|
|
330
|
+
} else if ((files.length === 0) && options.stdin && !options.fix) {
|
|
302
331
|
const getStdin = require('get-stdin');
|
|
303
332
|
getStdin().then(lintAndPrint);
|
|
304
333
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdownlint-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.1",
|
|
4
4
|
"description": "MarkdownLint Command Line Interface",
|
|
5
5
|
"main": "markdownlint.js",
|
|
6
6
|
"bin": {
|
|
@@ -37,28 +37,28 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"commander": "~
|
|
40
|
+
"commander": "~8.0.0",
|
|
41
41
|
"deep-extend": "~0.6.0",
|
|
42
42
|
"get-stdin": "~8.0.0",
|
|
43
|
-
"glob": "~7.1.
|
|
43
|
+
"glob": "~7.1.7",
|
|
44
44
|
"ignore": "~5.1.8",
|
|
45
|
-
"js-yaml": "
|
|
45
|
+
"js-yaml": "^4.1.0",
|
|
46
46
|
"jsonc-parser": "~3.0.0",
|
|
47
47
|
"lodash.differencewith": "~4.5.0",
|
|
48
48
|
"lodash.flatten": "~4.4.0",
|
|
49
|
-
"markdownlint": "~0.
|
|
50
|
-
"markdownlint-rule-helpers": "~0.
|
|
49
|
+
"markdownlint": "~0.23.1",
|
|
50
|
+
"markdownlint-rule-helpers": "~0.14.0",
|
|
51
51
|
"minimatch": "~3.0.4",
|
|
52
52
|
"minimist": "~1.2.5",
|
|
53
|
-
"
|
|
53
|
+
"run-con": "~1.2.10"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"ava": "^3.
|
|
57
|
-
"execa": "^5.
|
|
58
|
-
"husky": "^
|
|
56
|
+
"ava": "^3.15.0",
|
|
57
|
+
"execa": "^5.1.1",
|
|
58
|
+
"husky": "^7.0.1",
|
|
59
59
|
"tap-growl": "^3.0.0",
|
|
60
60
|
"test-rule-package": "./test/custom-rules/test-rule-package",
|
|
61
|
-
"xo": "^0.
|
|
61
|
+
"xo": "^0.42.0"
|
|
62
62
|
},
|
|
63
63
|
"xo": {
|
|
64
64
|
"space": true,
|