Skip to content

Commit

Permalink
Merge pull request #54 from hacker112/master
Browse files Browse the repository at this point in the history
Added support for jshint extends option
  • Loading branch information
cfjedimaster committed Jun 2, 2014
2 parents ec33c9d + 6ead2d7 commit 7721aa9
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ define(function (require, exports, module) {
* Reads configuration file in the specified directory. Returns a promise for configuration object.
*
* @param {string} dir absolute path to a directory.
* @param {string} configFileName name of the configuration file (optional)
*
* @returns {$.Promise} a promise to return configuration object.
*/
function _readConfig(dir) {
function _readConfig(dir, configFileName) {
var result = new $.Deferred(),
file;
file = FileSystem.getFileForPath(dir + _configFileName);
configFileName = configFileName || _configFileName;
file = FileSystem.getFileForPath(dir + configFileName);
file.read(function (err, content) {
if (!err) {
var cfg = {},
Expand All @@ -123,10 +125,26 @@ define(function (require, exports, module) {
result.reject(e);
return;
}
cfg.globals = config.globals || {};
if (config.globals) { delete config.globals; }
cfg.options = config;
result.resolve(cfg);
// Load any base config defined by "extends".
// The same functionality as in
// jslints -> cli.js -> loadConfig -> if (config['extends'])...
var baseConfigResult = $.Deferred();
if (config.extends) {
var extendFile = FileSystem.getFileForPath(dir + config.extends);
baseConfigResult = _readConfig(extendFile.parentPath, extendFile.name);
delete config.extends;
}
else {
baseConfigResult.resolve({});
}
baseConfigResult.done( function (baseConfig) {
cfg.globals = $.extend({}, baseConfig.globals, config.globals);
if (config.globals) { delete config.globals; }
cfg.options = $.extend({}, baseConfig.options, config);
result.resolve(cfg);
}).fail(function (e) {
result.reject(e);
});
} else {
result.reject(err);
}
Expand Down

0 comments on commit 7721aa9

Please sign in to comment.