rizowski/eslint-watch

Is the plugin linting only one file when it changes?

Closed this issue · 4 comments

Environment

  • Node Version: 6.11.0
  • Eslint-Watch Version: 3.1.0
  • Eslint Version: 3.19.0

Basic Description of the problem

I noticed when running your plugin, that if I have two files with errors, but save only one of them, that the linter outputs errors for both.

I very briefly looked into your source, and it looks like chokidar should be passing changed files only to your lintFile() function, so it seems strange that the linter is showing all the errors:

  chokidar.watch(watchDir, chokidarOptions)
    .on(events.change, function changeEvent(path) {
      logger.debug('Changed:', path);
      if (!cli.isPathIgnored(path) && isWatchableExtension(path, options.ext)) {
        const watchPath = options.changed ? [path] : watchDir;
        lintFile(watchPath);
      }
    }).on('error', logger.error);

In the past, I've written almost the same code for a gulp watch / lint that lints only the changed file.

From memory, I think I had to add a slight delay so that PHPStorm finished doing things with temp files, but the result were far, far increased time to linter output (obviously!).

Is your code linting only changed files, is this how you designed it, and do you think your code is working as expected?

Cheers,
Dave

Depending on your argument string, eslint-watch with the --watch flag will report all errors and warnings on the initial execution. After saving a file, depending on if you have --changed enabled, it will either lint a single file (--changed) or lint all files in the directory path you passed esw. (defaults to ./) This line is the key to that functionality watcher#110.

That makes perfect sense!

That being the case, and in lieu of me reading the f.ing docs, might I make a couple of suggestions for the readme?

It would be cool if you broke out the options options into sections, perhaps for watch, linting, and debugging, or maybe your plugin vs ESLint.

Also, perhaps a couple of common use cases. It took me a while this morning to work out I needed --watch and you just told me I needed --changed.

It would at least get someone who's coming to a project and has done a quick google to find a plugin they think they should exist (i.e. yours!) and get up and running quick.

But I should totally have looked at the options :D

I am closing this issue. If you want to create a PR with the document changes you suggested above, you are more than welcome.

OK, thanks :)