@@ -95,6 +95,7 @@ define(function (require, exports, module) {
9595 function handleHinterAsync ( text , fullPath ) {
9696 var deferred = new $ . Deferred ( ) ;
9797 _loadConfig ( fullPath )
98+ . then ( _applyOverrides ( fullPath ) )
9899 . done ( function ( cfg ) {
99100 deferred . resolve ( handleHinter ( text , fullPath , cfg ) ) ;
100101 } ) ;
@@ -151,6 +152,47 @@ define(function (require, exports, module) {
151152 } ) ;
152153 return result . promise ( ) ;
153154 }
155+
156+ /**
157+ * Applies per-file overrides, if any were provided in the configuration.
158+ * Follows format supported in commit #df60b9c on JSHint repository:
159+ * https://github.com/jshint/jshint/commit/df60b9c75daa4321a4d064fcab04e14692c94039
160+ *
161+ * @param {string } fullPath absolute path to the processed file
162+ * @returns {Function } function that returns a promise for configuration object with overrides applied
163+ */
164+ function _applyOverrides ( fullPath ) {
165+
166+ var basePath = ProjectManager . getProjectRoot ( ) . fullPath ,
167+ filePath = FileUtils . getRelativeFilename ( basePath , fullPath ) ;
168+
169+ return function ( cfg ) {
170+
171+ var bundle ,
172+ has = Object . prototype . hasOwnProperty . call . bind ( Object . prototype . hasOwnProperty ) ,
173+ overrides = cfg . options . overrides ,
174+ pattern ;
175+
176+ if ( overrides ) {
177+ delete cfg . options . overrides ;
178+
179+ for ( pattern in overrides ) {
180+ if ( has ( overrides , pattern ) && ( new RegExp ( pattern ) ) . test ( filePath ) ) {
181+ bundle = overrides [ pattern ] ;
182+
183+ if ( bundle . globals ) {
184+ $ . extend ( true , cfg . globals , bundle . globals ) ;
185+ delete bundle . globals ;
186+ }
187+ $ . extend ( true , cfg . options , bundle ) ;
188+
189+ }
190+ }
191+ }
192+
193+ return cfg ;
194+ } ;
195+ }
154196
155197 /**
156198 * Looks up the configuration file in the filesystem hierarchy and loads it.
0 commit comments