My code was being autofixed and cleaned up by Eslint, but then I decided to add two new eslint plugins:
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
I integrated these plugins into my code in the .eslintrc.json
under the rules
section:
"simple-import-sort/imports": [
"error",
{
"groups": [
[
"^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)"
],
["^\\w"],
["^@"],
["^\\u0000"],
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
]
}
],
"simple-import-sort/exports": [
"error",
{
"groups": [
[
"^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)"
],
["^\\w"],
["^@"],
["^\\u0000"],
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
]
}
],
"import/first": "error",
"import/newline-after-import": "error",
"import/no-duplicates": "error"
In addition, I have included the following plugins:
"plugins": [
"@typescript-eslint",
"import",
"simple-import-sort"
],
However, despite setting up fix on save in my .vscode/settings.json
, the imports are not being autofixed when I save the file:
https://i.sstatic.net/zwVvZ.png
This is how my .vscode/settings.json
looks like for enabling fix on save:
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript", "typescript"],
"eslint.nodePath": "./node_modules/eslint",
"eslint.packageManager": "npm"
}