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
相关推荐
withoutfear7 小时前
IntelliJ IDEA卡顿内存分配不足和索引被频繁触发问题解决办法
java·ide·intellij-idea
寥落半伤感13 小时前
在Pycharm中一键迅速安装包及查看虚拟环境中包名的方法
ide·python·pycharm
进击的炸酱面14 小时前
如何在服务器中使用codex?代理配置一图详解
ide·vscode·ssh
持敬chijing14 小时前
VSCode 远程开发环境完整搭建指南:汉化、SSH 免密连接与版本更新锁定
ide·vscode·ssh
郝学胜-神的一滴1 天前
C++11 工程级应用 09:告别无谓拷贝,解锁高性能移动语义
开发语言·数据结构·c++·vscode·软件工程·visual studio
weixin_402486342 天前
VS Code Codex/Claude Extension 无法安装 / 无法正常打开
linux·服务器·vscode
2501_915909062 天前
SwiftUI 和 UIKit 怎么选?两代 UI 框架的适用范围
vscode·ios·objective-c·个人开发·swift·敏捷流程
golang学习记2 天前
VS Code 新UI被曝重大bug:菜单栏消失了
vscode·bug
2501_915918412 天前
在Windows10上使用VSCode和Code Runner搭建Swift开发环境详细步骤
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
零基础的修炼2 天前
CUDA知识汇总
开发语言·c++·编辑器