markdownlint-cli 0.22.0 → 0.24.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/LICENSE +21 -21
- package/README.md +129 -125
- package/markdownlint.js +40 -24
- 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,125 +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] 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
|
-
CLI argument `--config` is not
|
|
87
|
-
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
|
|
88
|
-
The algorithm is described in
|
|
89
|
-
If `--config` argument is provided, the file must be valid JSON, JSONC, or YAML.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
[
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
[
|
|
118
|
-
[
|
|
119
|
-
|
|
120
|
-
[
|
|
121
|
-
[
|
|
122
|
-
[
|
|
123
|
-
[
|
|
124
|
-
[
|
|
125
|
-
[
|
|
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(
|
|
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,
|
|
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
|
|
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 =
|
|
56
|
-
|
|
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 ' +
|
|
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(
|
|
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
|
|
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(
|
|
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,6 +122,7 @@ 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
|
});
|
|
@@ -172,7 +185,7 @@ program
|
|
|
172
185
|
.option('-f, --fix', 'fix basic errors (does not work with STDIN)')
|
|
173
186
|
.option('-s, --stdin', 'read from STDIN (does not work with files)')
|
|
174
187
|
.option('-o, --output [outputFile]', 'write issues to file (no console)')
|
|
175
|
-
.option('-c, --config [configFile]', 'configuration file (JSON, JSONC, or YAML)')
|
|
188
|
+
.option('-c, --config [configFile]', 'configuration file (JSON, JSONC, JS, or YAML)')
|
|
176
189
|
.option('-i, --ignore [file|directory|glob]', 'file(s) to ignore/exclude', concatArray, [])
|
|
177
190
|
.option('-p, --ignore-path [file]', 'path to file with ignore pattern(s)')
|
|
178
191
|
.option('-r, --rules [file|directory|glob|package]', 'custom rule files', concatArray, []);
|
|
@@ -184,7 +197,7 @@ function tryResolvePath(filepath) {
|
|
|
184
197
|
if (path.basename(filepath) === filepath && path.extname(filepath) === '') {
|
|
185
198
|
// Looks like a package name, resolve it relative to cwd
|
|
186
199
|
// Get list of directories, where requested module can be.
|
|
187
|
-
let paths = Module._nodeModulePaths(
|
|
200
|
+
let paths = Module._nodeModulePaths(processCwd);
|
|
188
201
|
paths = paths.concat(Module.globalPaths);
|
|
189
202
|
if (require.resolve.paths) {
|
|
190
203
|
// Node >= 8.9.0
|
|
@@ -195,8 +208,8 @@ function tryResolvePath(filepath) {
|
|
|
195
208
|
}
|
|
196
209
|
|
|
197
210
|
// Maybe it is a path to package installed locally
|
|
198
|
-
return require.resolve(path.join(
|
|
199
|
-
} catch
|
|
211
|
+
return require.resolve(path.join(processCwd, filepath));
|
|
212
|
+
} catch {
|
|
200
213
|
return filepath;
|
|
201
214
|
}
|
|
202
215
|
}
|
|
@@ -230,12 +243,13 @@ if (program.ignorePath) {
|
|
|
230
243
|
let ignoreFilter = () => true;
|
|
231
244
|
if (existsSync(ignorePath)) {
|
|
232
245
|
const ignoreText = fs.readFileSync(ignorePath, fsOptions);
|
|
246
|
+
const ignore = require('ignore');
|
|
233
247
|
const ignoreInstance = ignore().add(ignoreText);
|
|
234
|
-
ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.
|
|
248
|
+
ignoreFilter = fileInfo => !ignoreInstance.ignores(fileInfo.relative);
|
|
235
249
|
}
|
|
236
250
|
|
|
237
251
|
const files = prepareFileList(program.args, ['md', 'markdown'])
|
|
238
|
-
.filter(ignoreFilter);
|
|
252
|
+
.filter(value => ignoreFilter(value));
|
|
239
253
|
const ignores = prepareFileList(program.ignore, ['md', 'markdown'], files);
|
|
240
254
|
const customRules = loadCustomRules(program.rules);
|
|
241
255
|
const diff = differenceWith(files, ignores, function (a, b) {
|
|
@@ -263,6 +277,7 @@ function lintAndPrint(stdin, files) {
|
|
|
263
277
|
...lintOptions,
|
|
264
278
|
resultVersion: 3
|
|
265
279
|
};
|
|
280
|
+
const markdownlintRuleHelpers = require('markdownlint-rule-helpers');
|
|
266
281
|
files.forEach(file => {
|
|
267
282
|
fixOptions.files = [file];
|
|
268
283
|
const fixResult = markdownlint.sync(fixOptions);
|
|
@@ -284,6 +299,7 @@ function lintAndPrint(stdin, files) {
|
|
|
284
299
|
if ((files.length > 0) && !program.stdin) {
|
|
285
300
|
lintAndPrint(null, diff);
|
|
286
301
|
} else if ((files.length === 0) && program.stdin && !program.fix) {
|
|
302
|
+
const getStdin = require('get-stdin');
|
|
287
303
|
getStdin().then(lintAndPrint);
|
|
288
304
|
} else {
|
|
289
305
|
program.help();
|
package/package.json
CHANGED
|
@@ -1,79 +1,81 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "markdownlint-cli",
|
|
3
|
-
"version": "0.
|
|
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.
|
|
50
|
-
"markdownlint-rule-helpers": "~0.
|
|
51
|
-
"minimatch": "~3.0.4",
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "markdownlint-cli",
|
|
3
|
+
"version": "0.24.0",
|
|
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.21.0",
|
|
50
|
+
"markdownlint-rule-helpers": "~0.12.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": "^0.33.1"
|
|
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
|
+
}
|