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 35 forks source link

source.fixAll.tslint has no effect #76

Closed vaindil closed 5 years ago

vaindil commented 5 years ago

The extension page says to use the setting below to enforce format on save:

"editor.codeActionsOnSave": {
    "source.fixAll.tslint": true
}

This has no effect, however. tslint only formats on save if the key is source.fixAll, adding the .tslint to the end breaks it.

VS Code version 1.33.0-insider Extension version 1.0.0

mjbvz commented 5 years ago

Are you sure? "source.fixAll.tslint" works just fine in my testing.

Please provide more details about your environment if it isn't working

vaindil commented 5 years ago

Yes, that setting didn't work for myself or a coworker. Making the change to remove .tslint fixed it for both of us.

I can provide any info you need, what would be helpful? We're both on Windows 10, both using extension version 1.0.0. I'm on VS Code 1.33.0-insider, coworker is on 1.32.3, both user setup.

I have tslint 5.14.0 installed globally, the project is using 5.13.1. I have TS 3.3.4 installed globally, project is using 3.2.4.

crushjz commented 5 years ago

Same issue also for me, but only when upgrading to VSCode >= 1.33.

I have also added a shortcut for the autoFix, but nothing happens.

Key binding:

{
    "key": "shift+alt+d",
    "command": "editor.action.codeAction",
    "args": {
      "kind": "source.fixAll.tslint",
      "apply": "first"
    },
    "when": "textInputFocus && !editorReadonly"
  }

VSCode settings:

"[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
  },
  "editor.codeActionsOnSave": {
    "source.fixAll.tslint": true
  },

Works without any problem with VSCode 1.32.x

ExtraBB commented 5 years ago

Can confirm that the following setting is not working with vs-code 1.33.1:

    "editor.codeActionsOnSave": {
        "source.fixAll": true
    }
vaindil commented 5 years ago

@ExtraBB Are you sure that setting isn't working? For me at least that does work, it only breaks when the inner key is "source.fixAll.tslint".

henrieri commented 5 years ago

"editor.codeActionsOnSave": { "source.fixAll.tslint": true } Started working for me when I updated vscode to 1.33.1 from 1.32.3

hchoriq commented 5 years ago

I can confirm "editor.codeActionsOnSave": { "source.fixAll.tslint": true }

finally just worked for me too in settings.json in 1.33.1

mjbvz commented 5 years ago

Closing as other people are confirming this works in 1.33

vaindil commented 5 years ago

I'm on the insiders build, 1.34.0-insider, it doesn't work here. I don't know if something would go into 1.33.1 that's not in 1.34.0-insider, but it doesn't work for me.

mjbvz commented 5 years ago

No idea why some people see this and others don't. I tested on windows with the current insiders and it works just fine

@vaindil What other extensions do you have installed? Do you see the tslint: fix all autofixable problems entry in the lightbulb menu?

vaindil commented 5 years ago

@mjbvz I disabled all extensions except this one, it still doesn't work. That entry does appear in the lightbulb menu, and clicking it does work. It just doesn't fix on save if the entry is "source.fixAll.tslint": true.

mjbvz commented 5 years ago

I'll re-open this but someone that can repo this needs to investigate. The problem could in VS Code itself. You can build VS Code from source, install this extension, and put a breakpoint on this line to check what code actions are returned to be run on save:

https://github.com/microsoft/vscode/blob/0918dabba5d8ad2c64d5197669192c78ecb66267/src/vs/workbench/api/browser/mainThreadSaveParticipant.ts#L302

vaindil commented 5 years ago

@mjbvz After much trouble I was able to debug VS Code from source (latest version of master). I installed the tslint extension via its .vsix file from the marketplace, but the extension doesn't work. Not sure how to continue.

Kauhsa commented 5 years ago

I can append this with more details later, but until that: for me, this issue doesn't happen all the time, but I can sometimes get a file to a state where no tslint fixes are run. Here is one example:

import * as React from 'react'

import * as Something from '../../index'
import _ from 'lodash';

console.log(React, Something, _)

In this case (and with my configuration), following tslint errors are reported, by both VSCode and by running tslint in terminal:

Import sources within a group must be alphabetized. (ordered-imports)
  2 | 
  3 | import * as Something from '../../index'
> 4 | import _ from 'lodash';
  5 | 
  6 | console.log(React, Something, _)
  7 | 

Imports from this module are not allowed in this group.  The expected groups (in order) are: libraries, parent directories, current directory. (ordered-imports)
  2 | 
  3 | import * as Something from '../../index'
> 4 | import _ from 'lodash';
  5 | 
  6 | console.log(React, Something, _)
  7 | 

Delete `;` (prettier)
  2 | 
  3 | import * as Something from '../../index'
> 4 | import _ from 'lodash';
    |                      ^
  5 | 
  6 | console.log(React, Something, _)
  7 | 

Calls to 'console.log' are not allowed. (no-console)
  4 | import _ from 'lodash';
  5 | 
> 6 | console.log(React, Something, _)
  7 | 

tslint manages to fix these errors (except no-console) from command line using --fix just fine. However, VSCode plugin cannot do anything.

Curiously, this can be fixed by removing the prohibited semicolon – after removing it from source, rest of the fixes will be applied correctly upon saving.

EDIT: I'm using:

VSCode version 1.33.1 Extension version 1.0.0

