Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

eslint-loader in watch mode only works when a new line is added #78

Closed
kiranps opened this issue Feb 4, 2016 · 12 comments
Closed

eslint-loader in watch mode only works when a new line is added #78

kiranps opened this issue Feb 4, 2016 · 12 comments

Comments

@kiranps
Copy link

kiranps commented Feb 4, 2016

No description provided.

@kiranps
Copy link
Author

kiranps commented Feb 4, 2016

i'm running eslint along with webpack

let a = 0

for above line esling gives error Missing semicolon

if i fixed it by adding ;

let a = 0;

watch mode does not reloads. if add another line

let a = 0;
let b = 0;

watch mode reloads

@MoOx
Copy link
Contributor

MoOx commented Feb 5, 2016

Maybe it's an webpack caching issue.
What other loaders are you using?
Can you try commenting that line https://github.com/MoOx/eslint-loader/blob/master/index.js#L111?

@kiranps
Copy link
Author

kiranps commented Feb 6, 2016

@MoOx commenting the line didn't worked

I also use babel loader, if i remove babel loader from webpack.config.js watch mode works perfectly

webpack.config.js

var path = require('path');
var webpack = require('webpack');

module.exports = {
  entry: './src/app.js',
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: 'bundle.js'
  },
  module: {
    preLoaders: [
      {test: /\.js$/, loader: "eslint-loader", exclude: /node_modules/}
    ],
    loaders: [
      {
        test: /\.js$/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015']
        }
      }
    ]
  },
  stats: {
    colors: true
  },
  watch: true
};

@kiranps
Copy link
Author

kiranps commented Feb 6, 2016

It looks like issue is with the webpack. with webpack-dev-server its working fine

railsed an issue in webpack

https://github.com/webpack/webpack/issues/2009

@MoOx
Copy link
Contributor

MoOx commented Feb 13, 2016 via email

@tvervest
Copy link

This issue might be related to #69.

My setup is identical to to the module section in kiranps' comment on Feb 6. Removing eslint or commenting out line 71 fixes the issue, but (obviously) disables linting. I also noticed that reloading works correctly when the build runs successfully on the initial run.

I hope we can fix this! I use this plugin on another project and it's very convenient, would be nice to be able to not have to constantly restart webpack if I was lazy the day before ;p

@andreypopp
Copy link

The issue is with how webpack reports errors, see this line. So the absence/presence of a semicolon doesn't really make a difference for webpack as babel loader generates identical code.

btw. I created a plugin for webpack called prefetch-context-webpack-plugin which works very well with eslint-loader:

import PrefetchContext from 'prefetch-context-webpack-plugin'

module.exports = {

  ...

  plugins: [
    new PrefetchContext({
      context: './src',
      loader: 'eslint-loader',
    })
  ]
}

All it does is it prefetches every file under a directory and processes it through a loader (eslint-loader in this example). This matches what eslint does, processes every file in a directory and not only those which are in the bundle. Still it reuses webpack caches and so it is fast.

I also fixed error reporting in the plugin, see here though it's a little bit hacky and I'd prefer to raise an issue in webpack regarding that use case.

@thetrevdev
Copy link

See webpack/webpack#2538

@rickyk586
Copy link

This solution worked for me: webpack/webpack#675 (comment)

@sth
Copy link

sth commented Jan 28, 2017

As a work around until webpack fixes its error reporting I added a plugin to my project that makes sure the babel output changes even for trivial changes in the input. This forces webpack to reprocesses the changed file which displays the updated eslint messages.

kadamwhite added a commit to mitmedialab/ajl.ai that referenced this issue Mar 6, 2017
See webpack-contrib/eslint-loader#78 for one issue with
this approach: changes that do not affect the AST (purely stylistic
things like adding a missing trailing comma) will not trigger a bundle
re-build. To be sure you're seeing all available lint output, run the
`npm run lint` command from the console.

Also alters the NPM scripts so that "npm test" is used in CI
@rafalp
Copy link

rafalp commented Oct 26, 2017

Note that this issue has been fixed as of Webpack 3

@MoOx
Copy link
Contributor

MoOx commented Oct 26, 2017

Good to know!

@MoOx MoOx closed this as completed Oct 26, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants