Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #52. Scan entire file tree for config by default. #55

Merged
merged 2 commits into from
Jun 5, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -217,22 +239,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 @@ -263,7 +293,7 @@ define(function (require, exports, module) {
}

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