markdownlint-cli 0.27.1 → 0.28.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 CHANGED
@@ -33,6 +33,7 @@ markdownlint --help
33
33
  -d, --dot include files/folders with a dot (for example `.github`)
34
34
  -f, --fix fix basic errors (does not work with STDIN)
35
35
  -i, --ignore [file|directory|glob] file(s) to ignore/exclude
36
+ -j, --json write issues in json format
36
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
@@ -112,15 +113,17 @@ A JS configuration file may internally `require` one or more npm packages as a w
112
113
 
113
114
  ## Use with pre-commit
114
115
 
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`:
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`:
116
117
 
117
118
  ```yaml
118
119
  - repo: https://github.com/igorshubovych/markdownlint-cli
119
- rev: v0.27.1
120
+ rev: v0.28.0
120
121
  hooks:
121
122
  - id: markdownlint
122
123
  ```
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
+
124
127
  ## Related
125
128
 
126
129
  - [markdownlint][markdownlint] - API for this module
@@ -144,3 +147,5 @@ MIT © Igor Shubovych
144
147
  [globprimer]: https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer
145
148
  [ignore]: https://github.com/kaelzhang/node-ignore
146
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
@@ -131,30 +131,48 @@ function prepareFileList(files, fileExtensions, previousResults) {
131
131
  }
132
132
 
133
133
  function printResult(lintResult) {
134
+
134
135
  const results = flatten(Object.keys(lintResult).map(file => {
135
136
  return lintResult[file].map(result => {
136
- 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 + '"]' : '')
144
- };
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
+ }
145
153
  });
146
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) => {
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
+ }
158
176
  // Note: process.exit(1) will end abruptly, interrupting asynchronous IO
159
177
  // streams (e.g., when the output is being piped). Just set the exit code
160
178
  // and let the program terminate normally.
@@ -191,6 +209,7 @@ program
191
209
  .option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
192
210
  .option('-f, --fix', 'fix basic errors (does not work with STDIN)')
193
211
  .option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
212
+ .option('-j, --json', 'write issues in json format')
194
213
  .option('-o, --output [outputFile]', 'write issues to file (no console)')
195
214
  .option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
196
215
  .option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, [])
@@ -278,6 +297,9 @@ function lintAndPrint(stdin, files) {
278
297
  stdin
279
298
  };
280
299
  }
300
+ if (options.json) {
301
+ lintOptions.resultVersion = 3;
302
+ }
281
303
 
282
304
  if (options.fix) {
283
305
  const fixOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdownlint-cli",
3
- "version": "0.27.1",
3
+ "version": "0.28.0",
4
4
  "description": "MarkdownLint Command Line Interface",
5
5
  "main": "markdownlint.js",
6
6
  "bin": {
@@ -37,12 +37,12 @@
37
37
  },
38
38
  "homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
39
39
  "dependencies": {
40
- "commander": "~7.1.0",
40
+ "commander": "~8.0.0",
41
41
  "deep-extend": "~0.6.0",
42
42
  "get-stdin": "~8.0.0",
43
- "glob": "~7.1.6",
43
+ "glob": "~7.1.7",
44
44
  "ignore": "~5.1.8",
45
- "js-yaml": "^4.0.0",
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",
@@ -50,15 +50,15 @@
50
50
  "markdownlint-rule-helpers": "~0.14.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.1",
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.42.0"
62
62
  },
63
63
  "xo": {
64
64
  "space": true,