vscode prettier格式化不生效

您所在的位置:网站首页 vscode格式化代码没反应 vscode prettier格式化不生效

vscode prettier格式化不生效

2023-08-09 06:01| 来源: 网络整理| 查看: 265

问题

vscode编辑器中使用了prettier的相关配置,其他项目也都生效了,但是就这一个项目不生效

原因

参考:https://www.cnblogs.com/shanjinghao/p/12764984.html

prettier3.7以上会优先读取项目根目录下的editorconfig or prettier config,如果有,就不会使用vscode setting中的设置,所以最好每个项目都配置一个单独的 prettier 配置 文件:.prettierrc文件。

vscode中prettier配置项说明 /* vscode中prettier的配置 */ "prettier.printWidth": 120, "prettier.tabWidth": 2, // 缩进字节数 "prettier.useTabs": false, // 缩进不使用tab,使用空格 "prettier.semi": true, // 句尾添加分号 // 使用单引号代替双引号 "prettier.singleQuote": true, // 默认值。因为使用了一些折行敏感型的渲染器(如GitHub comment)而按照markdown文本样式进行折行 "prettier.proseWrap": "preserve", // (x) => {} 箭头函数参数只有一个时是否要有小括号。avoid:省略括号 "prettier.arrowParens": "avoid", // 在对象,数组括号与文字之间加空格 "{ foo: bar }" "prettier.bracketSpacing": true, // 结尾是 \n \r \n\r auto "prettier.endOfLine": "auto", //不让prettier使用eslint的代码格式进行校验 "prettier.eslintIntegration": false, "prettier.htmlWhitespaceSensitivity": "ignore", // 不使用prettier格式化的文件填写在项目的.prettierignore文件中 "prettier.ignorePath": ".prettierignore", // 在jsx中把'>' 是否单独放一行 "prettier.jsxBracketSameLine": false, // 在jsx中使用单引号代替双引号 "prettier.jsxSingleQuote": false, // Require a 'prettierconfig' to format prettier "prettier.requireConfig": false, //不让prettier使用stylelint的代码格式进行校验 "prettier.stylelintIntegration": false, // 在对象或数组最后一个元素后面是否加逗号(在ES5中加尾逗号) "prettier.trailingComma": "es5", // 不让prettier使用tslint的代码格式进行校验 "prettier.tslintIntegration": false

新建 .prettierrc 文件示例:

{ "printWidth": 300, "tabWidth": 2, "useTabs": false, "semi": true, "singleQuote": true, "proseWrap": "preserve", "arrowParens": "avoid", "bracketSpacing": true, "endOfLine": "auto", "eslintIntegration": true, "htmlWhitespaceSensitivity": "ignore", "ignorePath": ".prettierignore", "jsxBracketSameLine": false, "jsxSingleQuote": false, "requireConfig": false, "stylelintIntegration": true, "trailingComma": "es5", "tslintIntegration": true }


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3