aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
256 stars 124 forks source link

ESLint errors not reported in VS 2015 #727

Open corydeppen opened 8 years ago

corydeppen commented 8 years ago

I'm running VS 2015 Update 3, ASP.NET and Web Tools 2015.1, and Microsoft .NET Core Tools (Preview 2) and for some reason I'm not seeing any errors being reported in the Error List when I open each file or right-click a file and select "Run Web Code Analysis". I have a .eslintrc file in the root of my MVC 5 app with just a few simple rules. I'm not sure if I should be seeing the contents of that file when I select Tools > Web Code Analysis > Edit ESLint settings, but I only see the contents of the .eslintrc file in my user directory. If I run the locally installed ESLint from the command line I can see the errors as expected.

This is very frustrating and quite confusing why this won't work. Any ideas what could be wrong or how I can troubleshoot this further?

alexgav commented 8 years ago

I'd be happy to take a look. Would you mind sharing your .eslintrc?

corydeppen commented 8 years ago

I appreciate you taking a look.

{
  "root": true,
  "env": {
    "browser": true,
    "commonjs": true,
    "jquery": true
  },
  "parserOptions": {
    "ecmaVersion": 5,
    "sourceType": "module"
  },
  "rules": {
    "indent": [
      "error",
      4,
      {
        "SwitchCase": 1
      }
    ],
    "linebreak-style": [
      "error",
      "windows"
    ],
    "quotes": [
      "error",
      "single"
    ],
    "semi": [
      "error",
      "always"
    ]
  },
  "globals": {
    "_": true,
    "ko": true,
    "toastr": true
  }
}
markvp commented 8 years ago

We experienced this issue too.

While they try to fix it... try this work-around...

Check the Web\External folder in your VS installation folder (often C:\Program Files (x86)\Microsoft Visual Studio 14.0) for a file named eslint.cmd

If it doesn't exist, open a command prompt in that folder and type npm install eslint

If this doesn't fix your issue (or you already had an eslint.cmd file), add the full location of that direction to your PATH environment variable. e.g. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External.

(See google for instructions as it depends on your windows OS version).

If neither of these fix the issue, try manually deleting the eslint subfolder in the node_modules folder and the two eslint files in the Web\External folder. Then re-attempt the install above using a command prompt with elevated privileges (running as Administrator).

corydeppen commented 8 years ago

@markvp Thanks, ESLint wasn't installed into the Web\External directory. Once I explicitly installed it in that location the errors were displayed as expected in the Error List.

I don't know what caused it not to be installed there, but I'm hopeful the resolution will be to use the version of eslint installed in the project before looking globally or in the Web\External directory.

I'll leave this open in case it's confirmed as a bug and a TFS work item needs to be created from it.

ltvan commented 8 years ago

I got the same issue. There is no error or warning shown up. The Web\External\node_modules already has eslint installed but without the Web\External\eslint.cmd. I created one but still no help. I also have nodejs installed so I also tried to install eslint and all other eslint-* globally as same as the Web\External but also no help.

markvp commented 8 years ago

When you say "created one". How did you create it? I suggest that you delete the eslint files in that folder and the eslint subfolder in the node_modules sub folder, open a command prompt with elevated priviliges in the web\external folder and install eslint as per above: npm install eslint

ltvan commented 8 years ago

I created an eslint.cmd with following content: @"%~dp0\node" "%~dp0\node_modules\eslint\bin\eslint" %*

I also tried delete eslint subfolder and install another one, but it's still no help.

markvp commented 8 years ago

And have you confirmed that the path variable is set?

ltvan commented 8 years ago

Yes, I did, and it still not work.

ltvan commented 8 years ago

I don't know if it has anything related to, just for your information, I'm using Windows 10.

Is there any way to see the log file of the analyzer?

markvp commented 8 years ago

In a command prompt, go to your project folder and type eslint **

ltvan commented 8 years ago

Missing babel-eslint and eslint-config-defaults. First, it uses my global nodejs instead of the web/external, although I already added to PATH (appended at the end). Second, when I install the eslint-* set, I mistake the eslint-config-defaults with eslint-config-default (without s). Now it works. However, it doesn't use my local .eslintrc.yml in the project directory.

I suggest that you should do the same way as vscode-eslint, use the local / global nodejs if available instead of installing a separate node_modules. It will be more transparent to user, and let user decide what they need.

Thanks.

RichardD012 commented 8 years ago

I have this all setup as described in the fixes and it simply does not show errors in the tooling Preview 2 install. I can open a command prompt and type eslint \ and it works perfectly so it's correctly added to my path from the Web/External directory. It gives me the correct errors and everything. Nothing shows up in Visual Studio though.

Edit: As Itvan noted, its because its using a) the global settings of the npm install which doesn't make any sense. It's also using global eslint settings instead of project specific settings. I have projects with different settings.

Edit2: So this was because eslint-config-defaults wasn't installed in that folder, but that error wasn't showing up. Still, this should definitely be referencing the eslint file inside a project if it exists, while respecting the node_modules directory so things like plugins and configs aren't necessary.

patoncrispy commented 8 years ago

I too am having problems getting this to work. I've messed around with the Externals folder, but really, don't see why I have to. Surely if I have eslint installed in my local project, have .eslintrc configured then I would expect this to work, based purely on convention...? Why does Visual Studio have to be different to everything else out there? Seems a bit counter-intuitive to me...

VS Code seems to manage this perfectly, too! :disappointed:

markvp commented 8 years ago

@patoncrispy, no idea why, sorry...

Did you delete the node_modules\eslint subfolder in web\external folder and then re-install (as Administrator)?

@RichardD012, our experience was that it fails using the local .eslintrc files if it references a plugin that is not installed in the web\external folder. My understanding is that it accumulates configurations, rather than replacing them. So anything defined in the core .eslintrc + anything that is defined in your local .estlintrc file (as long as all plugins / etc referenced are valid).

brgrz commented 7 years ago

Same issue here with JSLint.

dietergeerts commented 7 years ago

Why are such simple things left unresolved? This should be basic functionality.... Still trying to get it to work for my team. Luckily I'm using IntelliJ IDEA instead.

Is this fixed in VS 2017 and using the local .eslintrc.js file? If it is, then I can ask to upgrade

jrhalchak commented 7 years ago

Agreed with @dietergeerts I'm kind of amazed no one seems to care about this issue. I'm stuck switching between VS and VS Code for a .NET React app... not ideal.

kirin-yuen commented 5 years ago

In my case, I'm a front-end developer, our backend language is .net, so the IDE is VS 2015 V14 Update 3, I'm going to use eslint in VS 2015. It's fine that using the web analyzer with the default config .eslintrc.

But, I've my own rule config of eslint, it's no work with my .eslintrc that place to project root and also overwrite the system user folder of the default config .eslintrc.

After studying, I found that the eslint version builtin VS 2015 that I am using is @2.00, but my rule config is base on @5.7, so maybe the syntax or rules not support with @2.00. syntax

I'm going to try uninstall the older verson of C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External, then install the latest one, but it told me there is no package.json file.

So how can I create a package.json with existed modules? And is this solution work? Thanks