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
相关推荐
MediaTea4 小时前
Python 编辑器:Thonny
编辑器
笑醉踏歌行13 小时前
idea应用代码配色网站
java·ide·intellij-idea
山顶望月川14 小时前
并行科技MaaS平台支持文心4.5系列开源模型调用
人工智能·机器学习·编辑器
韩初心15 小时前
使用 visual studio 2022 编译 Lua5.4.8
ide·visual studio·lua5.4
GDAL15 小时前
Node.js REPL 教程
node.js·编辑器·vim
myloveasuka16 小时前
信号操作集函数
linux·运维·服务器·c语言·c++·vscode
向宇it16 小时前
【unity游戏开发——网络】网络游戏通信方案——强联网游戏(Socket长连接)、 弱联网游戏(HTTP短连接)
网络·http·游戏·unity·c#·编辑器·游戏引擎
comeilmforever17 小时前
IDEA2025 Version Control 窗口 local changes显示
java·ide·intellij-idea
kiss strong21 小时前
好用的自带AI功能的国产IDE
ide
成遇10 天前
在Vscode中安装Sass并配置
vscode·rust·sass