Vue 3 项目 ESLint 配置详解:初始模板的正确配置

本篇文章讲解下使用pnpm create vue创建的vue3项目中关于Eslint的一些相关配置

Vue 3 ESLint 配置指南

初始模板(pnpm create vue 创建)

ts 复制代码
import { globalIgnores } from 
'eslint/config'
import { defineConfigWithVueTs, 
vueTsConfigs } from '@vue/
eslint-config-typescript'
import pluginVue from 
'eslint-plugin-vue'
import skipFormatting from '@vue/
eslint-config-prettier/
skip-formatting'

export default defineConfigWithVueTs
(
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}
    '],
  },
  globalIgnores(['**/dist/**', '**/
  dist-ssr/**', '**/coverage/**']),
  pluginVue.configs['flat/
  essential'],
  vueTsConfigs.recommended,
  skipFormatting
)

需要安装的包

bash 复制代码
pnpm add -D eslint-plugin-prettier

添加自定义配置后的完整文件

ts 复制代码
import { globalIgnores } from 
'eslint/config'
import { defineConfigWithVueTs, 
vueTsConfigs } from '@vue/
eslint-config-typescript'
import pluginVue from 
'eslint-plugin-vue'
import skipFormatting from '@vue/
eslint-config-prettier/
skip-formatting'
import prettier from 
'eslint-plugin-prettier'

export default defineConfigWithVueTs
(
  {
    name: 'app/files-to-lint',
    files: ['**/*.{ts,mts,tsx,vue}'],
  },
  globalIgnores(['**/dist/**', '**/
  dist-ssr/**', '**/coverage/**']),
  pluginVue.configs['flat/essential'],
  vueTsConfigs.recommended,
  skipFormatting,
  // 新增内容
  {
    plugins: {
      prettier: prettier
    },
    rules: {
      'prettier/prettier': [
        'warn',
        {
          singleQuote: true,
          semi: false,
          printWidth: 80,
          trailingComma: 'none',
          endOfLine: 'auto'
        }
      ],
      'vue/
      multi-word-component-names': [
        'warn',
        {
          ignores: ['index']
        }
      ],
      'vue/
      no-setup-props-destructure': 
      'off',
      'no-undef': 'error'
    }
  }
)

核心变化

  1. 添加导入 : import prettier from 'eslint-plugin-prettier'
  2. 添加配置对象 : 包含 plugins 和 rules
  3. 安装依赖 : eslint-plugin-prettier
    这样就完成了从初始模板到完整配置的转换。
相关推荐
敲敲了个代码9 小时前
从硬编码到 Schema 推断:前端表单开发的工程化转型
前端·javascript·vue.js·学习·面试·职场和发展·前端框架
张雨zy11 小时前
Pinia 与 TypeScript 完美搭配:Vue 应用状态管理新选择
vue.js·ubuntu·typescript
dly_blog11 小时前
Vue 响应式陷阱与解决方案(第19节)
前端·javascript·vue.js
消失的旧时光-194311 小时前
401 自动刷新 Token 的完整架构设计(Dio 实战版)
开发语言·前端·javascript
console.log('npc')11 小时前
Table,vue3在父组件调用子组件columns列的方法展示弹窗文件预览效果
前端·javascript·vue.js
用户479492835691511 小时前
React Hooks 的“天条”:为啥绝对不能写在 if 语句里?
前端·react.js
我命由我1234512 小时前
SVG - SVG 引入(SVG 概述、SVG 基本使用、SVG 使用 CSS、SVG 使用 JavaScript、SVG 实例实操)
开发语言·前端·javascript·css·学习·ecmascript·学习方法
用户479492835691512 小时前
给客户做私有化部署,我是如何优雅搞定 NPM 依赖管理的?
前端·后端·程序员
C_心欲无痕12 小时前
vue3 - markRaw标记为非响应式对象
前端·javascript·vue.js
qingyun98913 小时前
深度优先遍历:JavaScript递归查找树形数据结构中的节点标签
前端·javascript·数据结构