markdownlint-cli
Advanced tools
Comparing version 0.13.0 to 0.14.0
@@ -18,14 +18,23 @@ #!/usr/bin/env node | ||
const minimatch = require('minimatch'); | ||
const pkg = require('./package'); | ||
const projectConfigFiles = [ | ||
'.markdownlint.json', | ||
'.markdownlint.yaml', | ||
'.markdownlint.yml' | ||
]; | ||
const configFileParsers = [JSON.parse, jsYaml.safeLoad]; | ||
function readConfiguration(args) { | ||
let config = rc('markdownlint', {}); | ||
const projectConfigFile = '.markdownlint.json'; | ||
const userConfigFile = args.config; | ||
try { | ||
fs.accessSync(projectConfigFile, fs.R_OK); | ||
const projectConfig = markdownlint.readConfigSync(projectConfigFile); | ||
config = extend(config, projectConfig); | ||
} catch (err) { | ||
for (const projectConfigFile of projectConfigFiles) { | ||
try { | ||
fs.accessSync(projectConfigFile, fs.R_OK); | ||
const projectConfig = markdownlint.readConfigSync(projectConfigFile, configFileParsers); | ||
config = extend(config, projectConfig); | ||
break; | ||
} catch (error) { | ||
// Ignore failure | ||
} | ||
} | ||
@@ -35,11 +44,13 @@ // Normally parsing this file is not needed, | ||
// However I have to do it to overwrite configuration | ||
// from .markdownlint.json. | ||
// from .markdownlint.{json,yaml,yml}. | ||
if (userConfigFile) { | ||
try { | ||
const userConfig = markdownlint.readConfigSync(userConfigFile, [JSON.parse, jsYaml.safeLoad]); | ||
const userConfig = markdownlint.readConfigSync(userConfigFile, configFileParsers); | ||
config = extend(config, userConfig); | ||
} catch (err) { | ||
} catch (error) { | ||
console.warn('Cannot read or parse config file', args.config); | ||
} | ||
} | ||
return config; | ||
@@ -59,2 +70,3 @@ } | ||
} | ||
files = files.map(function (file) { | ||
@@ -73,5 +85,6 @@ try { | ||
} | ||
return glob.sync(path.join(file, '**', extensionGlobPart), globOptions); | ||
} | ||
} catch (err) { | ||
} catch (error) { | ||
// Not a directory, not a file, may be a glob | ||
@@ -86,4 +99,6 @@ if (previousResults) { | ||
} | ||
return glob.sync(file, globOptions); | ||
} | ||
// File | ||
@@ -129,7 +144,8 @@ return file; | ||
} | ||
if (program.output) { | ||
try { | ||
fs.writeFileSync(program.output, lintResultString); | ||
} catch (err) { | ||
console.warn('Cannot write to output file ' + program.output + ': ' + err.message); | ||
} catch (error) { | ||
console.warn('Cannot write to output file ' + program.output + ': ' + error.message); | ||
process.exitCode = 2; | ||
@@ -170,7 +186,9 @@ } | ||
} | ||
return Module._resolveFilename(filepath, {paths: paths}); | ||
} | ||
// Maybe it is a path to package installed locally | ||
return require.resolve(path.join(process.cwd(), filepath)); | ||
} catch (err) { | ||
} catch (error) { | ||
return filepath; | ||
@@ -184,11 +202,12 @@ } | ||
const resolvedPath = [tryResolvePath(rule)]; | ||
const fileList = prepareFileList(resolvedPath, ['js']).map(function (filepath) { | ||
const fileList = flatten(prepareFileList(resolvedPath, ['js']).map(function (filepath) { | ||
return require(filepath.absolute); | ||
}); | ||
})); | ||
if (fileList.length === 0) { | ||
throw new Error('No such rule'); | ||
} | ||
return fileList; | ||
} catch (err) { | ||
console.error('Cannot load custom rule ' + rule + ': ' + err.message); | ||
} catch (error) { | ||
console.error('Cannot load custom rule ' + rule + ': ' + error.message); | ||
process.exit(3); | ||
@@ -220,2 +239,3 @@ } | ||
} | ||
const lintResult = markdownlint.sync(lintOptions); | ||
@@ -222,0 +242,0 @@ printResult(lintResult); |
{ | ||
"name": "markdownlint-cli", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "MarkdownLint Command Line Interface", | ||
@@ -46,3 +46,3 @@ "main": "markdownlint.js", | ||
"lodash.flatten": "~4.4.0", | ||
"markdownlint": "~0.11.0", | ||
"markdownlint": "~0.12.0", | ||
"minimatch": "~3.0.4", | ||
@@ -49,0 +49,0 @@ "rc": "~1.2.7" |
@@ -35,3 +35,3 @@ # markdownlint-cli [![Travis CI Build Status][travis-badge]][travis-url] [![AppVeyor CI Build Status][appveyor-badge]][appveyor-url] | ||
Configuration is stored JSON or INI files in the same [config format][config]. | ||
Configuration is stored in JSON, YAML or INI files in the same [config format][config]. | ||
@@ -52,3 +52,3 @@ The example of configuration file: | ||
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. | ||
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. | ||
@@ -55,0 +55,0 @@ ## Related |
13662
217
+ Addedmarkdownlint@0.12.0(transitive)
- Removedmarkdownlint@0.11.0(transitive)
Updatedmarkdownlint@~0.12.0