Skip to content

Commit

Permalink
Watch for changes to files with custom extensions, Fixes #66
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinwoo committed Jan 28, 2016
1 parent 21c1d23 commit 105be9a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions spec/watcher-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,16 @@ describe('Watcher', function () {
expect(configForFileSpy).to.not.have.been.called;
});

it('calls getConfigForFile if the path does not match a custom extension', function(){
path = 'yup.js2';
watcher({ _: paths, ext: ['.js1', '.js2'] });
expect(configForFileSpy).to.have.been.called;
});

it('does not call getConfigForFile if the path does not match a custom extension', function(){
path = 'nope.js';
watcher({ _: paths, ext: ['.js1', '.js2'] });
expect(configForFileSpy).to.not.have.been.called;
});

});
9 changes: 7 additions & 2 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ function lintFile(path, config) {
logger.log(formatter(results));
}

function isWatchableExtension(filePath){
function isWatchableExtension(filePath, extensions) {
if (extensions) {
return _.contains(extensions, path.extname(filePath));
}

// Use the ESLint default extension, if none is provided
return _.contains(cli.options.extensions, path.extname(filePath));
}

module.exports = function watcher(options) {
chokidar.watch(options._, chokidarOptions)
.on(events.change, function (path) {
logger.debug('Changed:', path);
if(!cli.isPathIgnored(path) && isWatchableExtension(path)){
if (!cli.isPathIgnored(path) && isWatchableExtension(path, options.ext)) {
var config = cli.getConfigForFile(path);
lintFile(path, config);
}
Expand Down

0 comments on commit 105be9a

Please sign in to comment.