From 78870f04a7823a03cf1c642b0e111187293f49b1 Mon Sep 17 00:00:00 2001 From: Igor Shubovych Date: Wed, 2 Mar 2016 22:46:12 +0200 Subject: [PATCH] Fix #3. Read configuration also from .markdownlint.json --- markdownlint.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/markdownlint.js b/markdownlint.js index 6a752276d..89a44529e 100755 --- a/markdownlint.js +++ b/markdownlint.js @@ -13,11 +13,27 @@ var markdownlint = require('markdownlint'); var path = require('path'); var glob = require('glob'); +function readJSONFrom(file) { + return JSON.parse(fs.readFileSync(file)); +} + function readConfiguration(args) { var config = rc('markdownlint', {}); - if (args.config) { + var projectConfigFile = '.markdownlint.json'; + var userConfigFile = args.config; + try { + fs.accessSync(projectConfigFile, fs.R_OK); + var projectConfig = readJSONFrom(projectConfigFile); + config = extend(config, projectConfig); + } catch (err) { + } + // Normally parsing this file is not needed, + // because it is already parsed by rc package. + // However I have to do it to overwrite configuration + // from .markdownlint.json. + if (userConfigFile) { try { - var userConfig = JSON.parse(fs.readFileSync(args.config)); + var userConfig = readJSONFrom(userConfigFile); config = extend(config, userConfig); } catch (e) { console.warn('Cannot read or parse config file', args.config);