vscode中使用eslint+prettier的配置

eslint+prettier+vscode自动保存用起来感觉非常爽快。

一般来说,安装eslint+prettier插件,然后使用相关脚手架配套的eslint+prettier,无法自动格式代码,每次都需要执行格式化命令。这里贴出保存自动格式化代码的setting.json。

javascript 复制代码
// ...其他配置项

// eslint配置开始
// eslint检测开关
"eslint.enable": true,
// 需要eslint校验的文件
"eslint.validate": {
	"javascript",
	"javascriptreact",
	"typescript",
	"typescriptreact",
	"vue",
}
"editor.codeActionsOnSave": { // 编辑器.代码保存时动作
	"source.fixAll.eslint": true // 使用eslint修复所有
}

如果不使用脚手架自带的eslint+prettier配置,可以参考我之前写的项目构建之代码检测

这里归纳一下三个安装命令。

  1. 全局安装eslint
powershell 复制代码
npm i eslint -g
  1. eslint初始化
powershell 复制代码
npx eslint --init
  1. 安装prettier、以及相关的eslint插件和配置项
powershell 复制代码
npm i prettier eslint-plugin-prettier eslint-config-pretter -D
相关推荐
farewell-Calm1 小时前
Android Studio 添加第三方库
android·ide·android studio
GDAL2 小时前
vscode 使用正则查找替换
ide·vscode·正则表达式·编辑器
WLDLSW2 小时前
windows上jupyter notebook增加标题目录功能
ide·windows·jupyter
拆房老料2 小时前
文档能力中台化实践:一份面向自研Office处理产品的理性技术选型说明
编辑器·开源软件
MounRiver_Studio3 小时前
RISC-V IDE MRS2使用笔记(十三):添加自定义工程模板
ide·mcu·risc-v·嵌入式开发
qq_393060473 小时前
在WSL2的Jupyter中正确显示中文字体seaborn覆盖plt的问题
ide·python·jupyter
HERR_QQ3 小时前
【cpp tool】GDB coredump vscode GUI 和多线程常用笔记
ide·笔记·vscode
MounRiver_Studio3 小时前
RISC-V IDE MRS2使用笔记(十二):快捷配置页面
ide·mcu·risc-v·嵌入式开发
世洋Blog3 小时前
Unity编辑器基础
unity·c#·编辑器·游戏引擎
研來如此3 小时前
VSCode连接远程服务器
服务器·ide·vscode