markdownlint-cli 0.27.1 → 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.
Files changed (3) hide show
  1. package/README.md +16 -6
  2. package/markdownlint.js +69 -34
  3. package/package.json +14 -12
package/README.md CHANGED
@@ -26,17 +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: [])
34
+ -j, --json write issues in json format
36
35
  -o, --output [outputFile] write issues to file (no console)
37
36
  -p, --ignore-path [file] path to file with ignore pattern(s)
38
- -r, --rules [file|directory|glob|package] custom rule files
37
+ -q, --quiet do not write issues to STDOUT
38
+ -r, --rules [file|directory|glob|package] include custom rule files (default: [])
39
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
40
43
  ```
41
44
 
42
45
  ### Globbing
@@ -99,6 +102,9 @@ If the `--config` argument is provided, the file must be valid JSON, JSONC, JS,
99
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.
100
103
  A JS configuration file may internally `require` one or more npm packages as a way of reusing configuration across projects.
101
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
+
102
108
  > JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
103
109
 
104
110
  ## Exit codes
@@ -112,15 +118,17 @@ A JS configuration file may internally `require` one or more npm packages as a w
112
118
 
113
119
  ## Use with pre-commit
114
120
 
115
- To run `markdownlint-cli` as part of a [pre-commit](https://pre-commit.com/) workflow, add something like the below to the `repos` list in the project's `.pre-commit-config.yaml`:
121
+ 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`:
116
122
 
117
123
  ```yaml
118
124
  - repo: https://github.com/igorshubovych/markdownlint-cli
119
- rev: v0.27.1
125
+ rev: v0.30.0
120
126
  hooks:
121
127
  - id: markdownlint
122
128
  ```
123
129
 
130
+ > 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].
131
+
124
132
  ## Related
125
133
 
126
134
  - [markdownlint][markdownlint] - API for this module
@@ -144,3 +152,5 @@ MIT © Igor Shubovych
144
152
  [globprimer]: https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer
145
153
  [ignore]: https://github.com/kaelzhang/node-ignore
146
154
  [gitignore]: https://git-scm.com/docs/gitignore
155
+ [pre-commit]: https://pre-commit.com/
156
+ [pre-commit-version]: https://pre-commit.com/#overriding-language-version
package/markdownlint.js CHANGED
@@ -5,17 +5,19 @@
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');
12
15
  const markdownlint = require('markdownlint');
13
- const rc = require('rc');
16
+ 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.warn('Cannot read or parse config file ' + userConfigFile + ': ' + error.message);
73
+ console.error(`Cannot read or parse config file '${userConfigFile}': ${error.message}`);
74
+ process.exitCode = 1;
72
75
  }
73
76
  }
74
77
 
@@ -131,30 +134,42 @@ function prepareFileList(files, fileExtensions, previousResults) {
131
134
  }
132
135
 
