microsoft / vscode-typescript-tslint-plugin

VS Code extension that provides TSLint support using the typescript-tslint-plugin
https://marketplace.visualstudio.com/items?itemName=ms-vscode.vscode-typescript-tslint-plugin
MIT License
188 stars 34 forks source link

Alert about tslint.json bad format. #45

Closed nathanredblur closed 5 years ago

nathanredblur commented 5 years ago

I lost like 3 hours trying to find why my tslint plugin didn't work. Then I fount that my tslint.json file had an extra comma that disable it.

VScode set the lenguage to JSON with comments by default, and I did't see the error.

here an example:

{
  "extends": "tslint-config-airbnb",
  "rules": {
    "import-name": [ true, {
      "classnames": "cx",
    }]
  }
}

I wouldn't lost all this 3 hours if someone point this extra comma after "cx".

adenflorian commented 5 years ago

This cost me a bit of time too, and now I'm trying to find a github issue on the right project to make sure this doesn't happen to someone else. I'm not sure if this is a vscode, tslint, or this project, or some other project's issue. What would we want to change?

From reading issues on multiple projects, these seem to be the options:

  1. Make jsonc (vscode's JSON parser?) not allow trailing commas a. Related: https://github.com/Microsoft/vscode/issues/43825
  2. Make tslint allow trailing commas a. Related: https://github.com/palantir/tslint/issues/1721
  3. Make sure that tsconfig.json is not used with jsonc, and instead parse it as vanilla JSON a. I'm not sure what is telling vscode to use jsonc for this file. Is it vscode itself, or this tslint extension?

Thoughts?

adenflorian commented 5 years ago

Workaround:

Add to settings.json:

"files.associations": {
    "tsconfig.json": "json"
},

Downside is you'll get errors for having comments in there.

Saying that, I think the best way forward might be to push for trailing commas to be allowed by tslint, because all the other options are breaking changes.

mjbvz commented 5 years ago

Caused by fix for #8. TSlint support comments in config files but not trailing commas and there is no equivalent language mode for this in VS Code. Proper support for trailing commas requires https://github.com/palantir/tslint/issues/1721 upstream.

Until then, you can make such errors more obvious with the suggestion in https://github.com/Microsoft/vscode-typescript-tslint-plugin/issues/45#issuecomment-468136545