vscode配置文件-vutur自动格式化-eslint校验-属性换行

vscode配置文件-vutur自动格式化-eslint校验-属性换行

{
    // eslint 配置
    "eslint.enable": true,
    "eslint.run": "onType",
    "eslint.options": {
        "extensions": [
            ".js",
            ".vue",
            ".jsx",
            ".tsx"
        ]
    },
    // 自动格式化代码设置
    "editor.codeActionsOnSave": {
         "source.fixAll": true,
        // "source.fixAll.eslint": true,
        // 保存时格式化
        "editor.formatOnSave": true,
    },
    "vetur.format.defaultFormatterOptions": {
        "js-beautify-html": {
            // "wrap_line_length": 250, // 换行字符串阈值
            "tabWidth": 20, // tab缩进大小,默认为2
            "semi": false, // 去掉末尾分号
            // "htmlWhitespaceSensitivity": "strict", // html空格敏感度,可选值:'css'(样式表)|'strict'(严格)|'ignore'(忽略)
            // "vueIndentScriptAndStyle": true, // vue文件中的script及style标签缩进
            // "endOfLine": "auto", // 结尾是 \n \r \n\r auto
            // auto 不进行格式化
            // force 首个属性与开始标签共一行,最后的属性与开始标签结束的 > 符号共一行,其他属性单独一行。
            // force-aligned 所有属性强制对齐,若组件名较长太不美观,不建议使用。
            // force-expand-multiline 所有属性单独占据一行且对齐。开始标签和开始标签结束的 > 符号同样单独占据一行。
            "wrap_attributes": "force-aligned", //属性换行
            // "end_with_newline": false,
        },
        "prettyhtml": {
            // "printWidth": 100,
            "singleQuote": false, // //去掉末尾分号
            // "wrapAttributes": false,
            "sortAttributes": false
        },
        "prettier": {
            // "semi": true, //去掉末尾分号
            "trailingComma": true, // 这个就是设置是否末尾添加逗号的字段
            "singleQuote": true //将所有双引号改为单引号
        }
    },
    // #让vue中的js按"prettier"格式进行格式化
    "vetur.format.defaultFormatter.html": "js-beautify-html",
    "vetur.format.defaultFormatter.js": "prettier",
    "path-autocomplete.extensionOnImport": true,
    "path-autocomplete.pathMappings": {
        "@": "${folder}/src"
    },
    "security.workspace.trust.untrustedFiles": "open",
    "editor.fontSize": 15,
    "liveServer.settings.donotShowInfoMsg": true,
    "less.compile": {
        "out": "../css/"
    },
    "editor.tabSize": 2,
    "[javascript]": {
        "editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
    },
    "[vue]": {
        "editor.defaultFormatter": "octref.vetur"
    },
    "workbench.startupEditor": "none",
    "explorer.confirmDelete": false,
    "[html]": {
        "editor.defaultFormatter": "vscode.html-language-features"
    },
    "cssrem.rootFontSize": 80,
    "cssrem.vwDesign": 1920,
    "[typescript]": {
        "editor.defaultFormatter": "vscode.typescript-language-features"
    },
    "liveServer.settings.port": 0,
    "vetur.validation.interpolation": false,
    "vetur.validation.script": false,
    "git.confirmSync": false,
    "git.enableSmartCommit": true,
    "editor.inlineSuggest.enabled": true,
    "eslint.trace.server": "off",
    "eslint.alwaysShowStatus": true,
    "github.copilot.enable": {
        "*": true,
        "yaml": false,
        "plaintext": false,
        "markdown": false
    },
    "git.openRepositoryInParentFolders": "always",
    "terminal.integrated.enableMultiLinePasteWarning": false,
    "eslint.nodeEnv": "",
    "editor.semanticTokenColorCustomizations": {},
    "editor.tokenColorCustomizations": {},
    "editor.bracketPairColorization.independentColorPoolPerBracketType": true,
    "editor.formatOnSave": true,
    "window.openFoldersInNewWindow": "on",
    "window.openFilesInNewWindow": "on",
    "editor.formatOnPaste": true,
    "backgroundCover.imagePath": "c:\\Users\\85839\\Pictures\\壁纸\\QQ截图20230412214624.png",
    "backgroundCover.opacity": 0.3,
    "backgroundCover.randomImageFolder": "c:\\Users\\85839\\Pictures\\壁纸",
    "backgroundCover.autoStatus": true,
    "workbench.colorTheme": "Default Dark+ Experimental",
    "[jsonc]": {
        "editor.defaultFormatter": "vscode.json-language-features"
    },
    "javascript.updateImportsOnFileMove.enabled": "always",
    "diffEditor.ignoreTrimWhitespace": false
}