...and relevant npm packages (I guess the plugin does use tslint from my node_modules):

typescript@3.3.4000 (doesn't matter whether I use this or VSCode's version 3.4.3 in VSCode) tslint@5.16.0 tslint-config-prettier@1.18.0 tslint-config-standard@8.0.1 tslint-plugin-prettier@2.0.1 tslint-react@4.0.0 prettier@1.17.0

And my 'tslint.json` looks like this – slightly edited, since we have our own package that we extend, but I can reproduce the error even with this config:

{
  "rulesDirectory": ["tslint-plugin-prettier"],
  "extends": [
    "tslint-react",
    "tslint-config-prettier"
  ],
  "rules": {
    "jsx-no-multiline-js": false,
    "no-console": true,
    "no-restricted-globals": [true, "event", "name", "length", "open"],
    "prettier": [
      true,
      {
        "semi": false,
        "singleQuote": true
      }
    ],
    "ordered-imports": [
      true,
      {
        "grouped-imports": true
      }
    ]
  }
}

EDIT 2: Looks like it doesn't need to be a semicolon at the end of import statement – a space will work as well.

To clarify, by having this problem I initially thought that the command doesn't work at all because I add my missing imports by pressing ctrl+space and selecting the correct import from the list, and this action (at least with my VSCode config) adds a semicolon at the end of the import even though I don't use them otherwise – I've relied on tslint to fix that when I save the file.

Koslun commented 5 years ago

"editor.codeActionsOnSave": { "source.fixAll.tslint": true } also works for me to fix everything on save.

VSCode version 1.33.1 Extension version 1.0.0

Mac OSX version 10.14.4 MacBook Pro (15-inch, 2018)

Installed from package.json: typescript@3.4.5 tslint@5.16.0 tslint-config-prettier@1.18.0 prettier@1.17.0

yskeat commented 5 years ago

"editor.codeActionsOnSave": { "source.fixAll.tslint": true } doesn't works for me.

Windows 10 Pro

VSCode about:

TSLint extension: v1.0.0

package.json

mjbvz commented 5 years ago

Can you test this again in the latest VS Code insiders build build. This may have been fixed by https://github.com/microsoft/vscode/commit/4875cc00d5b7302e87e9f339df3aa649f739951e

vaindil commented 5 years ago

I don't know if this happened as of today (I haven't recently been working with any files needing corrections), but tslint format on save isn't working at all now, even with just source.fixAll. tslint itself is working, as I see all of the warnings/errors, but they're not fixed on save.

TSLint extension version 1.1.0

VS Code: Version: 1.35.0-insider (user setup) Commit: 4ca38ce5584d7cd67b435b3c32ef1240c6a29628 Date: 2019-05-21T05:18:31.618Z Electron: 3.1.8 Chrome: 66.0.3359.181 Node.js: 10.2.0 V8: 6.6.346.32 OS: Windows_NT x64 10.0.17763

clenemt commented 5 years ago

Just updated extension to 1.1.0, it does not format on save anymore. It's okay, I can use my hands at least now ✋

VS Code: Version: 1.34.0 (user setup) Commit: a622c65b2c713c890fcf4fbf07cf34049d5fe758 Date: 2019-05-15T21:59:37.030Z Electron: 3.1.8 Chrome: 66.0.3359.181 Node.js: 10.2.0 V8: 6.6.346.32 OS: Windows_NT x64 10.0.16299

vaindil commented 5 years ago

For the record, mine no longer auto-fixed even as of 1.0.0, I just downgraded to check. Seems a VS Code update broke it.

gauravmahto commented 5 years ago

I also confirm that after updating to v1.34, the autofix feature doesn't work anymore.

Version: 1.34.0 (user setup) Commit: a622c65b2c713c890fcf4fbf07cf34049d5fe758 Date: 2019-05-15T21:59:37.030Z Electron: 3.1.8 Chrome: 66.0.3359.181 Node.js: 10.2.0 V8: 6.6.346.32 OS: Windows_NT x64 10.0.18362

vaindil commented 5 years ago

Opened a new issue #92 for format on save being completely broken, seems to be a different issue.

RezaRahmati commented 5 years ago

Seems broken on vs code 1.35

mjbvz commented 5 years ago

Should be fixed in 1.2.0 by #96

ShadabFaiz commented 4 years ago

I'm using version 1.36.1 2213894ea0415ee8c85c5eea0d0ff81ecc191529 x64

and can confirm it does not work. tslint: 5.11.0, typescript: 3.2. Note: My tslint is local to project, not global.

Also there is no fixAll option under SOURCE VIEW... With Sourve Action

bozdoz commented 4 years ago

For me, this worked:

"editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.organizeImports": true
}
fritx commented 4 years ago
{
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.organizeImports": true
  },
  // begins to work when I added the following
  "typescript.format.enable": false
}
{
  // probably because I had set the following in user scope
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
}
0xymg commented 3 years ago
{
"editor.codeActionsOnSave": {
        "source.fixAll.tslint": true,
        "source.organizeImports": true
    },
}

this worked for me fine.

But also sometimes it may take a while to affect it. Wait a little after save.

vicasas commented 3 years ago

This is still working. vscode v1.56.2

When used with Typescript files and when doing ctrl + s to save the automatic correction does not work.

  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },