Skip to content

Commit

Permalink
Merge pull request #55 from busykai/fix-52-scan-entire-tree
Browse files Browse the repository at this point in the history
Fix #52. Scan entire file tree for config by default.
  • Loading branch information
cfjedimaster committed Jun 5, 2014
2 parents 1ef58cf + 895fb37 commit 8c1e7d2
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,38 @@ define(function (require, exports, module) {
var CodeInspection = brackets.getModule("language/CodeInspection"),
FileSystem = brackets.getModule("filesystem/FileSystem"),
FileUtils = brackets.getModule("file/FileUtils"),
PreferencesManager = brackets.getModule("preferences/PreferencesManager"),
ProjectManager = brackets.getModule("project/ProjectManager"),
defaultConfig = {
"options": {"undef": true},
"globals": {}
};

require("jshint/jshint");

var PREF_SCAN_PROJECT_ONLY = "scanProjectOnly",
JSHINT_NAME = "JSHint";

var pm = PreferencesManager.getExtensionPrefs("jshint");

pm.definePreference(PREF_SCAN_PROJECT_ONLY, "boolean", false)
.on("change", function (e, d) {
var val = pm.get(PREF_SCAN_PROJECT_ONLY);
if (_scanProjectOnly !== val) {
_scanProjectOnly = val;
CodeInspection.requestRun(JSHINT_NAME);
}
});

/**
* Extension preference which when set to true will limit the look up for configuration file
* to the project sub-tree. If false, the entire file tree will be searched. The default is
* false.
* @private
* @type {boolean}
*/
var _scanProjectOnly = pm.get(PREF_SCAN_PROJECT_ONLY);

/**
* @private
* @type {string}
Expand Down Expand Up @@ -80,8 +104,6 @@ define(function (require, exports, module) {
} else {
return null;
}


}

/**
Expand Down Expand Up @@ -259,22 +281,30 @@ define(function (require, exports, module) {
var projectRootEntry = ProjectManager.getProjectRoot(),
result = new $.Deferred(),
relPath,
rootPath,
file,
config;

if (!projectRootEntry) {
return result.reject().promise();
}

// for files outside the project root, use default config
if (!(relPath = FileUtils.getRelativeFilename(projectRootEntry.fullPath, fullPath))) {
if (!_scanProjectOnly) {
// scan entire filesystem
rootPath = projectRootEntry.fullPath.substring(0, projectRootEntry.fullPath.indexOf("/") + 1);
} else {
rootPath = projectRootEntry.fullPath;
}

// for files outside the root, use default config
if (!(relPath = FileUtils.getRelativeFilename(rootPath, fullPath))) {
result.resolve(defaultConfig);
return result.promise();
}

relPath = FileUtils.getDirectoryPath(relPath);

_lookupAndLoad(projectRootEntry.fullPath, relPath, _readConfig)
_lookupAndLoad(rootPath, relPath, _readConfig)
.done(function (cfg) {
result.resolve(cfg);
});
Expand Down Expand Up @@ -305,7 +335,7 @@ define(function (require, exports, module) {
}

CodeInspection.register("javascript", {
name: "JSHint",
name: JSHINT_NAME,
scanFile: handleHinter,
scanFileAsync: handleHinterAsync
});
Expand Down

0 comments on commit 8c1e7d2

Please sign in to comment.