133
136
  function printResult(lintResult) {
134
- const results = flatten(Object.keys(lintResult).map(file => {
135
- return lintResult[file].map(result => {
137
+ const results = flatten(Object.keys(lintResult).map(file => lintResult[file].map(result => {
138
+ if (options.json) {
136
139
  return {
137
- file: file,
138
- lineNumber: result.lineNumber,
139
- column: (result.errorRange && result.errorRange[0]) || 0,
140
- names: result.ruleNames.join('/'),
141
- description: result.ruleDescription +
142
- (result.errorDetail ? ' [' + result.errorDetail + ']' : '') +
143
- (result.errorContext ? ' [Context: "' + result.errorContext + '"]' : '')
140
+ fileName: file,
141
+ ...result
144
142
  };
145
- });
146
- }));
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
+
147
156
  let lintResultString = '';
148
157
  if (results.length > 0) {
149
- results.sort((a, b) => {
150
- return a.file.localeCompare(b.file) || a.lineNumber - b.lineNumber ||
151
- a.names.localeCompare(b.names) || a.description.localeCompare(b.description);
152
- });
153
- lintResultString = results.map(result => {
154
- const {file, lineNumber, column, names, description} = result;
155
- const columnText = column ? `:${column}` : '';
156
- return `${file}:${lineNumber}${columnText} ${names} ${description}`;
157
- }).join('\n');
158
+ if (options.json) {
159
+ results.sort((a, b) => a.fileName.localeCompare(b.fileName) || a.lineNumber - b.lineNumber
160
+ || a.ruleDescription.localeCompare(b.ruleDescription));
161
+ lintResultString = JSON.stringify(results, null, 2);
162
+ } else {
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));
165
+
166
+ lintResultString = results.map(result => {
167
+ const {file, lineNumber, column, names, description} = result;
168
+ const columnText = column ? `:${column}` : '';
169
+ return `${file}:${lineNumber}${columnText} ${names} ${description}`;
170
+ }).join('\n');
171
+ }
172
+
158
173
  // Note: process.exit(1) will end abruptly, interrupting asynchronous IO
159
174
  // streams (e.g., when the output is being piped). Just set the exit code
160
175
  // and let the program terminate normally.
@@ -164,16 +179,16 @@ function printResult(lintResult) {
164
179
  }
165
180
 
166
181
  if (options.output) {
167
- lintResultString = lintResultString.length > 0 ?
168
- lintResultString + os.EOL :
169
- lintResultString;
182
+ lintResultString = lintResultString.length > 0
183
+ ? lintResultString + os.EOL
184
+ : lintResultString;
170
185
  try {
171
186
  fs.writeFileSync(options.output, lintResultString);
172
187
  } catch (error) {
173
188
  console.warn('Cannot write to output file ' + options.output + ': ' + error.message);
174
189
  process.exitCode = 2;
175
190
  }
176
- } else if (lintResultString) {
191
+ } else if (lintResultString && !options.quiet) {
177
192
  console.error(lintResultString);
178
193
  }
179
194
  }
@@ -191,10 +206,14 @@ program
191
206
  .option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
192
207
  .option('-f, --fix', 'fix basic errors (does not work with STDIN)')
193
208
  .option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
209
+ .option('-j, --json', 'write issues in json format')
194
210
  .option('-o, --output [outputFile]', 'write issues to file (no console)')
195
211
  .option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
196
- .option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, [])
197
- .option('-s, --stdin', 'read from STDIN (does not work with files)');
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');
198
217
 
199
218
  program.parse(process.argv);
200
219
 
@@ -235,7 +254,7 @@ function loadCustomRules(rules) {
235
254
  return fileList;
236
255
  } catch (error) {
237
256
  console.error('Cannot load custom rule ' + rule + ': ' + error.message);
238
- process.exit(3);
257
+ return process.exit(3);
239
258
  }
240
259
  }));
241
260
  }
@@ -268,6 +287,18 @@ const diff = differenceWith(files, ignores, function (a, b) {
268
287
  function lintAndPrint(stdin, files) {
269
288
  files = files || [];
270
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
+
271
302
  const lintOptions = {
272
303
  config,
273
304
  customRules,
@@ -279,6 +310,10 @@ function lintAndPrint(stdin, files) {
279
310
  };
280
311
  }
281
312
 
313
+ if (options.json) {
314
+ lintOptions.resultVersion = 3;
315
+ }
316
+
282
317
  if (options.fix) {
283
318
  const fixOptions = {
284
319
  ...lintOptions,
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "markdownlint-cli",
3
- "version": "0.27.1",
3
+ "version": "0.30.0",
4
4
  "description": "MarkdownLint Command Line Interface",
5
5
  "main": "markdownlint.js",
6
6
  "bin": {
7
7
  "markdownlint": "markdownlint.js"
8
8
  },
9
9
  "engines": {
10
- "node": ">=10"
10
+ "node": ">=12"
11
11
  },
12
12
  "scripts": {
13
13
  "invalid": "node ./markdownlint.js --config test/test-config.json -- test/incorrect.md",
@@ -37,37 +37,39 @@
37
37
  },
38
38
  "homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
39
39
  "dependencies": {
40
- "commander": "~7.1.0",
40
+ "commander": "~8.3.0",
41
41
  "deep-extend": "~0.6.0",
42
42
  "get-stdin": "~8.0.0",
43
- "glob": "~7.1.6",
44
- "ignore": "~5.1.8",
45
- "js-yaml": "^4.0.0",
43
+ "glob": "~7.2.0",
44
+ "ignore": "~5.1.9",
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.23.1",
50
- "markdownlint-rule-helpers": "~0.14.0",
49
+ "markdownlint": "~0.24.0",
50
+ "markdownlint-rule-helpers": "~0.15.0",
51
51
  "minimatch": "~3.0.4",
52
52
  "minimist": "~1.2.5",
53
- "rc": "~1.2.8"
53
+ "run-con": "~1.2.10"
54
54
  },
55
55
  "devDependencies": {
56
56
  "ava": "^3.15.0",
57
- "execa": "^5.0.0",
58
- "husky": "^5.1.2",
57
+ "execa": "^5.1.1",
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.38.2"
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
  },