Skip to content

Commit

Permalink
Fix #3. Read configuration also from .markdownlint.json
Browse files Browse the repository at this point in the history
  • Loading branch information
igorshubovych committed Mar 2, 2016
1 parent 2b8ad96 commit 78870f0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 78870f0

Please sign in to comment.