vue3+ts+vite集成eslint

2024-06-19 13:36

本文主要是介绍vue3+ts+vite集成eslint,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

项目中安装eslint

yarn add eslint -D

eslint初始化

npx eslint --init

按照下方操作即可

在这里插入图片描述

安装@typescript-eslint/parser

yarn add @typescript-eslint/parser -D

安装vite-plugin-eslint2

yarn add vite-plugin-eslint2 -D

配置vite-plugin-eslint2

// vite.config.ts
import eslint from 'vite-plugin-eslint2';export default defineConfig({plugins: [eslint({cache: false, // 不生成eslint缓存include: ['src/**/*.{js,jsx,ts,tsx,vue}']})]
})

eslint.config.js参考

import globals from 'globals';
import pluginJs from '@eslint/js';
import tsEslint from 'typescript-eslint';
import pluginVue from 'eslint-plugin-vue';export default [{languageOptions: {globals: {...globals.browser,Component: true,ComponentPublicInstance: true,ComputedRef: true,EffectScope: true,ExtractDefaultPropTypes: true,ExtractPropTypes: true,ExtractPublicPropTypes: true,InjectionKey: true,PropType: true,Ref: true,VNode: true,WritableComputedRef: true,apiUrl: true,axios: true,computed: true,createApp: true,customRef: true,defineAsyncComponent: true,defineComponent: true,effectScope: true,getCurrentInstance: true,getCurrentScope: true,h: true,inject: true,isProxy: true,isReactive: true,isReadonly: true,isRef: true,markRaw: true,nextTick: true,onActivated: true,onBeforeMount: true,onBeforeRouteLeave: true,onBeforeRouteUpdate: true,onBeforeUnmount: true,onBeforeUpdate: true,onDeactivated: true,onErrorCaptured: true,onMounted: true,onRenderTracked: true,onRenderTriggered: true,onScopeDispose: true,onServerPrefetch: true,onUnmounted: true,onUpdated: true,provide: true,reactive: true,readonly: true,ref: true,resolveComponent: true,shallowReactive: true,shallowReadonly: true,shallowRef: true,statusCode: true,toRaw: true,toRef: true,toRefs: true,toValue: true,triggerRef: true,unref: true,useAttrs: true,useCssModule: true,useCssVars: true,useLink: true,useRoute: true,useRouter: true,useSlots: true,watch: true,watchEffect: true,watchPostEffect: true,watchSyncEffect: true,process: true},parserOptions: {parser: '@typescript-eslint/parser' // 需要手动安装这个插件}}},pluginJs.configs.recommended,...tsEslint.configs.recommended,...pluginVue.configs['flat/essential'],{rules: {'quotes': ['error', 'single'], // 字符串必须是单引号'semi': ['error', 'always', { omitLastInOneLineBlock: true }], // 必须使用分号'no-duplicate-imports': 'error', // 禁止重复导入'no-unreachable-loop': 'error', // 不允许循环体只允许一次迭代'no-use-before-define': 'error', // 禁止定义变量前使用'camelcase': 'error', // 强制驼峰命名'complexity': ['error', 10], // 限制圈复杂度'curly': 'error', // 对所有控制语句强制执行一致的大括号样式'default-case': 'error', // 要求 switch 语句中有 default 分支'default-case-last': 'error', // 强制 default 分支出现在最后'default-param-last': 'error', // 强制在函数的参数默认值出现在最后'dot-notation': 'error', // 强制尽可能地使用点号'eqeqeq': 'error', // 要求使用 === 和 !=='func-name-matching': 'error', // 要求函数名与赋值给它们的变量名或属性名相匹配'init-declarations': 'error', // 要求或禁止 var 声明中的初始化'max-depth': ['error', 3], // 强制可嵌套的块的最大深度'no-alert': 'error', // 禁用 alert、confirm 和 prompt'no-caller': 'error', // 禁用 arguments.caller 或 arguments.callee'no-eval': 'error', // 禁用 eval()'no-floating-decimal': 'error', // 禁止数字字面量中使用前导和末尾小数点'no-implied-eval': 'error', // 禁止使用类似 eval() 的方法'no-nested-ternary': 'error', // 禁用嵌套的三元表达式'no-var': 'error', // 要求使用 let 或 const 而不是 var'no-unused-vars': 'off', // 可以出现未使用过的函数参数变量'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', // 禁用 console'prefer-const': ['error', { destructuring: 'all' }], // 要求使用 const 声明那些声明后不再被修改的变量'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0, maxBOF: 0 }], // 禁止出现多行空行'no-extra-parens': 'error', // 禁止不必要的括号'object-curly-spacing': ['error', 'always'], // 强制在花括号中使用一致的空格'no-param-reassign': ['error', { props: true }], // 禁止对 function 的参数进行重新赋值'@typescript-eslint/no-explicit-any': ['off'], // 可以使用 any'vue/multi-word-component-names': ['off'], // 可以使用多个单词的组件名'vue/no-setup-props-destructure': ['off'], // 可以使用 props 解构'prefer-spread': 'off'// 可以使用apply}}
];

这篇关于vue3+ts+vite集成eslint的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1075180

相关文章

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

SpringBoot+Vue3整合SSE实现实时消息推送功能

《SpringBoot+Vue3整合SSE实现实时消息推送功能》在日常开发中,我们经常需要实现实时消息推送的功能,这篇文章将基于SpringBoot和Vue3来简单实现一个入门级的例子,下面小编就和大... 目录前言先大概介绍下SSE后端实现(SpringBoot)前端实现(vue3)1. 数据类型定义2.

Spring Boot 集成 mybatis核心机制

《SpringBoot集成mybatis核心机制》这篇文章给大家介绍SpringBoot集成mybatis核心机制,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值... 目录Spring Boot浅析1.依赖管理(Starter POMs)2.自动配置(AutoConfigu

SpringBoot集成iText快速生成PDF教程

《SpringBoot集成iText快速生成PDF教程》本文介绍了如何在SpringBoot项目中集成iText9.4.0生成PDF文档,包括新特性的介绍、环境准备、Service层实现、Contro... 目录SpringBoot集成iText 9.4.0生成PDF一、iText 9新特性与架构变革二、环

JAVA SpringBoot集成Jasypt进行加密、解密的详细过程

《JAVASpringBoot集成Jasypt进行加密、解密的详细过程》文章详细介绍了如何在SpringBoot项目中集成Jasypt进行加密和解密,包括Jasypt简介、如何添加依赖、配置加密密钥... 目录Java (SpringBoot) 集成 Jasypt 进行加密、解密 - 详细教程一、Jasyp

前端Visual Studio Code安装配置教程之下载、汉化、常用组件及基本操作

《前端VisualStudioCode安装配置教程之下载、汉化、常用组件及基本操作》VisualStudioCode是微软推出的一个强大的代码编辑器,功能强大,操作简单便捷,还有着良好的用户界面,... 目录一、Visual Studio Code下载二、汉化三、常用组件1、Auto Rename Tag2

springBoot (springCloud2025)集成redisCluster 集群的操作方法

《springBoot(springCloud2025)集成redisCluster集群的操作方法》文章介绍了如何使用SpringBoot集成RedisCluster集群,并详细说明了pom.xm... 目录pom.XMLapplication.yamlcluster配置类其他配置类连接池配置类Redis

vite搭建vue3项目的搭建步骤

《vite搭建vue3项目的搭建步骤》本文主要介绍了vite搭建vue3项目的搭建步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录1.确保Nodejs环境2.使用vite-cli工具3.进入项目安装依赖1.确保Nodejs环境

Nginx搭建前端本地预览环境的完整步骤教学

《Nginx搭建前端本地预览环境的完整步骤教学》这篇文章主要为大家详细介绍了Nginx搭建前端本地预览环境的完整步骤教学,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录项目目录结构核心配置文件:nginx.conf脚本化操作:nginx.shnpm 脚本集成总结:对前端的意义很多