首页 > 其他分享 >【前端必会】Prettier,有了ESlint,还要Prettier

【前端必会】Prettier,有了ESlint,还要Prettier

时间:2022-09-20 23:02:35浏览次数:85  
标签:格式化 ESlint -- prettier https 必会 save Prettier

介绍

已经安装了ESLint为什么还要Prettier,主要是让ESLint专注于语法相关的验证,检查潜在问题。而代码格式化则有Prettier来接管
对比参考:https://blog.csdn.net/aaqingying/article/details/121209404

安装

npm install --save-dev --save-exact prettier
--save-exact 参考:https://blog.csdn.net/aaqingying/article/details/121209404

格式化

格式化前

执行.\node_modules\.bin\prettier ./scripts/index.js -w

的确有些变化,第3行没用的括号,多余的分号都被去掉了

VSCode格式化工具配置

安装vscode插件prettier-vscode

有好多,装星星多的。
装好后执行alt+shift+f

点击配置为Prettier

确定后代码也被格式化了

在格式化就不会弹配置默认的格式化工具了
默认规则参考
https://www.prettier.cn/docs/configuration.html
http://json.schemastore.org/prettierrc

总结

  1. 此时Prettier和Eslint还不能友好的玩耍。
  2. Prettier命令不常用,直接整合开发工具即可

标签:格式化,ESlint,--,prettier,https,必会,save,Prettier
From: https://www.cnblogs.com/lee35/p/16713110.html

相关文章