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

相关文章

Debezium 与 Apache Kafka 的集成方式步骤详解

《Debezium与ApacheKafka的集成方式步骤详解》本文详细介绍了如何将Debezium与ApacheKafka集成,包括集成概述、步骤、注意事项等,通过KafkaConnect,D... 目录一、集成概述二、集成步骤1. 准备 Kafka 环境2. 配置 Kafka Connect3. 安装 D

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

Spring AI集成DeepSeek的详细步骤

《SpringAI集成DeepSeek的详细步骤》DeepSeek作为一款卓越的国产AI模型,越来越多的公司考虑在自己的应用中集成,对于Java应用来说,我们可以借助SpringAI集成DeepSe... 目录DeepSeek 介绍Spring AI 是什么?1、环境准备2、构建项目2.1、pom依赖2.2

前端原生js实现拖拽排课效果实例

《前端原生js实现拖拽排课效果实例》:本文主要介绍如何实现一个简单的课程表拖拽功能,通过HTML、CSS和JavaScript的配合,我们实现了课程项的拖拽、放置和显示功能,文中通过实例代码介绍的... 目录1. 效果展示2. 效果分析2.1 关键点2.2 实现方法3. 代码实现3.1 html部分3.2

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

CSS3中使用flex和grid实现等高元素布局的示例代码

《CSS3中使用flex和grid实现等高元素布局的示例代码》:本文主要介绍了使用CSS3中的Flexbox和Grid布局实现等高元素布局的方法,通过简单的两列实现、每行放置3列以及全部代码的展示,展示了这两种布局方式的实现细节和效果,详细内容请阅读本文,希望能对你有所帮助... 过往的实现方法是使用浮动加

css渐变色背景|<gradient示例详解

《css渐变色背景|<gradient示例详解》CSS渐变是一种从一种颜色平滑过渡到另一种颜色的效果,可以作为元素的背景,它包括线性渐变、径向渐变和锥形渐变,本文介绍css渐变色背景|<gradien... 使用渐变色作为背景可以直接将渐China编程变色用作元素的背景,可以看做是一种特殊的背景图片。(是作为背

CSS自定义浏览器滚动条样式完整代码

《CSS自定义浏览器滚动条样式完整代码》:本文主要介绍了如何使用CSS自定义浏览器滚动条的样式,包括隐藏滚动条的角落、设置滚动条的基本样式、轨道样式和滑块样式,并提供了完整的CSS代码示例,通过这些技巧,你可以为你的网站添加个性化的滚动条样式,从而提升用户体验,详细内容请阅读本文,希望能对你有所帮助...

css实现图片旋转功能

《css实现图片旋转功能》:本文主要介绍了四种CSS变换效果:图片旋转90度、水平翻转、垂直翻转,并附带了相应的代码示例,详细内容请阅读本文,希望能对你有所帮助... 一 css实现图片旋转90度.icon{ -moz-transform:rotate(-90deg); -webkit-transfo

vue基于ElementUI动态设置表格高度的3种方法

《vue基于ElementUI动态设置表格高度的3种方法》ElementUI+vue动态设置表格高度的几种方法,抛砖引玉,还有其它方法动态设置表格高度,大家可以开动脑筋... 方法一、css + js的形式这个方法需要在表格外层设置一个div,原理是将表格的高度设置成外层div的高度,所以外层的div需要