@@ -12,14 +12,38 @@ define(function (require, exports, module) {
1212 var CodeInspection = brackets . getModule ( "language/CodeInspection" ) ,
1313 FileSystem = brackets . getModule ( "filesystem/FileSystem" ) ,
1414 FileUtils = brackets . getModule ( "file/FileUtils" ) ,
15+ PreferencesManager = brackets . getModule ( "preferences/PreferencesManager" ) ,
1516 ProjectManager = brackets . getModule ( "project/ProjectManager" ) ,
1617 defaultConfig = {
1718 "options" : { "undef" : true } ,
1819 "globals" : { }
1920 } ;
2021
2122 require ( "jshint/jshint" ) ;
23+
24+ var PREF_SCAN_PROJECT_ONLY = "scanProjectOnly" ,
25+ JSHINT_NAME = "JSHint" ;
26+
27+ var pm = PreferencesManager . getExtensionPrefs ( "jshint" ) ;
28+
29+ pm . definePreference ( PREF_SCAN_PROJECT_ONLY , "boolean" , false )
30+ . on ( "change" , function ( e , d ) {
31+ var val = pm . get ( PREF_SCAN_PROJECT_ONLY ) ;
32+ if ( _scanProjectOnly !== val ) {
33+ _scanProjectOnly = val ;
34+ CodeInspection . requestRun ( JSHINT_NAME ) ;
35+ }
36+ } ) ;
2237
38+ /**
39+ * Extension preference which when set to true will limit the look up for configuration file
40+ * to the project sub-tree. If false, the entire file tree will be searched. The default is
41+ * false.
42+ * @private
43+ * @type {boolean }
44+ */
45+ var _scanProjectOnly = pm . get ( PREF_SCAN_PROJECT_ONLY ) ;
46+
2347 /**
2448 * @private
2549 * @type {string }
@@ -80,8 +104,6 @@ define(function (require, exports, module) {
80104 } else {
81105 return null ;
82106 }
83-
84-
85107 }
86108
87109 /**
@@ -259,22 +281,30 @@ define(function (require, exports, module) {
259281 var projectRootEntry = ProjectManager . getProjectRoot ( ) ,
260282 result = new $ . Deferred ( ) ,
261283 relPath ,
284+ rootPath ,
262285 file ,
263286 config ;
264287
265288 if ( ! projectRootEntry ) {
266289 return result . reject ( ) . promise ( ) ;
267290 }
268291
269- // for files outside the project root, use default config
270- if ( ! ( relPath = FileUtils . getRelativeFilename ( projectRootEntry . fullPath , fullPath ) ) ) {
292+ if ( ! _scanProjectOnly ) {
293+ // scan entire filesystem
294+ rootPath = projectRootEntry . fullPath . substring ( 0 , projectRootEntry . fullPath . indexOf ( "/" ) + 1 ) ;
295+ } else {
296+ rootPath = projectRootEntry . fullPath ;
297+ }
298+
299+ // for files outside the root, use default config
300+ if ( ! ( relPath = FileUtils . getRelativeFilename ( rootPath , fullPath ) ) ) {
271301 result . resolve ( defaultConfig ) ;
272302 return result . promise ( ) ;
273303 }
274304
275305 relPath = FileUtils . getDirectoryPath ( relPath ) ;
276306
277- _lookupAndLoad ( projectRootEntry . fullPath , relPath , _readConfig )
307+ _lookupAndLoad ( rootPath , relPath , _readConfig )
278308 . done ( function ( cfg ) {
279309 result . resolve ( cfg ) ;
280310 } ) ;
@@ -305,7 +335,7 @@ define(function (require, exports, module) {
305335 }
306336
307337 CodeInspection . register ( "javascript" , {
308- name : "JSHint" ,
338+ name : JSHINT_NAME ,
309339 scanFile : handleHinter ,
310340 scanFileAsync : handleHinterAsync
311341 } ) ;
0 commit comments