在VS代码中,我不希望Black格式化我的settings.json

2024-09-30 01:37:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我想对Python文件使用黑色格式化程序,但不想对JSON设置使用黑色格式化程序

我在我的settings.json中设置了以下内容:

    "python.formatting.provider": "black",
    "editor.formatOnSave": true,

我尝试通过向settings.json添加以下内容来使用--exclude标记:

    "python.formatting.blackArgs": [
        "--exclude /*\\.json/"
    ],

这相当于使用black --exclude /*\.json/的命令行调用

我也试过了

    "python.formatting.blackArgs": [
        "--exclude /*\\.json/"
    ],

根据这篇文章:VS Code Python + Black formatter arguments - python.formatting.blackArgs

但是,它仍在格式化my settings.json


Tags: 文件标记程序jsontruesettingsproviderexclude
1条回答
网友
1楼 · 发布于 2024-09-30 01:37:24

Black不格式化JSON。发生的事情是VS代码有自己的JSON格式化程序,这就是格式化settings.json的原因。您是否打开了设置,如"editor.formatOnSave"打开了?如果是这样的话,听起来您希望将其范围仅限于Python文件,例如:

"[python]": {
  "editor.formatOnSave": true
}

相关问题 更多 >

    热门问题