I could not find a proper full configuration for this online, and I know I'll need this again in the future.
There are two ways to achieve this with some plugins; one via hitting the shell and doing an in-place replace, the other is by doing it with extensions configurable in vscode. Both should give you the same results.
You will need this whichever way you run this
# Install the package into your system or your virtualenv
pip3 install autoflake
# Copy the path from below
which autoflake
For shell-based one
//Remove Unused Python imports via bash
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.py$",
"isAsync": true,
// Use the full path from above in case it can't find it
"cmd": "autoflake --in-place --remove-all-unused-imports \"${file}\""
},
]
},
For the extension-based one
// Autoflake settings are also available in the UI-based settings.
// Check that the Autoflake extension runs first. If not, might need to change the path.
"autoflake.path": "/path/to/your/autoflake"
// Make it remove *all* imports, not just the standard ones
"autoflake.removeAllUnusedImports": true
//Remove Unused Python imports via bash
"runItOn": {
"commands": [
{
"match": "\\.py$",
"isShellCommand": false,
"isAsync": true,
"cmd": "autoflake.removeUnused"
},
]
},
nice