markdownlint-cli
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -8,3 +8,3 @@ #!/usr/bin/env node | ||
var program = require('commander'); | ||
var values = require('lodash.values'); | ||
var difference = require('lodash.difference'); | ||
var flatten = require('lodash.flatten'); | ||
@@ -44,10 +44,13 @@ var extend = require('deep-extend'); | ||
function prepareFileList(files) { | ||
var globOptions = { | ||
nodir: true | ||
}; | ||
files = files.map(function (file) { | ||
try { | ||
if (fs.lstatSync(file).isDirectory()) { | ||
return glob.sync(path.join(file, '**', '*.{md,markdown}')); | ||
return glob.sync(path.join(file, '**', '*.{md,markdown}'), globOptions); | ||
} | ||
} catch (err) { | ||
// Not a directory, not a file, may be a glob | ||
return glob.sync(file); | ||
return glob.sync(file, globOptions); | ||
} | ||
@@ -61,2 +64,3 @@ return file; | ||
var lintOptions = { | ||
resultVersion: 2, | ||
files: lintFiles, | ||
@@ -68,5 +72,24 @@ config: config | ||
function printResult(lintResult, hasErrors) { | ||
if (hasErrors) { | ||
console.error(lintResult.toString()); | ||
function printResult(lintResult) { | ||
var results = flatten(Object.keys(lintResult).map(function (file) { | ||
return lintResult[file].map(function (result) { | ||
return { | ||
file: file, | ||
lineNumber: result.lineNumber, | ||
names: result.ruleNames.join('/'), | ||
description: result.ruleDescription + | ||
(result.errorDetail ? ' [' + result.errorDetail + ']' : '') + | ||
(result.errorContext ? ' [Context: "' + result.errorContext + '"]' : '') | ||
}; | ||
}); | ||
})); | ||
if (results.length > 0) { | ||
results.sort(function (a, b) { | ||
return a.file.localeCompare(b.file) || a.lineNumber - b.lineNumber || | ||
a.names.localeCompare(b.names) || a.description.localeCompare(b.description); | ||
}); | ||
var lintResultString = results.map(function (result) { | ||
return result.file + ': ' + result.lineNumber + ': ' + result.names + ' ' + result.description; | ||
}).join('\n'); | ||
console.error(lintResultString); | ||
// Note: process.exit(1) will end abruptly, interrupting asynchronous IO | ||
@@ -78,19 +101,10 @@ // streams (e.g., when the output is being piped). Just set the exit code | ||
process.exitCode = 1; | ||
return; | ||
} | ||
var result = lintResult.toString(); | ||
if (result) { | ||
console.log(result); | ||
} | ||
} | ||
function notEmptyObject(item) { | ||
return Object.keys(item).length > 0; | ||
function concatArray(item, array) { | ||
array.push(item); | ||
return array; | ||
} | ||
function hasResultErrors(lintResult) { | ||
return values(lintResult).some(notEmptyObject); | ||
} | ||
program | ||
@@ -100,3 +114,4 @@ .version(pkg.version) | ||
.usage('[options] <files|directories|globs>') | ||
.option('-c, --config [configFile]', 'Configuration file'); | ||
.option('-c, --config [configFile]', 'configuration file') | ||
.option('-i, --ignore [file|directory|glob]', 'files to ignore/exclude', concatArray, []); | ||
@@ -106,10 +121,11 @@ program.parse(process.argv); | ||
var files = prepareFileList(program.args); | ||
var ignores = prepareFileList(program.ignore); | ||
var diff = difference(files, ignores); | ||
if (files && files.length > 0) { | ||
if (files.length > 0) { | ||
var config = readConfiguration(program); | ||
var lintResult = lint(files, config); | ||
var hasErrors = hasResultErrors(lintResult); | ||
printResult(lintResult, hasErrors); | ||
var lintResult = lint(diff, config); | ||
printResult(lintResult); | ||
} else { | ||
program.help(); | ||
} |
{ | ||
"name": "markdownlint-cli", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "MarkdownLint Command Line Interface", | ||
@@ -42,5 +42,5 @@ "main": "markdownlint.js", | ||
"glob": "~7.0.3", | ||
"lodash.flatten": "~4.3.0", | ||
"lodash.values": "~4.2.0", | ||
"markdownlint": "~0.6.4", | ||
"lodash.difference": "~4.5.0", | ||
"lodash.flatten": "~4.4.0", | ||
"markdownlint": "~0.7.0", | ||
"rc": "~1.1.6" | ||
@@ -47,0 +47,0 @@ }, |
@@ -22,5 +22,6 @@ # markdownlint-cli [![Travis CI Build Status][travis-badge]][travis-url] [![AppVeyor CI Build Status][appveyor-badge]][appveyor-url] | ||
-h, --help output usage information | ||
-V, --version output the version number | ||
-c, --config [configFile] Configuration file | ||
-h, --help output usage information | ||
-V, --version output the version number | ||
-c, --config [configFile] configuration file | ||
-i, --ignore [file|directory|glob] files to ignore/exclude | ||
``` | ||
@@ -27,0 +28,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9106
112
72
+ Addedlodash.difference@~4.5.0
+ Addedlodash.difference@4.5.0(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedmarkdown-it@8.4.0(transitive)
+ Addedmarkdownlint@0.7.0(transitive)
- Removedlodash.values@~4.2.0
- Removedlodash.flatten@4.3.0(transitive)
- Removedlodash.values@4.2.0(transitive)
- Removedmarkdown-it@8.3.2(transitive)
- Removedmarkdownlint@0.6.4(transitive)
Updatedlodash.flatten@~4.4.0
Updatedmarkdownlint@~0.7.0