It worked on my office PC, but my autopep8 formatter didn't work in my home VScode and I was discouraged. -> The problem is in the settings
Besides autopep8, I used flake8 and mypy. The environment is venv using Pipenv (It is not related to this problem because there is no problem if the interpreter is properly selected on VScode.)
Settings.json looks like this. Although formatOnSave works, it is not formatted, and there is no response when I format the document by right-clicking. However, the format (`` `$ autopep8 sample.py```) from the command line worked.
settings.json
"editor.formatOnSave": true,
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--ignore=E402, E501, W503"
],
"python.formatting.autopep8Args": [
"--ignore=E50", //Start a new line with a semicolon
"--max-line-length=120",
"--aggressive",
"--aggressive",
],
"python.jediEnabled": false,
"python.linting.mypyEnabled": true,
It was too hard to write without the formatter working, so I desperately searched.
There was such an issue. autopep8 formatting not working #2843 https://github.com/Microsoft/vscode-python/issues/2843
@thernstig your settings aren't quite right; you want as you have to make each individual item you would pass on the command line an individual thing in the array:
"python.formatting.autopep8Args": ["--max-line-length", "100"]
You need to pass the individual items in the array to the command line. (Free translation)
The following part was wrong.
settings.json
"python.formatting.autopep8Args": [
"--ignore",
"E50",
"--max-line-length",
"120",
"--aggressive",
"--aggressive",
],
You can set autopep8 as follows, but in settings.json it seems that you need to pass it individually in the array. It was written in the same way as the item setting of flake8 above due to brain death ...
usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename]
[--ignore-local-config] [-r] [-j n] [-p n] [-a]
[--experimental] [--exclude globs] [--list-fixes]
[--ignore errors] [--select errors] [--max-line-length n]
[--line-range line line] [--hang-closing] [--exit-code]
[files [files ...]]
Recommended Posts