Skip to content

Commit

Permalink
Fixed #741: expose loadConfig from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
valueof committed Jul 1, 2013
1 parent b39e2ac commit 28dae4b
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,6 @@ function removeComments(str) {
return str;
}

/**
* Loads and parses a configuration file.
*
* @param {string} fp a path to the config file
* @returns {object} config object
*/
function loadConfig(fp) {
if (!fp) {
return {};
}

if (!shjs.test("-e", fp)) {
cli.error("Can't find config file: " + fp);
process.exit(1);
}

try {
return JSON.parse(removeComments(shjs.cat(fp)));
} catch (err) {
cli.error("Can't parse config file: " + fp);
process.exit(1);
}
}

/**
* Tries to find a configuration file in either project directory
* or in the home directory. Configuration files are named
Expand Down Expand Up @@ -293,6 +269,30 @@ function lint(code, results, config, data, file) {
}

var exports = {
/**
* Loads and parses a configuration file.
*
* @param {string} fp a path to the config file
* @returns {object} config object
*/
loadConfig: function (fp) {
if (!fp) {
return {};
}

if (!shjs.test("-e", fp)) {
cli.error("Can't find config file: " + fp);
process.exit(1);
}

try {
return JSON.parse(removeComments(shjs.cat(fp)));
} catch (err) {
cli.error("Can't parse config file: " + fp);
process.exit(1);
}
},

/**
* Gathers all files that need to be linted
*
Expand Down Expand Up @@ -350,7 +350,7 @@ var exports = {
}

files.forEach(function (file) {
var config = opts.config || loadConfig(findConfig(file));
var config = opts.config || exports.loadConfig(findConfig(file));
var code;

try {
Expand Down Expand Up @@ -392,7 +392,7 @@ var exports = {
// Use config file if specified
var config;
if (options.config) {
config = loadConfig(options.config);
config = exports.loadConfig(options.config);
}

switch (true) {
Expand Down

0 comments on commit 28dae4b

Please sign in to comment.