ts项目eslint + prettier配置

1,277 阅读1分钟

1. 集成 editorconfig 配置

EditorConfig 有助于为不同 IDE 编辑器上处理同一项目的多个开发人员维护一致的编码风格。已在.editorconfig 进行基础配置,安装插件:EditorConfig for VS Code 即可。

image-20210722215138665

2. 使用 prettier 工具,配置保存时自动格式化

Prettier 是一款强大的代码格式化工具,支持 JavaScript、TypeScript、CSS、SCSS、Less、JSX、Angular、Vue、GraphQL、JSON、Markdown 等语言,基本上前端能用到的文件格式它都可以搞定,是当下最流行的代码格式化工具。

已经完.prettierrc .prettierignore 等文件配置,并完成 eslint 和 prettier 同步设置。 安装 prettier 插件。

image-20210722214543454

安装 ESLint 插件:

image-20210722215933360

建议选择 Vetur , Vue VSCode Snippets 等插件辅助开发。

进入 VS Code 左下角 setting 勾选 Editor: Format On Save。在每一个类型文件右击,选择 format doc. 选择 prettier 作为格式化工具,就可以在保存是自动格式化了。 若无法格式化,继续尝试右击配置 prettier。

3. git Husky 和 eslint

本项目使用 Husky 插件,在进行 commit 前会自动进行 eslint 检测。