我安装了更漂亮的vscode插件并拥有一个.pretteirrc.js:
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: true,
singleQuote: true,
printWidth: 60,
}在设置中,默认的格式化程序被设置为:esbenp.漂亮-vscode和格式在保存上被选中,但是在保存时没有格式化,也没有给出错误的指示。
右击具有以下内容的js文件:
var test = [1, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 2, 3, 4, 5, 6]选择格式文档不格式化,格式文档也不使用.=>更漂亮的代码格式化程序也不选择类型记录和javascript语言特性。
奇怪的是,尽管设置中没有默认格式化程序,但具有语言特性的格式却是默认的。
我可以在扩展中看到更漂亮的插件,并且启用了它。
vscode是1.41.0版
重新启动几次并重新加载vscode窗口。将尝试删除并重新安装vscode,因为在保存时自动格式化是我无法摆脱的特性。
任何要检查的建议都是受欢迎的,代码没有语法错误(参见上面的示例代码),因此不应该阻止vscode格式化,也不会给出任何错误的指示。
从项目目录中删除.vscode目录,现在默认格式化程序更漂亮了,但仍然没有格式化。
发布于 2019-12-17 20:03:14
Uninistalled和重新安装vscode和格式化再次工作。
我的..vscode/setings.json看起来像
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"prettier.configPath": "./personal.yml"
}因此,对于这个项目,我使用个人格式,但在签入文件之前,我创建了一个任务. .vscode/tasks.json,它将标准格式化所有、修改的、.js和.json文件。
{
"version": "2.0.0",
"tasks": [
{
"label": "Format",
"command": "git status -s | grep '\\.js$\\|\\.json$' | cut -f3 -d' ' | xargs prettier --write --config ./.standard.yml;",
"type": "shell"
}
]
}mac上的Regexp工作方式不同,所以我不得不运行更漂亮的两次:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "format",
"type": "shell",
"command": "git status -s | grep '\\.js$' | cut -f3 -d' ' | xargs prettier --write --config ./.prettierrc.yml && git status -s | grep '\\.json$' | cut -f3 -d' ' | xargs prettier --write --config ./.prettierrc.yml"
}
]
}https://stackoverflow.com/questions/59339262
复制相似问题