接上篇:从0搭建vite-vue3-ts项目框架:配置less+svg+pinia+vant+axios

文档同步项目gitee:https://gitee.com/lixin_ajax/vue3-vite-ts-pinia-vant-less.git

一、Eslint:用于检测代码

安装eslint相关依赖

yarn add eslint eslint-plugin-vue @typescript-eslint/parser @typescript-eslint/eslint-plugin -D

eslint-plugin-vue:仅支持vue,提供的规则可以支持 .vue\js\jsx\ts\tsx 文件校验

@typescript-eslint/parser:解析器,让ESLint拥有规范TypeScript代码的能力

@typescript-eslint/eslint-plugin:插件,包含一系列TypeScript的ESint规则

初始化eslint

npx eslint --init

选择项目eslint配置,回车确认,空格多选

√ How would you like to use ESLint? · style    你希望怎样使用eslint
√ What type of modules does your project use? · esm  你的项目使用什么模块
√ Which framework does your project use? · vue 项目框架
√ Does your project use TypeScript? · No / Yes 是否使用typescript
√ Where does your code run? · browser, node 代码运行在哪
√ How would you like to define a style for your project? · guide 项目样式
√ Which style guide do you want to follow? · standard-with-typescript 项目风格
√ What format do you want your config file to be in? · JavaScript 配置文件格式
√ Would you like to install them now? · No / Yes 确认是否安装
√ Which package manager do you want to use? · yarn 安装方式

安装完成,项目根目录生成.eslintrc.cjs文件

// .eslintrc.cjs

module.exports = {
env: {
browser: true,
es2021: true,
node: true
},
extends: [
'plugin:vue/vue3-essential',
'standard-with-typescript'
],
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module'
},
plugins: [
'vue'
],
rules: {
}
}

在.eslintrc.cjs rules中配置eslint规则细节

rules配置eslint官网:https://eslint.org/docs/latest/rules/

腾讯云开发社区中文文档:https://cloud.tencent.com/developer/doc/1078

常用规则,参考:https://blog.csdn.net/ivenqin/article/details/104673237/

eslint-plugin-vue rules:https://eslint.vuejs.org/rules/

我的rules:

rules: {
"vue/no-v-html": "off",
"vue/script-setup-uses-vars": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"vue/custom-event-name-casing": "off",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"space-before-function-paren": "off", "vue/attributes-order": "off",
"vue/one-component-per-file": "off",
"vue/html-closing-bracket-newline": "off",
"vue/max-attributes-per-line": "off",
"vue/multiline-html-element-content-newline": "off",
"vue/singleline-html-element-content-newline": "off",
"vue/attribute-hyphenation": "off",
"vue/require-default-prop": "off",
"vue/require-explicit-emits": "off",
"vue/html-self-closing": [
"error",
{
html: {
void: "always",
normal: "never",
component: "always",
},
svg: "always",
math: "always",
},
],
"vue/multi-word-component-names": "off",
"vue/no-parsing-error": ["off"],
"eol-last": "off",
},

  

二、Prettier:用于格式化代码

安装prettier相关依赖

yarn add prettier eslint-config-prettier eslint-plugin-prettier stylelint-config-prettier -D

eslint-config-prettier:解决eslint和prettier冲突

eslint-config-prettier:将prettier作为eslint规则

stylelint-config-prettier:关闭所有不必要的或者有可能与Prettier冲突的规则

修改.eslintrc.cjs,配置prettier

  extends: [
"plugin:prettier/recommended",
],
plugins: ["prettier"],
rules: {
"prettier/prettier": [
"error",
{
endOfLine: "auto",
},
],
}

  

修改package.json,配置修复项目格式命令

"scripts": {
"lint-fix": "eslint --fix --ext .js --ext .jsx --ext .ts --ext .d.ts --ext .vue src/"
},

或直接

"scripts": {
"lint-fix": "eslint . --fix"
},

执行命令,yarn lint-fix,项目按照eslint-prettier规则进行代码格式化

配置完成!

