markdownlint-cli 0.24.0 → 0.27.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.
Files changed (3) hide show
  1. package/README.md +30 -13
  2. package/markdownlint.js +27 -20
  3. package/package.json +17 -16
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # markdownlint-cli [![Travis CI Build Status][travis-badge]][travis-url] [![AppVeyor CI Build Status][appveyor-badge]][appveyor-url]
1
+ # markdownlint-cli
2
+
3
+ [![GitHub Actions Build Status][actions-badge]][actions-url]
2
4
 
3
5
  > Command Line Interface for [MarkdownLint][markdownlint]
4
6
 
@@ -8,6 +10,12 @@
8
10
  npm install -g markdownlint-cli
9
11
  ```
10
12
 
13
+ On macOS you can install via [Homebrew](https://brew.sh/):
14
+
15
+ ```bash
16
+ brew install markdownlint-cli
17
+ ```
18
+
11
19
  ## Usage
12
20
 
13
21
  ```bash
@@ -21,13 +29,14 @@ markdownlint --help
21
29
 
22
30
  -h, --help output usage information
23
31
  -V, --version output the version number
24
- -f, --fix fix basic errors (does not work with STDIN)
25
- -s, --stdin read from STDIN (does not work with files)
26
- -o, --output [outputFile] write issues to file (no console)
27
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)
28
35
  -i, --ignore [file|directory|glob] file(s) to ignore/exclude
36
+ -o, --output [outputFile] write issues to file (no console)
29
37
  -p, --ignore-path [file] path to file with ignore pattern(s)
30
38
  -r, --rules [file|directory|glob|package] custom rule files
39
+ -s, --stdin read from STDIN (does not work with files)
31
40
  ```
32
41
 
33
42
  ### Globbing
@@ -69,7 +78,7 @@ Because this option makes changes to the input files, it is good to make a backu
69
78
 
70
79
  Configuration is stored in JSON, JSONC, YAML, or INI files in the same [config format][config].
71
80
 
72
- The example of configuration file:
81
+ A sample configuration file:
73
82
 
74
83
  ```json
75
84
  {
@@ -81,7 +90,7 @@ The example of configuration file:
81
90
  }
