由于某种原因,Visual Studio Code 看起来正在将我的代码格式化为使用 2 个选项卡。我已经改变了我的settings.json
使用 2 个空格作为制表符,我已通过按制表符按钮验证了这一点,并且它按预期使用了 2 个空格。然而,Python 缩进仍然使用 4 个空格(或 2 个制表符),如下图所示:
您可以看到它使用两个(2 个间隔)选项卡。我查看了我能找到的所有关于配置 VS Code Python 格式的 Stack Overflow 帖子,但我所做的一切都不起作用。它仍然会自动格式化,看起来像这样。这是我的settings.json
:
{
"python.pythonPath": "venv/bin/python3",
"python.linting.enabled": true,
"editor.tabSize": 2,
"editor.formatOnSave": true,
"editor.detectIndentation": false
}
有谁知道发生了什么事吗?对于非 Python 文件,它工作正常,所以我不知道 pylint 是否发生了这种情况。这真让我抓狂。
我想通了 - 我将格式化程序更改为 autopep8 并告诉它使用 2 个空格。这是我更新的settings.json
file:
{
"python.pythonPath": "venv/bin/python3",
"editor.tabSize": 2,
"editor.formatOnSave": true,
"python.linting.pylintArgs": [
"--indent-string=' '"
],
"python.formatting.autopep8Args": [
"--indent-size=2"
],
"python.linting.pylintEnabled": true,
"python.formatting.provider": "autopep8"
}
我对这里发生的 linting / 格式化内容有点陌生,但我了解到 linting 和格式化是不同的:https://code.visualstudio.com/docs/python/editing#_formatting https://code.visualstudio.com/docs/python/editing#_formatting。我的 linter 可能告诉我需要两个空格,但我需要将格式化程序配置为在保存文件时使用 2 个空格进行格式化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)