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
    这样就完成了从初始模板到完整配置的转换。
相关推荐
大包子23 分钟前
structuredClone vs lodash.cloneDeep:核心差异与选型指南
javascript·vue.js
海码事务所24 分钟前
Google Play 新个人开发者账号上架指南:12 人连续 14 天封闭测试怎么做?
前端
田威AI28 分钟前
图片内文字翻译的规格:输入输出、保真、自动化、时间与费用
前端·计算机视觉
不可能片场38 分钟前
命令行中文变问号 我用环境变量救了场
前端·electron
lerhxx1 小时前
AI 应用中的上下文管理 —— 从"上下文窗口"到"分层压缩"的工程实践
前端·javascript
骑着蜗牛撵大象3271 小时前
多 Agent 分治协作:MapReduce 模式下的并行扇出与结果归并
前端
用户55318297321 小时前
Flutter iOS 热更新深入 Dart VM:读懂函数入口、解释执行与调用桥接
前端
前端snow1 小时前
为什么大厂要用Postgres + mogodb的框架?
前端
雪芽蓝域zzs1 小时前
第 3 节:地图点击事件,点击获取经纬度
vue.js
运维有小邓11 小时前
2026年主流AD域管理软件有哪些?
前端