webpack-contrib / eslint-loader

[DEPRECATED] A ESlint loader for webpack
MIT License
1.06k stars 121 forks source link

Loader reporting syntax errors when dealing with typescript files #308

Closed filipekiss closed 4 years ago

filipekiss commented 4 years ago

Expected Behavior

I expect the loader to respect the .eslintrc.json and parse TypeScript correctly instead of parsing it as JavaScript

Actual Behavior

When I run the webpack config using eslint-loader, it tries to parse typescript files as JavaScript:

image

When I run eslint directly on the file, the errors are reported correctly:

image

Code

There's a repo with the code here

How Do We Reproduce?

Clone the repo and run npm run test. To see the expected result, run eslint src/*.ts

ricardogobbosouza commented 4 years ago

Hi @filipekiss Not a problem with eslint-loader, if you remove eslint-loader, same error happens, you need loader for typescript, try this:

// webpack.config.js
....
module: {
  rules: [
    { enforce: 'pre', test: /\.ts$/, exclude: /node_modules/, loader: 'eslint-loader' },
    { test: /\.tsx?$/, loader: "ts-loader" },
  ],
},
...
filipekiss commented 4 years ago

Hi @ricardogobbosouza, thank you for the explanation. It indeed worked when I added the ts-loader rule. Do you have any idea why do I need it, though? This particular case I only want to use webpack to watch-lint files.

Thanks for the help, appreciated! Cheers!

ricardogobbosouza commented 4 years ago

@filipekiss webpack does not handle typescript files. See https://webpack.js.org/guides/typescript/

You can use eslint-watch

filipekiss commented 4 years ago

I mean, do I still need the TS Loader for the eslint-loader in this case? Shouldn't eslint-loader just pass this to eslint and eslint itself will handle the TypeScript stuff?


(I'll close the issue because this is more curiosity than an issue related to eslint-loader. Thank you for your help!)

ricardogobbosouza commented 4 years ago

@filipekiss using loader yes, you will need to add ts-loader

You can try using the plugin https://github.com/webpack-contrib/eslint-webpack-plugin

filipekiss commented 4 years ago

Thank you, Ricardo! :D

alexander-akait commented 4 years ago

@ricardogobbosouza what is status of plugin? Any ETA wen we can deprecate loader in favor plugin?

ricardogobbosouza commented 4 years ago

@evilebottnawi The plugin was born very complete, but I need to make some adjustments, especially in the option lintDirtyModulesOnly, unfortunately we still have few downloads and therefore few reports of use. I think we can depreciate the loader as soon as webpack 5 as released

ricardogobbosouza commented 4 years ago

@evilebottnawi I just released eslint-webpack-plugin v0.1.0 I think we can already recommend the plugin, but I still doubt about deprecating eslint-loader

samywang92 commented 4 years ago

Edit: never mind I fixed issue! Thank you though :)

@ricardogobbosouza Hi Ricardo, I had a similar issue so I didn't want to open a new one.

When I use typescript 'as' keyword, causes eslint-loader to throw error on the 'as' - " Parsing error: Unexpected token, expected "," " even if I add ts-loader to config. If I remove eslint-loader completely, it works fine and no errors are thrown.

Example code of as usage:

const state = reactive({
      testVariable: [] as Array<string>,
})

I do not get any other issues with typescript syntax such as const newName: string = 'hello' currently using following:

In Nuxt environment