簡體   English   中英

VS Code Auto-Formatter 自動在注釋和類之間添加行

[英]VS Code Auto-Formatter Automatically Adds Lines Between Comments and Class

視窗 10
vscode: v1.51.0
美化: v1.5.0

vs 代碼中的Python Auto Formatter程序在注釋和類之間添加了這些行。
當這在類之間完成時很好,但是當我想添加一個描述時
使用注釋在其上方的類,它再次在注釋和類之間放置 2 行

保存前的代碼:

class Hello():
    def ok():
        pass

# ok
class Hi():

    def ok():
        pass

保存后的代碼:

class Hello():
    def ok():
        pass

# ok


class Hi():

    def ok():
        pass

Vscode Settings.json

{
    "workbench.colorTheme": "Signed Dark Pro",
    "editor.fontSize": 16,
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "window.zoomLevel": 2,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "[jsonc]": {
        "editor.defaultFormatter": "HookyQR.beautify"
    },
    "workbench.iconTheme": "material-icon-theme",
    "editor.formatOnPaste": true,
    "editor.formatOnType": true,
    "files.autoSave": "off",
    "python.jediEnabled": false,
    "python.languageServer": "Microsoft",
    "todo-tree.tree.showScanModeButton": false,
    "todo-tree.highlights.defaultHighlight": {
        "icon": "alert",
        "type": "text",
        "foreground": "black",
        "background": "#FF8C00",
        "opacity": 100,
        "iconColour": "#FF8C00"
    },
    "todo-tree.highlights.customHighlight": {
        "TODO": {
            "icon": "check",
            "gutterIcon": true,
            "type": "text-and-comment"
        },
        "FIXME": {
            "foreground": "#AACCFF",
            "background": "#222333",
            "iconColour": "yellow",
            "gutterIcon": true,
            "type": "text-and-comment"
        },
        "COMMENT": {
            "foreground": "red",
            "background": "blue",
            "iconColour": "red",
            "gutterIcon": true,
            "type": "text-and-comment"
        }
    },
    "kite.showWelcomeNotificationOnStartup": false,
    "python.pythonPath": "\anaconda3\\envs\\tf-gpu\\python.exe",
    "todo-tree.general.tags": [
        "XXX",
        "TODO",
        "HACK",
        "FIXME",
        "BUG",
        "todo",
        "COMMENT"
    ],
    "[javascript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "typescript.updateImportsOnFileMove.enabled": "always",
    "git.autofetch": true,
    "java.home": "C:/Program Files/Java/jdk-13.0.2",
    "C_Cpp.updateChannel": "Insiders",
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "java.refactor.renameFromFileExplorer": "autoApply",
    "java.project.importOnFirstTimeStartup": "automatic",
    "editor.formatOnSave": true,
    "diffEditor.codeLens": true
}

我注意到您在設置中使用了"editor.formatOnSave": true, 針對您描述的問題,建議您添加以下設置進行處理:

 "editor.formatOnSaveMode": "modifications",

在保存(格式化)文件之前和之后:

在此處輸入圖片說明

您可以通過在.vscode/settings.json使用以下配置來禁用它

{
    "python.formatting.provider": "autopep8",
    "python.formatting.autopep8Args": [
        "--ignore=E302"
    ]
}

以下是解釋的所有autopep8功能: https : //github.com/hhatto/autopep8#features

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM