TSlint, Prettier, autosave, autofix: A drama in VSCode

Update: I suggest you switch to eslint+prettier, especially now that tslint is deprecated. The post below is no longer relevant.

Something peculiar that bugged me for a while now. Depending on your setup, it can happen that VScode's autosave collides with TSLint and Prettier doing autofixing. You think it should work, but it doesn't. You read half a year of old github issue entries, just to find out that apparantly everybody could have a similar problem. But most certainly they don't. Sounds complicated? Yup, and it's fucking annoying.

This is what works for me:

The only plugin I have installed in VSCode is TSLint. "TSLint". Not "TSLint (deprecated)"…

TSLint is configured using a project specific tslint.json in the root directory. The settings are modified to accomodate some of NextJS' TS preferences and my personal taste options.

Content Plugin missing (blockSourceCode)

Note the "tslint-config-prettier" module and "tslint-plugin-prettier". Don't worry about ".prettierrc".

Now, whenever tslint is being run, it includes prettier's formatting rules for source code feedback in the editor, as well as when fixing all fixable issues on save. Hip hip hooray!

The problem was in my case, that I still had the Prettier plugin installed in vscode. In which case a) you get weird delays and performance issues and b) autosave in combination with autofix doesn't work. You can test this by disabling autosave and seeing if your autofix works on a manual save.

Well, I hope this helps someone.

Photo by Ilija Boshkov on Unsplash

Published: 09/18/2019

© 2020 genox.ch – emaillegal