As I develop React applications using TypeScript in VSCode, I rely on tools like prettier and TSLint to maintain clean code.
In some recent projects, I've noticed that when I save my files, prettier disrupts the automatic sorting of imports:
Before saving: https://i.sstatic.net/QA0Ny.png
After saving: https://i.sstatic.net/SZBe6.png
It seems to be a result of prettier as the issue disappears when I disable it.
My current VSCode settings include:
"editor.formatOnSave": true,
"editor.formatOnType": false,
"prettier.tslintIntegration": true,
"tslint.autoFixOnSave": false,
Furthermore, these are the settings specified in my TSLint configuration (tslint.json
):
{
"extends": [
"tslint:recommended",
"tslint-eslint-rules",
"tslint-react",
"tslint-config-prettier"
],
"jsRules": {},
"rules": {
"interface-name": false,
"jsx-no-lambda": false,
"quotemark": [true, "single", "jsx-double"]
}
}
I'm curious about the root cause of this discrepancy. These settings have been effective in past projects without any import sorting issues upon saving. Strangely, only the imports seem to be affected by prettier's behavior.