rek*_*a18 41 flake8 visual-studio-code
有两件事让我烦恼.首先是当我在一行上输入超过80个字符时Flake8给出的警告.第二个是我尚未使用我导入的模块名称时收到的警告.我查看了终端中使用Flake8的所有文档.没用
flake8 --ignore=E402
flake8 --max-line-length=120
Run Code Online (Sandbox Code Playgroud)
这不起作用.至少VS Code没有显示任何效果.
art*_*ode 86
就我而言(vscode 1.72.2,flake 5.0.4),它只能通过添加以下内容才能起作用:
"flake8.args": [
"--max-line-length=120"
]
Run Code Online (Sandbox Code Playgroud)
在里面settings.json
我更喜欢编辑工作区设置,即<root project folder>/.vscode/settings.json,因为我将其存储在版本控制中。这样它就得到了备份,参与该项目的每个人都将获得它。
大多数其他答案中建议的内容:
"python.linting.flake8Args": [
"--max-line-length=120",
],
Run Code Online (Sandbox Code Playgroud)
对我没有影响。
rek*_*a18 85
我花了一个下午的时间查找如何做到这一点的文档.以为我会和大家分享.
将您的参数添加到USER SETTINGS json文件中,如下所示:
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402,F841,F401,E302,E305",
],
Run Code Online (Sandbox Code Playgroud)
dcs*_*san 18
note that flake8 uses
"python.linting.flake8Args": [
Run Code Online (Sandbox Code Playgroud)
whereas black seems to use:
"python.formatting.blackArgs": [
Run Code Online (Sandbox Code Playgroud)
if you're using both (or toggling) these settings maybe helpful:
{
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"120"
],
"python.linting.flake8Args": [
"--max-line-length=120",
"--ignore=E402",
],
"python.pythonPath": "venv/bin/python"
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*ger 12
我最近遇到了这个问题。我遇到了问题,因为我将参数设置--config flake8.cfg为而不是--config=flake8.cfg。在底层,vscode 将 CLI 参数放在引号中。添加"--config flake8.cfg"到 flake8 命令似乎会让 flake8 误以为它正在查看文件路径而不是 CLI 参数。
我的解决方案是将参数设置为--config=flake8.cfg(使用等号)或将参数设置为数组中的单独项目:
"python.linting.flake8Args": [
"--config",
"flake8.cfg"
]
Run Code Online (Sandbox Code Playgroud)
reka18提出的解决方案很棒,毫无疑问是专门针对原始问题编写的。
从更一般的角度来看, 如果您从事具有专用配置文件的项目,我建议您不要使用这种技巧。
您肯定会遇到难以理解的配置冲突,并且可能会忽略项目有意强制执行的规则。
在这种情况下,您应该使用以下内容:
假设该文件名为 .flake8 并且位于项目的根文件夹中
// .vscode/settings.json
"python.linting.flake8Args": ["--config", ".flake8"],
Run Code Online (Sandbox Code Playgroud)
使用--config .flake8可确保仅读取此文件(请参阅官方文档)。因此,使用此选项很重要,即使它是默认值。否则,可能会意外使用父文件夹中的自定义用户配置。
| 归档时间: |
|
| 查看次数: |
9966 次 |
| 最近记录: |