From b46e53799d6573fdf32d1c598e4ebbe4ed9e5dc6 Mon Sep 17 00:00:00 2001 From: Arzhan Kinzhalin Date: Thu, 5 Jun 2014 14:43:41 -0300 Subject: [PATCH 1/2] Fix #52. Scan entire file tree for config. Also, add jshint.scanProjectOnly extension pref. When set to true would only scan up to the project root. --- main.js | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/main.js b/main.js index 4a2cc8f..448b141 100644 --- a/main.js +++ b/main.js @@ -12,6 +12,7 @@ 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}, @@ -19,7 +20,30 @@ define(function (require, exports, module) { }; 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} @@ -42,6 +66,8 @@ define(function (require, exports, module) { config = defaultConfig; } + _scanProjectOnly = pm.get(PREF_SCAN_PROJECT_ONLY); + var resultJH = JSHINT(text, config.options, config.globals); if (!resultJH) { @@ -80,8 +106,6 @@ define(function (require, exports, module) { } else { return null; } - - } /** @@ -217,6 +241,7 @@ define(function (require, exports, module) { var projectRootEntry = ProjectManager.getProjectRoot(), result = new $.Deferred(), relPath, + rootPath, file, config; @@ -224,15 +249,22 @@ define(function (require, exports, module) { 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); }); @@ -263,7 +295,7 @@ define(function (require, exports, module) { } CodeInspection.register("javascript", { - name: "JSHint", + name: JSHINT_NAME, scanFile: handleHinter, scanFileAsync: handleHinterAsync }); From 895fb37bd970b76b03509cbc624536771511ee5f Mon Sep 17 00:00:00 2001 From: Arzhan Kinzhalin Date: Thu, 5 Jun 2014 14:54:04 -0300 Subject: [PATCH 2/2] Remove unnecessary re-reading of the preference. --- main.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.js b/main.js index 448b141..431cbdc 100644 --- a/main.js +++ b/main.js @@ -66,8 +66,6 @@ define(function (require, exports, module) { config = defaultConfig; } - _scanProjectOnly = pm.get(PREF_SCAN_PROJECT_ONLY); - var resultJH = JSHINT(text, config.options, config.globals); if (!resultJH) {