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
相关推荐
newobut19 小时前
vscode远程调试python程序,基于debugpy库
vscode·python·调试·debugpy
潮流coder1 天前
vscode修改缓存保存路径
ide·vscode·缓存
承接电子控制相关项目1 天前
安装VSCODE发现 右击选项中无VSCODE 打开选项,处理方法汇总
ide·vscode·编辑器
BD_Marathon1 天前
【JavaWeb】IDEA运行并部署JavaWeb项目原理
java·ide·intellij-idea
Better Bench1 天前
Ubuntu aarch64\arm64系统安装vscode
linux·vscode·ubuntu
x10n91 天前
OceanBase 参数对比工具 附源码
数据库·vscode·oceanbase·腾讯云ai代码助手
Irene19911 天前
vs Code 中 ESLint 插件 和 npm install eslint 的区别
eslint
我是菜鸟0713号1 天前
VSCode配置Qt6开发教程
ide·vscode·编辑器
Jovin Giogic1 天前
简明教程:记录 Ubuntu系统命令行安装TexLive,配置vscode
linux·vscode·ubuntu·latex·texlive
小蜜蜂嗡嗡1 天前
Android studio配置忽略文件
android·ide·android studio