diff --git a/README.md b/README.md index 6d299d8..cf0eaef 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ This package will run against your currently open file as you type and when you Included features === * Supports jshintConfig in package.json - * Supports custom .jshintrc file in project root + * Supports custom .jshintrc file in project root and all parent directories * Line number turns red when error on that line * Once you move your cursor to a line with an error, it will show in the status bar. * Configure how you want JSHint to run. diff --git a/lib/atom-jshint.js b/lib/atom-jshint.js index 3d38712..110e14c 100644 --- a/lib/atom-jshint.js +++ b/lib/atom-jshint.js @@ -5,6 +5,7 @@ var JSHINT_Worker = null; var Subscriber = require('emissary').Subscriber; var fs = require('fs'); +var path = require('path'); module.exports = AtomJshint = (function(){ JSHINT_Worker = cp.fork(__dirname + '/worker.js'); @@ -154,15 +155,21 @@ module.exports = AtomJshint = (function(){ return this.setConfig(packageJson.jshintConfig); } } - if( fs.existsSync(atom.project.path + '/.jshintrc') ){ - var configFile = fs.readFileSync(atom.project.path + '/.jshintrc','UTF8'); - var conf = {}; - try { - conf = JSON.parse(configFile); - } catch(e){ - console.error('error parsing config file'); + var workingPath = atom.project.path || ''; + var dirs = workingPath.split(path.sep); + while ( dirs.length >= 1 ) { + var configPath = path.join(dirs.join(path.sep), '/.jshintrc'); + if( fs.existsSync(configPath) ){ + var configFile = fs.readFileSync(configPath, 'UTF8'); + var conf = {}; + try { + conf = JSON.parse(configFile); + } catch(e){ + console.error('error parsing config file'); + } + return this.setConfig(conf); } - return this.setConfig(conf); + dirs.pop(); } };