82
91
  ```
83
92
 
84
- See [test configuration file][test-config] or [style folder][style-folder] for more examples.
93
+ For more examples, see [.markdownlint.jsonc][markdownlint-jsonc], [.markdownlint.yaml][markdownlint-yaml], or the [style folder][style-folder].
85
94
 
86
95
  The CLI argument `--config` is not required.
87
96
  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.
@@ -101,6 +110,17 @@ A JS configuration file may internally `require` one or more npm packages as a w
101
110
  - `2`: Unable to write `-o`/`--output` output file
102
111
  - `3`: Unable to load `-r`/`--rules` custom rule
103
112
 
113
+ ## Use with pre-commit
114
+
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
+
117
+ ```yaml
118
+ - repo: https://github.com/igorshubovych/markdownlint-cli
119
+ rev: v0.27.1
120
+ hooks:
121
+ - id: markdownlint
122
+ ```
123
+
104
124
  ## Related
105
125
 
106
126
  - [markdownlint][markdownlint] - API for this module
@@ -111,17 +131,14 @@ A JS configuration file may internally `require` one or more npm packages as a w
111
131
 
112
132
  MIT © Igor Shubovych
113
133
 
114
- [travis-badge]: https://img.shields.io/travis/igorshubovych/markdownlint-cli/master.svg?label=linux
115
- [travis-url]: https://travis-ci.org/igorshubovych/markdownlint-cli
116
-
117
- [appveyor-badge]: https://img.shields.io/appveyor/ci/igorshubovych/markdownlint-cli/master.svg?label=windows
118
- [appveyor-url]: https://ci.appveyor.com/project/igorshubovych/markdownlint-cli
119
-
134
+ [actions-badge]: https://github.com/igorshubovych/markdownlint-cli/workflows/CI/badge.svg?branch=master
135
+ [actions-url]: https://github.com/igorshubovych/markdownlint-cli/actions?query=workflow%3ACI
120
136
  [markdownlint]: https://github.com/DavidAnson/markdownlint
137
+ [markdownlint-jsonc]: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
138
+ [markdownlint-yaml]: https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml
121
139
  [rules]: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
122
140
  [config]: https://github.com/DavidAnson/markdownlint#optionsconfig
123
141
  [style-folder]: https://github.com/DavidAnson/markdownlint/tree/main/style
124
- [test-config]: https://github.com/igorshubovych/markdownlint-cli/blob/master/test/test-config.json
125
142
  [rc-standards]: https://www.npmjs.com/package/rc#standards
126
143
  [glob]: https://github.com/isaacs/node-glob
127
144
  [globprimer]: https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer
package/markdownlint.js CHANGED
@@ -6,6 +6,7 @@ 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');
@@ -14,13 +15,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').safeLoad(text);
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(args) {
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 = '*.';
@@ -161,11 +163,14 @@ function printResult(lintResult) {
161
163
  process.exitCode = 1;
162
164
  }
163
165
 
164
- if (program.output) {
166
+ if (options.output) {
167
+ lintResultString = lintResultString.length > 0 ?
168
+ lintResultString + os.EOL :
169
+ lintResultString;
165
170
  try {
166
- fs.writeFileSync(program.output, lintResultString);
171
+ fs.writeFileSync(options.output, lintResultString);
167
172
  } catch (error) {
168
- console.warn('Cannot write to output file ' + program.output + ': ' + error.message);
173
+ console.warn('Cannot write to output file ' + options.output + ': ' + error.message);
169
174
  process.exitCode = 2;
170
175
  }
171
176
  } else if (lintResultString) {
@@ -182,13 +187,14 @@ program
182
187
  .version(pkg.version)
183
188
  .description(pkg.description)
184
189
  .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
190
  .option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)')
191
+ .option('-d, --dot', 'include files/folders with a dot (for example `.github`)')
192
+ .option('-f, --fix', 'fix basic errors (does not work with STDIN)')
189
193
  .option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
194
+ .option('-o, --output [outputFile]', 'write issues to file (no console)')
190
195
  .option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
191
- .option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, []);
196
+ .option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, [])
197
+ .option('-s, --stdin', 'read from STDIN (does not work with files)');
192
198
 
193
199
  program.parse(process.argv);
194
200
 
@@ -198,6 +204,7 @@ function tryResolvePath(filepath) {
198
204
  // Looks like a package name, resolve it relative to cwd
199
205
  // Get list of directories, where requested module can be.
200
206
  let paths = Module._nodeModulePaths(processCwd);
207
+ // eslint-disable-next-line unicorn/prefer-spread
201
208
  paths = paths.concat(Module.globalPaths);
202
209
  if (require.resolve.paths) {
203
210
  // Node >= 8.9.0
@@ -235,8 +242,8 @@ function loadCustomRules(rules) {
235
242
 
236
243
  let ignorePath = '.markdownlintignore';
237
244
  let {existsSync} = fs;
238
- if (program.ignorePath) {
239
- ignorePath = program.ignorePath;
245
+ if (options.ignorePath) {
246
+ ignorePath = options.ignorePath;
240
247
  existsSync = () => true;
241
248
  }
242
249
 
@@ -250,8 +257,8 @@ if (existsSync(ignorePath)) {
250
257
 
251
258
  const files = prepareFileList(program.args, ['md', 'markdown'])
252
259
  .filter(value => ignoreFilter(value));
253
- const ignores = prepareFileList(program.ignore, ['md', 'markdown'], files);
254
- const customRules = loadCustomRules(program.rules);
260
+ const ignores = prepareFileList(options.ignore, ['md', 'markdown'], files);
261
+ const customRules = loadCustomRules(options.rules);
255
262
  const diff = differenceWith(files, ignores, function (a, b) {
256
263
  return a.absolute === b.absolute;
257
264
  }).map(function (paths) {
@@ -260,7 +267,7 @@ const diff = differenceWith(files, ignores, function (a, b) {
260
267
 
261
268
  function lintAndPrint(stdin, files) {
262
269
  files = files || [];
263
- const config = readConfiguration(program);
270
+ const config = readConfiguration(options.config);
264
271
  const lintOptions = {
265
272
  config,
266
273
  customRules,
@@ -272,13 +279,13 @@ function lintAndPrint(stdin, files) {
272
279
  };
273
280
  }
274
281
 
275
- if (program.fix) {
282
+ if (options.fix) {
276
283
  const fixOptions = {
277
284
  ...lintOptions,
278
285
  resultVersion: 3
279
286
  };
280
287
  const markdownlintRuleHelpers = require('markdownlint-rule-helpers');
281
- files.forEach(file => {
288
+ for (const file of files) {
282
289
  fixOptions.files = [file];
283
290
  const fixResult = markdownlint.sync(fixOptions);
284
291
  const fixes = fixResult[file].filter(error => error.fixInfo);
@@ -289,16 +296,16 @@ function lintAndPrint(stdin, files) {
289
296
  fs.writeFileSync(file, fixedText, fsOptions);
290
297
  }
291
298
  }
292
- });
299
+ }
293
300
  }
294
301
 
295
302
  const lintResult = markdownlint.sync(lintOptions);
296
303
  printResult(lintResult);
297
304
  }
298
305
 
299
- if ((files.length > 0) && !program.stdin) {
306
+ if ((files.length > 0) && !options.stdin) {
300
307
  lintAndPrint(null, diff);
301
- } else if ((files.length === 0) && program.stdin && !program.fix) {
308
+ } else if ((files.length === 0) && options.stdin && !options.fix) {
302
309
  const getStdin = require('get-stdin');
303
310
  getStdin().then(lintAndPrint);
304
311
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "markdownlint-cli",
3
- "version": "0.24.0",
3
+ "version": "0.27.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": "~2.9.0",
41
- "deep-extend": "~0.5.1",
42
- "get-stdin": "~5.0.1",
43
- "glob": "~7.1.2",
44
- "ignore": "~5.1.4",
45
- "js-yaml": "~3.13.1",
46
- "jsonc-parser": "~2.2.0",
40
+ "commander": "~7.1.0",
41
+ "deep-extend": "~0.6.0",
42
+ "get-stdin": "~8.0.0",
43
+ "glob": "~7.1.6",
44
+ "ignore": "~5.1.8",
45
+ "js-yaml": "^4.0.0",
46
+ "jsonc-parser": "~3.0.0",
47
47
  "lodash.differencewith": "~4.5.0",
48
48
  "lodash.flatten": "~4.4.0",
49
- "markdownlint": "~0.21.0",
50
- "markdownlint-rule-helpers": "~0.12.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
- "rc": "~1.2.7"
53
+ "rc": "~1.2.8"
54
54
  },
55
55
  "devDependencies": {
56
- "ava": "^3.8.1",
57
- "execa": "^2.0.4",
58
- "husky": "^3.0.4",
56
+ "ava": "^3.15.0",
57
+ "execa": "^5.0.0",
58
+ "husky": "^5.1.2",
59
59
  "tap-growl": "^3.0.0",
60
60
  "test-rule-package": "./test/custom-rules/test-rule-package",
61
- "xo": "^0.33.1"
61
+ "xo": "^0.38.2"
62
62
  },
63
63
  "xo": {
64
64
  "space": true,
@@ -67,7 +67,8 @@
67
67
  "no-var": 0,
68
68
  "prefer-arrow-callback": 0,
69
69
  "promise/prefer-await-to-then": 0,
70
- "object-shorthand": 0
70
+ "object-shorthand": 0,
71
+ "unicorn/prefer-ternary": 0
71
72
  }
72
73
  },
73
74
  "ava": {