Vue3+TypeScript 项目中,配置 ESLint 和 Prettier的更多相关文章

  1. 使用vscode开发vue cli 3项目,配置eslint以及prettier

    初始化项目时选择eslint-config-standard作为代码检测规范,vscode安装ESLint和Prettier - Code formatter两个插件,并进行如下配置 { " ...

  2. Vue2/3 项目中的 ESLint + Prettier 代码检测格式化风格指南

    Vue2/3 项目中的 ESLint + Prettier 代码检测格式化风格指南 因为平时都是使用 VSCode ESLint + Prettier 检测格式化不规范代码,但是随着接手的项目越来越多 ...

  3. eslint配置介绍-如何在uniapp中配置eslint

    eslint uniapp-eslint及vue-eslint配置 ESLint 是一个开源的 JavaScript 代码检查工具.可以让程序员在编码的过程中发现问题而不是在执行的过程中. 1. es ...

  4. 如何在VUE项目中添加ESLint

    如何在VUE项目中添加ESLint 1. 首先在项目的根目录下 新建 .eslintrc.js文件,其配置规则可以如下:(自己小整理了一份),所有的代码如下: // https://eslint.or ...

  5. 我是如何在公司项目中使用ESLint来提升代码质量的

    ESLint:你认识我吗 ESLint是一个语法规则和代码风格的检查工具. 和学习所有编程语言一样,想要入门ESLint,首先要去它的官网看看:https://eslint.org/. ESLint的 ...

  6. 在VSCode中配置Eslint格式化

    在VSCode中配置Eslint 格式化时使代码保持Eslint语法规范 安装Eslint以及prettier美化插件 在VSCode配置设置项中添加如下代码 { "workbench.co ...

  7. vue-webpack所构建好的项目中增加Eslint

    首先在package.json中配置eslint模块: 在终端运行命令:npm install 然后在build文件夹中web pack.base.conf.js配置eslint 接下来在在项目中新建 ...

  8. webpack中配置eslint

    首先安装eslint npm install eslint --save-dev 安装好这个工具后,初始化eslint npx eslint --init 这个时候会自动生成.eslintrc.js ...

  9. Vue3+Vue-cli4项目中使用腾讯滑块验证码

    Vue3+Vue-cli4项目中使用腾讯滑块验证码 简介: 滑块验证码相比于传统的图片验证码具有以下优点: 验证码的具体验证不需要服务端去验证,服务端只需要核验验证结果即可. 验证码的实现不需要我们去 ...

  10. 在TypeScript项目中进行BDD测试

    在TypeScript项目中进行BDD测试 什么是BDD? BDD(Behavior-Driven Design)是软件团队的一种工作方式,通过以下方式缩小业务人员和技术人员之间的差距: 鼓励跨角色协 ...

随机推荐

  1. vue中push()和splice()的使用方法

    vue中push()和splice()的使用方法 push()使用 push() 方法可向数组的末尾添加一个或多个元素,并返回新的长度.注意:1. 新元素将添加在数组的末尾. 2.此方法改变数组的长度 ...

  2. Windows7下驱动开发与调试体系构建——2.R3与R0的通信示例

    目录/参考资料:https://www.cnblogs.com/railgunRG/p/14412321.html 在阅读本节前,建议先阅读<Windows内核安全与驱动开发>第五章内容, ...

  3. Linux三剑客sed

    注意sed和awk使用单引号,双引号有特殊解释 sed是Stream Editor(字符流编辑器)的缩写,简称流编辑器. sed是操作.过滤和转换文本内容的强大工具. 常用功能包括结合正则表达式对文件 ...

  4. fltp备份文件后统计验证

    上一篇(https://www.cnblogs.com/jying/p/16805821.html)记录了自己在centos使用lftp备份文件的过程,本篇记录自己对备份后的文件与源文件目录的对比统计 ...

  5. Dubbo-时间轮设计

    前言 Dubbo源码阅读分享系列文章,欢迎大家关注点赞 SPI实现部分 Dubbo-SPI机制 Dubbo-Adaptive实现原理 Dubbo-Activate实现原理 Dubbo SPI-Wrap ...

  6. 1742C

    题目链接 题目大意: 在一个8x8的方格中你每次可以将一行全部涂成红色或者将一列涂成蓝色.问最后一次操作是什么操作: 如果是行操作就输出R 如果是列操作就输出B 解题思路: 我们可一枚举每行每列,如果 ...

  7. JUC学习笔记——共享模型之不可变

    JUC学习笔记--共享模型之不可变 在本系列内容中我们会对JUC做一个系统的学习,本片将会介绍JUC的不可变内容 我们会分为以下几部分进行介绍: 不可变案例 不可变设计 模式之享元 原理之final ...

  8. HTTPS详解一

    前言 作为一个有追求的程序员,了解行业发展趋势和扩充自己的计算机知识储备都是很有必要的,特别是一些计算机基础方面的内容,就比如本篇文章要讲的计算机网络方面的知识.本文将为大家详细梳理一下 HTTPS ...

  9. 基于k8s的CI/CD的实现

    综述 首先,本篇文章所介绍的内容,已经有完整的实现,可以参考这里. 在微服务.DevOps和云平台流行的当下,使用一个高效的持续集成工具也是一个非常重要的事情.虽然市面上目前已经存在了比较成熟的自动化 ...

  10. python安装/环境变量配置/多版本共存

    Python学习之路Day02: 一.今日学习内容概括: 计算机五大组成部分详解 计算机三大核心硬件 操作系统 编程与编程语言 编程语言的发展 编程语言分类 python解释器 Python Pyth ...