markdownlint-cli 0.13.0 → 0.16.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 +2 -2
- package/markdownlint.js +38 -18
- package/package.json +10 -18
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ $ markdownlint --help
|
|
|
32
32
|
|
|
33
33
|
`markdownlint-cli` reuses [the rules][rules] from `markdownlint` package.
|
|
34
34
|
|
|
35
|
-
Configuration is stored JSON or INI files in the same [config format][config].
|
|
35
|
+
Configuration is stored in JSON, YAML or INI files in the same [config format][config].
|
|
36
36
|
|
|
37
37
|
The example of configuration file:
|
|
38
38
|
|
|
@@ -48,7 +48,7 @@ The example of configuration file:
|
|
|
48
48
|
|
|
49
49
|
See [test configuration file][test-config] or [style folder][style-folder] for more examples.
|
|
50
50
|
|
|
51
|
-
CLI argument `--config` is not mandatory. If it is not provided, `markdownlint-cli` looks for file `.markdownlint.json` in current folder, or for file `.markdownlintrc` in current or all upper folders. The algorithm is described in details on [rc package page][rc-standards]. If `--config` argument is provided, the file must be valid JSON or YAML.
|
|
51
|
+
CLI argument `--config` is not mandatory. 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. The algorithm is described in details on [rc package page][rc-standards]. If `--config` argument is provided, the file must be valid JSON or YAML.
|
|
52
52
|
|
|
53
53
|
## Related
|
|
54
54
|
|
package/markdownlint.js
CHANGED
|
@@ -15,31 +15,42 @@ const markdownlint = require('markdownlint');
|
|
|
15
15
|
const rc = require('rc');
|
|
16
16
|
const glob = require('glob');
|
|
17
17
|
const minimatch = require('minimatch');
|
|
18
|
-
|
|
19
18
|
const pkg = require('./package');
|
|
20
19
|
|
|
20
|
+
const projectConfigFiles = [
|
|
21
|
+
'.markdownlint.json',
|
|
22
|
+
'.markdownlint.yaml',
|
|
23
|
+
'.markdownlint.yml'
|
|
24
|
+
];
|
|
25
|
+
const configFileParsers = [JSON.parse, jsYaml.safeLoad];
|
|
26
|
+
|
|
21
27
|
function readConfiguration(args) {
|
|
22
28
|
let config = rc('markdownlint', {});
|
|
23
|
-
const projectConfigFile = '.markdownlint.json';
|
|
24
29
|
const userConfigFile = args.config;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
for (const projectConfigFile of projectConfigFiles) {
|
|
31
|
+
try {
|
|
32
|
+
fs.accessSync(projectConfigFile, fs.R_OK);
|
|
33
|
+
const projectConfig = markdownlint.readConfigSync(projectConfigFile, configFileParsers);
|
|
34
|
+
config = extend(config, projectConfig);
|
|
35
|
+
break;
|
|
36
|
+
} catch (error) {
|
|
37
|
+
// Ignore failure
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
40
|
// Normally parsing this file is not needed,
|
|
32
41
|
// because it is already parsed by rc package.
|
|
33
42
|
// However I have to do it to overwrite configuration
|
|
34
|
-
// from .markdownlint.json.
|
|
43
|
+
// from .markdownlint.{json,yaml,yml}.
|
|
44
|
+
|
|
35
45
|
if (userConfigFile) {
|
|
36
46
|
try {
|
|
37
|
-
const userConfig = markdownlint.readConfigSync(userConfigFile,
|
|
47
|
+
const userConfig = markdownlint.readConfigSync(userConfigFile, configFileParsers);
|
|
38
48
|
config = extend(config, userConfig);
|
|
39
|
-
} catch (
|
|
49
|
+
} catch (error) {
|
|
40
50
|
console.warn('Cannot read or parse config file', args.config);
|
|
41
51
|
}
|
|
42
52
|
}
|
|
53
|
+
|
|
43
54
|
return config;
|
|
44
55
|
}
|
|
45
56
|
|
|
@@ -54,6 +65,7 @@ function prepareFileList(files, fileExtensions, previousResults) {
|
|
|
54
65
|
} else {
|
|
55
66
|
extensionGlobPart += '{' + fileExtensions.join(',') + '}';
|
|
56
67
|
}
|
|
68
|
+
|
|
57
69
|
files = files.map(function (file) {
|
|
58
70
|
try {
|
|
59
71
|
if (fs.lstatSync(file).isDirectory()) {
|
|
@@ -67,9 +79,10 @@ function prepareFileList(files, fileExtensions, previousResults) {
|
|
|
67
79
|
return fileInfo.original;
|
|
68
80
|
});
|
|
69
81
|
}
|
|
82
|
+
|
|
70
83
|
return glob.sync(path.join(file, '**', extensionGlobPart), globOptions);
|
|
71
84
|
}
|
|
72
|
-
} catch (
|
|
85
|
+
} catch (error) {
|
|
73
86
|
// Not a directory, not a file, may be a glob
|
|
74
87
|
if (previousResults) {
|
|
75
88
|
const matcher = new minimatch.Minimatch(path.resolve(process.cwd(), file), globOptions);
|
|
@@ -79,8 +92,10 @@ function prepareFileList(files, fileExtensions, previousResults) {
|
|
|
79
92
|
return fileInfo.original;
|
|
80
93
|
});
|
|
81
94
|
}
|
|
95
|
+
|
|
82
96
|
return glob.sync(file, globOptions);
|
|
83
97
|
}
|
|
98
|
+
|
|
84
99
|
// File
|
|
85
100
|
return file;
|
|
86
101
|
});
|
|
@@ -121,11 +136,12 @@ function printResult(lintResult) {
|
|
|
121
136
|
// @see {@link https://github.com/igorshubovych/markdownlint-cli/pull/29#issuecomment-343535291}
|
|
122
137
|
process.exitCode = 1;
|
|
123
138
|
}
|
|
139
|
+
|
|
124
140
|
if (program.output) {
|
|
125
141
|
try {
|
|
126
142
|
fs.writeFileSync(program.output, lintResultString);
|
|
127
|
-
} catch (
|
|
128
|
-
console.warn('Cannot write to output file ' + program.output + ': ' +
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.warn('Cannot write to output file ' + program.output + ': ' + error.message);
|
|
129
145
|
process.exitCode = 2;
|
|
130
146
|
}
|
|
131
147
|
} else if (lintResultString) {
|
|
@@ -161,11 +177,13 @@ function tryResolvePath(filepath) {
|
|
|
161
177
|
// Node >= 8.9.0
|
|
162
178
|
return require.resolve(filepath, {paths: paths});
|
|
163
179
|
}
|
|
180
|
+
|
|
164
181
|
return Module._resolveFilename(filepath, {paths: paths});
|
|
165
182
|
}
|
|
183
|
+
|
|
166
184
|
// Maybe it is a path to package installed locally
|
|
167
185
|
return require.resolve(path.join(process.cwd(), filepath));
|
|
168
|
-
} catch (
|
|
186
|
+
} catch (error) {
|
|
169
187
|
return filepath;
|
|
170
188
|
}
|
|
171
189
|
}
|
|
@@ -174,15 +192,16 @@ function loadCustomRules(rules) {
|
|
|
174
192
|
return flatten(rules.map(function (rule) {
|
|
175
193
|
try {
|
|
176
194
|
const resolvedPath = [tryResolvePath(rule)];
|
|
177
|
-
const fileList = prepareFileList(resolvedPath, ['js']).map(function (filepath) {
|
|
195
|
+
const fileList = flatten(prepareFileList(resolvedPath, ['js']).map(function (filepath) {
|
|
178
196
|
return require(filepath.absolute);
|
|
179
|
-
});
|
|
197
|
+
}));
|
|
180
198
|
if (fileList.length === 0) {
|
|
181
199
|
throw new Error('No such rule');
|
|
182
200
|
}
|
|
201
|
+
|
|
183
202
|
return fileList;
|
|
184
|
-
} catch (
|
|
185
|
-
console.error('Cannot load custom rule ' + rule + ': ' +
|
|
203
|
+
} catch (error) {
|
|
204
|
+
console.error('Cannot load custom rule ' + rule + ': ' + error.message);
|
|
186
205
|
process.exit(3);
|
|
187
206
|
}
|
|
188
207
|
}));
|
|
@@ -209,6 +228,7 @@ function lintAndPrint(stdin, files) {
|
|
|
209
228
|
stdin: stdin
|
|
210
229
|
};
|
|
211
230
|
}
|
|
231
|
+
|
|
212
232
|
const lintResult = markdownlint.sync(lintOptions);
|
|
213
233
|
printResult(lintResult);
|
|
214
234
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdownlint-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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
|
+
"node": ">=8"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"invalid": "node ./markdownlint.js --config test/test-config.json -- test/incorrect.md",
|
|
@@ -40,22 +40,20 @@
|
|
|
40
40
|
"deep-extend": "~0.5.1",
|
|
41
41
|
"get-stdin": "~5.0.1",
|
|
42
42
|
"glob": "~7.1.2",
|
|
43
|
-
"js-yaml": "
|
|
43
|
+
"js-yaml": "^3.13.1",
|
|
44
44
|
"lodash.differencewith": "~4.5.0",
|
|
45
45
|
"lodash.flatten": "~4.4.0",
|
|
46
|
-
"markdownlint": "~0.
|
|
46
|
+
"markdownlint": "~0.14.1",
|
|
47
47
|
"minimatch": "~3.0.4",
|
|
48
48
|
"rc": "~1.2.7"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"ava": "^
|
|
52
|
-
"
|
|
53
|
-
"babel-preset-stage-2": "^6.5.0",
|
|
54
|
-
"execa": "^0.6.3",
|
|
51
|
+
"ava": "^1.4.1",
|
|
52
|
+
"execa": "^1.0.0",
|
|
55
53
|
"husky": "^0.11.3",
|
|
56
54
|
"tap-growl": "^1.1.2",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
55
|
+
"test-rule-package": "./test/custom-rules/test-rule-package",
|
|
56
|
+
"xo": "*"
|
|
59
57
|
},
|
|
60
58
|
"xo": {
|
|
61
59
|
"space": true,
|
|
@@ -63,6 +61,7 @@
|
|
|
63
61
|
"linebreak-style": 0,
|
|
64
62
|
"no-var": 0,
|
|
65
63
|
"prefer-arrow-callback": 0,
|
|
64
|
+
"promise/prefer-await-to-then": 0,
|
|
66
65
|
"object-shorthand": 0
|
|
67
66
|
}
|
|
68
67
|
},
|
|
@@ -71,13 +70,6 @@
|
|
|
71
70
|
"test/**/*.js",
|
|
72
71
|
"!test/custom-rules/**/*.js"
|
|
73
72
|
],
|
|
74
|
-
"failFast": true
|
|
75
|
-
"babel": {
|
|
76
|
-
"presets": [
|
|
77
|
-
"es2015",
|
|
78
|
-
"stage-2"
|
|
79
|
-
],
|
|
80
|
-
"plugins": []
|
|
81
|
-
}
|
|
73
|
+
"failFast": true
|
|
82
74
|
}
|
|
83
75
|
}
|