本文摘自PHP中文网,作者爱喝马黛茶的安东尼,侵删。

ESlint:是用来统一JavaScript代码风格的工具,不包含css、html等。
解决方案:
1、安装插件
(1)ESlint:javascript代码检测工具,可以配置每次保存时格式化js,但每次保存只格式化一点点,你得连续按住Ctrl+S好几次,才格式化好,自行体会~~
(2)vetur:可以格式化html、标准css(有分号 、大括号的那种)、标准js(有分号 、双引号的那种)、vue文件,
但是!格式化的标准js文件不符合ESlint规范,会给你加上双引号、分号等,像这样

(不好)
能把html格式化分行显示

(好)
(3)Prettier - Code formatter:只关注格式化,并不具有eslint检查语法等能力,只关心格式化文件(最大长度、混合标签和空格、引用样式等),包括JavaScript ? Flow ? TypeScript ? CSS ? SCSS ? Less ? JSX ? Vue ? GraphQL ? JSON ? Markdown
(4)Manta's Stylus Supremacy:格式化stylus的插件(不用就不装),因为vetur会把css格式化有分号 、大括号的那种,此插件会把css格式化成stylus风格,像这样

2、在vscode的文件-首选项-设置里,右侧配置里添加如下代码即可(代码有注释!),从此直接按Ctrl+S键即可一键格式化了。


代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | {
"editor.detectIndentation" : false,
"editor.tabSize" : 2,
"editor.formatOnSave" : true,
"eslint.autoFixOnSave" : true,
"eslint.validate" : [
"javascript" ,
"javascriptreact" ,
{
"language" : "vue" ,
"autoFix" : true
}
],
"prettier.eslintIntegration" : true,
"prettier.semi" : false,
"prettier.singleQuote" : true,
"javascript.format.insertSpaceBeforeFunctionParenthesis" : true,
"vetur.format.defaultFormatter.html" : "js-beautify-html" ,
"vetur.format.defaultFormatter.js" : "vscode-typescript" ,
"vetur.format.defaultFormatterOptions" : {
"js-beautify-html" : {
"wrap_attributes" : "force-aligned"
}
},
"stylusSupremacy.insertColons" : false,
"stylusSupremacy.insertSemicolons" : false,
"stylusSupremacy.insertBraces" : false,
"stylusSupremacy.insertNewLineAroundImports" : false,
"stylusSupremacy.insertNewLineAroundBlocks" : false
}
|
PHP中文网,有大量免费的vscode入门教程,欢迎大家学习!
以上就是vscode eslint是什么的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
高效开发者是如何个性化 vs code 插件与配置的?
vsCode无法用jq怎么办
vsCode中文切换失败
linux打开vsCode有乱码
golang 能用 vsCode 开发吗?
vsCode怎么操作scss
23个常用的vsCode快捷键(动图演示)
vsCode打开终端控制台方法详解
vsCode怎样编写c语言
vsCode todo如何使用
更多相关阅读请进入《vsCode》频道 >>
转载请注明出处:木庄网络博客 » vscode eslint是什么