markdownlint-cli 0.21.0 → 0.23.2

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 (4) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +129 -114
  3. package/markdownlint.js +59 -33
  4. package/package.json +81 -79
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2016-2020 Igor Shubovych
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-2020 Igor Shubovych
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,114 +1,129 @@
1
- # markdownlint-cli [![Travis CI Build Status][travis-badge]][travis-url] [![AppVeyor CI Build Status][appveyor-badge]][appveyor-url]
2
-
3
- > Command Line Interface for [MarkdownLint][markdownlint]
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install -g markdownlint-cli
9
- ```
10
-
11
- ## Usage
12
-
13
- ```bash
14
- markdownlint --help
15
-
16
- Usage: markdownlint [options] <files|directories|globs>
17
-
18
- MarkdownLint Command Line Interface
19
-
20
- Options:
21
-
22
- -h, --help output usage information
23
- -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
- -c, --config [configFile] configuration file (JSON, JSONC, or YAML)
28
- -i, --ignore [file|directory|glob] files to ignore/exclude
29
- -r, --rules [file|directory|glob|package] custom rule files
30
- ```
31
-
32
- ### Globbing
33
-
34
- `markdownlint-cli` supports advanced globbing patterns like `**/*.md` ([more information][globprimer]).
35
- With shells like Bash, it may be necessary to quote globs so they are not interpreted by the shell.
36
- For example, `--ignore *.md` would be expanded by Bash to `--ignore a.md b.md ...` before invoking `markdownlint-cli`, causing it to ignore only the first file because `--ignore` takes a single parameter (though it can be used multiple times).
37
- Quoting the glob like `--ignore '*.md'` passes it through unexpanded and ignores the set of files.
38
-
39
- #### Globbing examples
40
-
41
- To lint all Markdown files in a Node.js project (excluding dependencies), the following commands might be used:
42
-
43
- Windows CMD: `markdownlint **/*.md --ignore node_modules`
44
-
45
- Linux Bash: `markdownlint '**/*.md' --ignore node_modules`
46
-
47
- ### Ignoring files
48
-
49
- If present in the current folder, a `.markdownlintignore` file will be used to ignore files and /or directories according to the rules for [gitignore][gitignore].
50
-
51
- The order of operations is:
52
-
53
- - Enumerate files/directories/globs on the command line
54
- - Apply exclusions from `.markdownlintignore`
55
- - Apply exclusions from `-i`/`--ignore` option(s)
56
-
57
- ### Fixing errors
58
-
59
- When the `--fix` option is specified, `markdownlint-cli` tries to apply all fixes reported by the active rules and reports any errors that remain.
60
- Because this option makes changes to the input files, it is good to make a backup first or work with files under source control so any unwanted changes can be undone.
61
-
62
- > Because not all rules include fix information when reporting errors, fixes may overlap, and not all errors are fixable, `--fix` will not usually address all errors.
63
-
64
- ## Configuration
65
-
66
- `markdownlint-cli` reuses [the rules][rules] from `markdownlint` package.
67
-
68
- Configuration is stored in JSON, JSONC, YAML, or INI files in the same [config format][config].
69
-
70
- The example of configuration file:
71
-
72
- ```json
73
- {
74
- "default": true,
75
- "MD003": { "style": "atx_closed" },
76
- "MD007": { "indent": 4 },
77
- "no-hard-tabs": false,
78
- "whitespace": false
79
- }
80
- ```
81
-
82
- See [test configuration file][test-config] or [style folder][style-folder] for more examples.
83
-
84
- CLI argument `--config` is not mandatory.
85
- If it is not provided, `markdownlint-cli` looks for file `.markdownlint.json`/`.markdownlint.yaml`/`.markdownlint.yml` in current folder, or for file `.markdownlintrc` in current or all upper folders.
86
- The algorithm is described in details on [rc package page][rc-standards].
87
- If `--config` argument is provided, the file must be valid JSON, JSONC, or YAML.
88
-
89
- ## Related
90
-
91
- - [markdownlint][markdownlint] - API for this module
92
- - [glob][glob] - Pattern matching implementation
93
- - [ignore][ignore] - `.markdownlintignore` implementation
94
-
95
- ## License
96
-
97
- MIT © Igor Shubovych
98
-
99
- [travis-badge]: https://img.shields.io/travis/igorshubovych/markdownlint-cli/master.svg?label=linux
100
- [travis-url]: https://travis-ci.org/igorshubovych/markdownlint-cli
101
-
102
- [appveyor-badge]: https://img.shields.io/appveyor/ci/igorshubovych/markdownlint-cli/master.svg?label=windows
103
- [appveyor-url]: https://ci.appveyor.com/project/igorshubovych/markdownlint-cli
104
-
105
- [markdownlint]: https://github.com/DavidAnson/markdownlint
106
- [rules]: https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md
107
- [config]: https://github.com/DavidAnson/markdownlint#optionsconfig
108
- [style-folder]: https://github.com/DavidAnson/markdownlint/tree/master/style
109
- [test-config]: https://github.com/igorshubovych/markdownlint-cli/blob/master/test/test-config.json
110
- [rc-standards]: https://www.npmjs.com/package/rc#standards
111
- [glob]: https://github.com/isaacs/node-glob
112
- [globprimer]: https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer
113
- [ignore]: https://github.com/kaelzhang/node-ignore
114
- [gitignore]: https://git-scm.com/docs/gitignore
1
+ # markdownlint-cli [![Travis CI Build Status][travis-badge]][travis-url] [![AppVeyor CI Build Status][appveyor-badge]][appveyor-url]
2
+
3
+ > Command Line Interface for [MarkdownLint][markdownlint]
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g markdownlint-cli
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ markdownlint --help
15
+
16
+ Usage: markdownlint [options] <files|directories|globs>
17
+
18
+ MarkdownLint Command Line Interface
19
+
20
+ Options:
21
+
22
+ -h, --help output usage information
23
+ -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
+ -c, --config [configFile] configuration file (JSON, JSONC, JS, or YAML)
28
+ -i, --ignore [file|directory|glob] file(s) to ignore/exclude
29
+ -p, --ignore-path [file] path to file with ignore pattern(s)
30
+ -r, --rules [file|directory|glob|package] custom rule files
31
+ ```
32
+
33
+ ### Globbing
34
+
35
+ `markdownlint-cli` supports advanced globbing patterns like `**/*.md` ([more information][globprimer]).
36
+ With shells like Bash, it may be necessary to quote globs so they are not interpreted by the shell.
37
+ For example, `--ignore *.md` would be expanded by Bash to `--ignore a.md b.md ...` before invoking `markdownlint-cli`, causing it to ignore only the first file because `--ignore` takes a single parameter (though it can be used multiple times).
38
+ Quoting the glob like `--ignore '*.md'` passes it through unexpanded and ignores the set of files.
39
+
40
+ #### Globbing examples
41
+
42
+ To lint all Markdown files in a Node.js project (excluding dependencies), the following commands might be used:
43
+
44
+ Windows CMD: `markdownlint **/*.md --ignore node_modules`
45
+
46
+ Linux Bash: `markdownlint '**/*.md' --ignore node_modules`
47
+
48
+ ### Ignoring files
49
+
50
+ If present in the current folder, a `.markdownlintignore` file will be used to ignore files and/or directories according to the rules for [gitignore][gitignore].
51
+ If the `-p`/`--ignore-path` option is present, the specified file will be used instead of `.markdownlintignore`.
52
+
53
+ The order of operations is:
54
+
55
+ - Enumerate files/directories/globs passed on the command line
56
+ - Apply exclusions from `-p`/`--ignore-path` (if specified) or `.markdownlintignore` (if present)
57
+ - Apply exclusions from any `-i`/`--ignore` option(s) that are specified
58
+
59
+ ### Fixing errors
60
+
61
+ When the `--fix` option is specified, `markdownlint-cli` tries to apply all fixes reported by the active rules and reports any errors that remain.
62
+ Because this option makes changes to the input files, it is good to make a backup first or work with files under source control so any unwanted changes can be undone.
63
+
64
+ > Because not all rules include fix information when reporting errors, fixes may overlap, and not all errors are fixable, `--fix` will not usually address all errors.
65
+
66
+ ## Configuration
67
+
68
+ `markdownlint-cli` reuses [the rules][rules] from `markdownlint` package.
69
+
70
+ Configuration is stored in JSON, JSONC, YAML, or INI files in the same [config format][config].
71
+
72
+ The example of configuration file:
73
+
74
+ ```json
75
+ {
76
+ "default": true,
77
+ "MD003": { "style": "atx_closed" },
78
+ "MD007": { "indent": 4 },
79
+ "no-hard-tabs": false,
80
+ "whitespace": false
81
+ }
82
+ ```
83
+
84
+ See [test configuration file][test-config] or [style folder][style-folder] for more examples.
85
+
86
+ The CLI argument `--config` is not required.
87
+ 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.
88
+ The algorithm is described in detail on the [`rc` package page][rc-standards].
89
+ If the `--config` argument is provided, the file must be valid JSON, JSONC, JS, or YAML.
90
+ 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.
91
+ A JS configuration file may internally `require` one or more npm packages as a way of reusing configuration across projects.
92
+
93
+ > JS configuration files must be provided via the `--config` argument; they are not automatically loaded because running untrusted code is a security concern.
94
+
95
+ ## Exit codes
96
+
97
+ `markdownlint-cli` returns one of the following exit codes:
98
+
99
+ - `0`: Program ran successfully
100
+ - `1`: Linting errors / bad parameter
101
+ - `2`: Unable to write `-o`/`--output` output file
102
+ - `3`: Unable to load `-r`/`--rules` custom rule
103
+
104
+ ## Related
105
+
106
+ - [markdownlint][markdownlint] - API for this module
107
+ - [glob][glob] - Pattern matching implementation
108
+ - [ignore][ignore] - `.markdownlintignore` implementation
109
+
110
+ ## License
111
+
112
+ MIT © Igor Shubovych
113
+
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
+
120
+ [markdownlint]: https://github.com/DavidAnson/markdownlint
121
+ [rules]: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
122
+ [config]: https://github.com/DavidAnson/markdownlint#optionsconfig
123
+ [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
+ [rc-standards]: https://www.npmjs.com/package/rc#standards
126
+ [glob]: https://github.com/isaacs/node-glob
127
+ [globprimer]: https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer
128
+ [ignore]: https://github.com/kaelzhang/node-ignore
129
+ [gitignore]: https://git-scm.com/docs/gitignore
package/markdownlint.js CHANGED
@@ -6,22 +6,21 @@ const fs = require('fs');
6
6
  const path = require('path');
7
7
  const Module = require('module');
8
8
  const program = require('commander');
9
- const getStdin = require('get-stdin');
10
- const jsYaml = require('js-yaml');
11
- const jsoncParser = require('jsonc-parser');
12
9
  const differenceWith = require('lodash.differencewith');
13
10
  const flatten = require('lodash.flatten');
14
- const extend = require('deep-extend');
15
- const ignore = require('ignore');
16
11
  const markdownlint = require('markdownlint');
17
- const markdownlintRuleHelpers = require('markdownlint-rule-helpers');
18
12
  const rc = require('rc');
19
13
  const glob = require('glob');
20
14
  const minimatch = require('minimatch');
15
+ const minimist = require('minimist');
21
16
  const pkg = require('./package');
22
17
 
23
18
  function jsoncParse(text) {
24
- return JSON.parse(jsoncParser.stripComments(text));
19
+ return JSON.parse(require('jsonc-parser').stripComments(text));
20
+ }
21
+
22
+ function jsYamlSafeLoad(text) {
23
+ return require('js-yaml').safeLoad(text);
25
24
  }
26
25
 
27
26
  const projectConfigFiles = [
@@ -29,33 +28,46 @@ const projectConfigFiles = [
29
28
  '.markdownlint.yaml',
30
29
  '.markdownlint.yml'
31
30
  ];
32
- const configFileParsers = [jsoncParse, jsYaml.safeLoad];
31
+ const configFileParsers = [jsoncParse, jsYamlSafeLoad];
33
32
  const fsOptions = {encoding: 'utf8'};
33
+ const processCwd = process.cwd();
34
34
 
35
35
  function readConfiguration(args) {
36
- let config = rc('markdownlint', {});
37
36
  const userConfigFile = args.config;
37
+ const jsConfigFile = /\.js$/i.test(userConfigFile);
38
+ const rcArgv = minimist(process.argv.slice(2));
39
+ if (jsConfigFile) {
40
+ // Prevent rc package from parsing .js config file as INI
41
+ delete rcArgv.config;
42
+ }
43
+
44
+ // Load from well-known config files
45
+ let config = rc('markdownlint', {}, rcArgv);
38
46
  for (const projectConfigFile of projectConfigFiles) {
39
47
  try {
40
48
  fs.accessSync(projectConfigFile, fs.R_OK);
41
49
  const projectConfig = markdownlint.readConfigSync(projectConfigFile, configFileParsers);
42
- config = extend(config, projectConfig);
50
+ config = require('deep-extend')(config, projectConfig);
43
51
  break;
44
- } catch (error) {
52
+ } catch (_) {
45
53
  // Ignore failure
46
54
  }
47
55
  }
56
+
48
57
  // Normally parsing this file is not needed,
49
58
  // because it is already parsed by rc package.
50
59
  // However I have to do it to overwrite configuration
51
60
  // from .markdownlint.{json,yaml,yml}.
52
-
53
61
  if (userConfigFile) {
54
62
  try {
55
- const userConfig = markdownlint.readConfigSync(userConfigFile, configFileParsers);
56
- config = extend(config, userConfig);
63
+ const userConfig = jsConfigFile ?
64
+ // Evaluate .js configuration file as code
65
+ require(path.resolve(processCwd, userConfigFile)) :
66
+ // Load JSON/YAML configuration as data
67
+ markdownlint.readConfigSync(userConfigFile, configFileParsers);
68
+ config = require('deep-extend')(config, userConfig);
57
69
  } catch (error) {
58
- console.warn('Cannot read or parse config file ' + args.config + ': ' + error.message);
70
+ console.warn('Cannot read or parse config file ' + userConfigFile + ': ' + error.message);
59
71
  }
60
72
  }
61
73
 
@@ -80,7 +92,7 @@ function prepareFileList(files, fileExtensions, previousResults) {
80
92
  // Directory (file falls through to below)
81
93
  if (previousResults) {
82
94
  const matcher = new minimatch.Minimatch(
83
- path.resolve(process.cwd(), path.join(file, '**', extensionGlobPart)), globOptions);
95
+ path.resolve(processCwd, path.join(file, '**', extensionGlobPart)), globOptions);
84
96
  return previousResults.filter(function (fileInfo) {
85
97
  return matcher.match(fileInfo.absolute);
86
98
  }).map(function (fileInfo) {
@@ -90,10 +102,10 @@ function prepareFileList(files, fileExtensions, previousResults) {
90
102
 
91
103
  return glob.sync(path.join(file, '**', extensionGlobPart), globOptions);
92
104
  }
93
- } catch (error) {
105
+ } catch (_) {
94
106
  // Not a directory, not a file, may be a glob
95
107
  if (previousResults) {
96
- const matcher = new minimatch.Minimatch(path.resolve(process.cwd(), file), globOptions);
108
+ const matcher = new minimatch.Minimatch(path.resolve(processCwd, file), globOptions);
97
109
  return previousResults.filter(function (fileInfo) {
98
110
  return matcher.match(fileInfo.absolute);
99
111
  }).map(function (fileInfo) {
@@ -110,17 +122,19 @@ function prepareFileList(files, fileExtensions, previousResults) {
110
122
  return flatten(files).map(function (file) {
111
123
  return {
112
124
  original: file,
125
+ relative: path.relative(processCwd, file),
113
126
  absolute: path.resolve(file)
114
127
  };
115
128
  });
116
129
  }
117
130
 
118
131
  function printResult(lintResult) {
119
- const results = flatten(Object.keys(lintResult).map(function (file) {
120
- return lintResult[file].map(function (result) {
132
+ const results = flatten(Object.keys(lintResult).map(file => {
133
+ return lintResult[file].map(result => {
121
134
  return {
122
135
  file: file,
123
136
  lineNumber: result.lineNumber,
137
+ column: (result.errorRange && result.errorRange[0]) || 0,
124
138
  names: result.ruleNames.join('/'),
125
139
  description: result.ruleDescription +
126
140
  (result.errorDetail ? ' [' + result.errorDetail + ']' : '') +
@@ -130,12 +144,14 @@ function printResult(lintResult) {
130
144
  }));
131
145
  let lintResultString = '';
132
146
  if (results.length > 0) {
133
- results.sort(function (a, b) {
147
+ results.sort((a, b) => {
134
148
  return a.file.localeCompare(b.file) || a.lineNumber - b.lineNumber ||
135
149
  a.names.localeCompare(b.names) || a.description.localeCompare(b.description);
136
150
  });
137
- lintResultString = results.map(function (result) {
138
- return result.file + ':' + result.lineNumber + ' ' + result.names + ' ' + result.description;
151
+ lintResultString = results.map(result => {
152
+ const {file, lineNumber, column, names, description} = result;
153
+ const columnText = column ? `:${column}` : '';
154
+ return `${file}:${lineNumber}${columnText} ${names} ${description}`;
139
155
  }).join('\n');
140
156
  // Note: process.exit(1) will end abruptly, interrupting asynchronous IO
141
157
  // streams (e.g., when the output is being piped). Just set the exit code
@@ -169,8 +185,9 @@ program
169
185
  .option('-f, --fix', 'fix basic errors (does not work with STDIN)')
170
186
  .option('-s, --stdin', 'read from STDIN (does not work with files)')
171
187
  .option('-o, --output [outputFile]', 'write issues to file (no console)')
172
- .option('-c, --config [configFile]', 'configuration file (JSON, JSONC, or YAML)')
173
- .option('-i, --ignore [file|directory|glob]', 'files to ignore/exclude', concatArray, [])
188
+ .option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)')
189
+ .option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
190
+ .option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
174
191
  .option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, []);
175
192
 
176
193
  program.parse(process.argv);
@@ -180,7 +197,7 @@ function tryResolvePath(filepath) {
180
197
  if (path.basename(filepath) === filepath && path.extname(filepath) === '') {
181
198
  // Looks like a package name, resolve it relative to cwd
182
199
  // Get list of directories, where requested module can be.
183
- let paths = Module._nodeModulePaths(process.cwd());
200
+ let paths = Module._nodeModulePaths(processCwd);
184
201
  paths = paths.concat(Module.globalPaths);
185
202
  if (require.resolve.paths) {
186
203
  // Node >= 8.9.0
@@ -191,8 +208,8 @@ function tryResolvePath(filepath) {
191
208
  }
192
209
 
193
210
  // Maybe it is a path to package installed locally
194
- return require.resolve(path.join(process.cwd(), filepath));
195
- } catch (error) {
211
+ return require.resolve(path.join(processCwd, filepath));
212
+ } catch (_) {
196
213
  return filepath;
197
214
  }
198
215
  }
@@ -216,16 +233,23 @@ function loadCustomRules(rules) {
216
233
  }));
217
234
  }
218
235
 
219
- const markdownlintIgnore = '.markdownlintignore';
236
+ let ignorePath = '.markdownlintignore';
237
+ let {existsSync} = fs;
238
+ if (program.ignorePath) {
239
+ ignorePath = program.ignorePath;
240
+ existsSync = () => true;
241
+ }
242
+
220
243
  let ignoreFilter = () => true;
221
- if (fs.existsSync(markdownlintIgnore)) {
222
- const ignoreText = fs.readFileSync(markdownlintIgnore, fsOptions);
244
+ if (existsSync(ignorePath)) {
245
+ const ignoreText = fs.readFileSync(ignorePath, fsOptions);
246
+ const ignore = require('ignore');
223
247
  const ignoreInstance = ignore().add(ignoreText);
224
- ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.original);
248
+ ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.relative);
225
249
  }
226
250
 
227
251
  const files = prepareFileList(program.args, ['md', 'markdown'])
228
- .filter(ignoreFilter);
252
+ .filter(value => ignoreFilter(value));
229
253
  const ignores = prepareFileList(program.ignore, ['md', 'markdown'], files);
230
254
  const customRules = loadCustomRules(program.rules);
231
255
  const diff = differenceWith(files, ignores, function (a, b) {
@@ -253,6 +277,7 @@ function lintAndPrint(stdin, files) {
253
277
  ...lintOptions,
254
278
  resultVersion: 3
255
279
  };
280
+ const markdownlintRuleHelpers = require('markdownlint-rule-helpers');
256
281
  files.forEach(file => {
257
282
  fixOptions.files = [file];
258
283
  const fixResult = markdownlint.sync(fixOptions);
@@ -274,6 +299,7 @@ function lintAndPrint(stdin, files) {
274
299
  if ((files.length > 0) && !program.stdin) {
275
300
  lintAndPrint(null, diff);
276
301
  } else if ((files.length === 0) && program.stdin && !program.fix) {
302
+ const getStdin = require('get-stdin');
277
303
  getStdin().then(lintAndPrint);
278
304
  } else {
279
305
  program.help();
package/package.json CHANGED
@@ -1,79 +1,81 @@
1
- {
2
- "name": "markdownlint-cli",
3
- "version": "0.21.0",
4
- "description": "MarkdownLint Command Line Interface",
5
- "main": "markdownlint.js",
6
- "bin": {
7
- "markdownlint": "markdownlint.js"
8
- },
9
- "engines": {
10
- "node": ">=8"
11
- },
12
- "scripts": {
13
- "invalid": "node ./markdownlint.js --config test/test-config.json -- test/incorrect.md",
14
- "fix": "cp test/incorrect.md test/incorrect.copy.md && node ./markdownlint.js --fix test/incorrect.copy.md ; cat test/incorrect.copy.md && rm test/incorrect.copy.md",
15
- "test": "ava",
16
- "watch": "npm test -- --watch --tap | tap-growl",
17
- "start": "node ./markdownlint.js",
18
- "precommit": "xo && npm test"
19
- },
20
- "files": [
21
- "markdownlint.js"
22
- ],
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/igorshubovych/markdownlint-cli.git"
26
- },
27
- "keywords": [
28
- "markdown",
29
- "markdownlint",
30
- "cli",
31
- "cli-app"
32
- ],
33
- "author": "Igor Shubovych <igor.shubovych@gmail.com>",
34
- "license": "MIT",
35
- "bugs": {
36
- "url": "https://github.com/igorshubovych/markdownlint-cli/issues"
37
- },
38
- "homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
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",
47
- "lodash.differencewith": "~4.5.0",
48
- "lodash.flatten": "~4.4.0",
49
- "markdownlint": "~0.18.0",
50
- "markdownlint-rule-helpers": "~0.6.0",
51
- "minimatch": "~3.0.4",
52
- "rc": "~1.2.7"
53
- },
54
- "devDependencies": {
55
- "ava": "^2.2.0",
56
- "execa": "^2.0.4",
57
- "husky": "^3.0.4",
58
- "tap-growl": "^3.0.0",
59
- "test-rule-package": "./test/custom-rules/test-rule-package",
60
- "xo": "*"
61
- },
62
- "xo": {
63
- "space": true,
64
- "rules": {
65
- "linebreak-style": 0,
66
- "no-var": 0,
67
- "prefer-arrow-callback": 0,
68
- "promise/prefer-await-to-then": 0,
69
- "object-shorthand": 0
70
- }
71
- },
72
- "ava": {
73
- "files": [
74
- "test/**/*.js",
75
- "!test/custom-rules/**/*.js"
76
- ],
77
- "failFast": true
78
- }
79
- }
1
+ {
2
+ "name": "markdownlint-cli",
3
+ "version": "0.23.2",
4
+ "description": "MarkdownLint Command Line Interface",
5
+ "main": "markdownlint.js",
6
+ "bin": {
7
+ "markdownlint": "markdownlint.js"
8
+ },
9
+ "engines": {
10
+ "node": ">=10"
11
+ },
12
+ "scripts": {
13
+ "invalid": "node ./markdownlint.js --config test/test-config.json -- test/incorrect.md",
14
+ "fix": "cp test/incorrect.md test/incorrect.copy.md && node ./markdownlint.js --fix test/incorrect.copy.md ; cat test/incorrect.copy.md && rm test/incorrect.copy.md",
15
+ "test": "ava",
16
+ "watch": "npm test -- --watch --tap | tap-growl",
17
+ "start": "node ./markdownlint.js",
18
+ "precommit": "xo && npm test"
19
+ },
20
+ "files": [
21
+ "markdownlint.js"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/igorshubovych/markdownlint-cli.git"
26
+ },
27
+ "keywords": [
28
+ "markdown",
29
+ "markdownlint",
30
+ "cli",
31
+ "cli-app"
32
+ ],
33
+ "author": "Igor Shubovych <igor.shubovych@gmail.com>",
34
+ "license": "MIT",
35
+ "bugs": {
36
+ "url": "https://github.com/igorshubovych/markdownlint-cli/issues"
37
+ },
38
+ "homepage": "https://github.com/igorshubovych/markdownlint-cli#readme",
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",
47
+ "lodash.differencewith": "~4.5.0",
48
+ "lodash.flatten": "~4.4.0",
49
+ "markdownlint": "~0.20.4",
50
+ "markdownlint-rule-helpers": "~0.11.0",
51
+ "minimatch": "~3.0.4",
52
+ "minimist": "~1.2.5",
53
+ "rc": "~1.2.7"
54
+ },
55
+ "devDependencies": {
56
+ "ava": "^3.8.1",
57
+ "execa": "^2.0.4",
58
+ "husky": "^3.0.4",
59
+ "tap-growl": "^3.0.0",
60
+ "test-rule-package": "./test/custom-rules/test-rule-package",
61
+ "xo": "*"
62
+ },
63
+ "xo": {
64
+ "space": true,
65
+ "rules": {
66
+ "linebreak-style": 0,
67
+ "no-var": 0,
68
+ "prefer-arrow-callback": 0,
69
+ "promise/prefer-await-to-then": 0,
70
+ "object-shorthand": 0
71
+ }
72
+ },
73
+ "ava": {
74
+ "files": [
75
+ "test/**/*.js",
76
+ "!test/custom-rules/**/*.js",
77
+ "!test/md043-config.js"
78
+ ],
79
+ "failFast": true
80
+ }
81
+ }