效果
在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 您可以使用ESLint插件来格式化您的Python代码,并在运算符前后自动加上空格。为了配置ESLint,您需要在ESLint配置文件中添加以下规则: ``` "rules": { "space-before-function-paren": ["error", "always"], "keyword-spacing": ["error", { "before": true, "after": true, "overrides": { "+": { "before": false, "after": false }, "-": { "before": false, "after": false }, "*": { "before": false, "after": false }, "/": { "before": false, "after": false } } }] } ``` 这些规则将确保在函数名称和左括号之间始终存在一个空格,并在关键字前后始终存在一个空格,除了“+”,“-”,“*”和“/”符号。您可以根据您的需求修改这些规则。 ### 回答2: 在使用 VSCodeESLint 插件自动格式化 Python 代码时,可以通过在项目的根目录下创建 `.eslintrc.js` 文件来配置 ESLint。 1. 首先,确保已经在项目中安装了 `eslint` 插件和 `eslint-plugin-python` 插件(用于支持 Python 代码的 ESLint 校验)。 2. 在项目的根目录下创建 `.eslintrc.js` 文件。 3. 打开 `.eslintrc.js` 文件,添加以下内容: ```js module.exports = { root: true, env: { es6: true, node: true, browser: true, "python/pythonVersion": "3.8" }, extends: ["eslint:recommended", "plugin:python/recommended"], plugins: ["python"], rules: { "python/operators-spacing": ["error", { "before": true, "after": true }] } }; ``` 以上配置的关键在于 `"python/operators-spacing"` 这个 rule。该 rule 可以用来控制运算符前后的空格,通过将 `before` 和 `after` 都设置为 `true`,即可在 `- * /` 等运算符的前后自动加上空格。 4. 保存 `.eslintrc.js` 文件。 之后,当你在 VSCode 中保存 Python 代码时,ESLint 插件会自动对代码进行格式化,并在运算符前后添加空格。 ### 回答3: 使用VSCodeESLint插件自动格式化Python代码时,在运算符(如 +、-、*、/ 等)的前后加上空格,可以通过配置.eslintrc.js文件来实现。 步骤如下: 1. 确保已经在VSCode中安装了ESLint插件,并在项目根目录下安装了eslinteslint-plugin-python插件。 2. 在项目根目录下创建一个名为.eslintrc.js的文件,并在其中添加以下内容: ```javascript module.exports = { extends: 'eslint:recommended', plugins: ['python'], rules: { 'python/operator-assignment-semicolon': ['error', 'always'], 'python/operator-assignment-space': ['error', 'always'] } }; ``` 上述代码使用了eslint:recommended作为基本配置,并引入了eslint-plugin-python插件来处理Python特定的规则。 3. 完成配置后,保存.eslintrc.js文件并重新打开Python代码文件。 4. 在保存Python代码文件时,ESLint插件会根据配置自动格式化代码,为运算符的前后添加空格。 例如,对于以下Python代码: ```python result=3+5 ``` 保存后,ESLint自动格式化为: ```python result = 3 + 5 ``` 这样就在运算符的前后加上了空格。 需要注意的是,ESLint插件对于Python代码的格式化有一些限制,不能处理所有的自定义格式要求。如果想要更加细致地控制Python代码的格式化,可以考虑使用其他专门的Python代码格式化工具,例如autopep8。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星月前端

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值