当前位置: 首页 > news >正文

vue中配置Eslint的步骤

1. 安装ESLint相关依赖

# 安装ESLint核心包
npm install --save-dev eslint# 安装Vue相关插件
npm install --save-dev eslint-plugin-vue vue-eslint-parser# 安装JavaScript推荐配置
npm install --save-dev @eslint/js globals# 安装Prettier相关(用于代码格式化)
npm install --save-dev prettier eslint-plugin-prettier

2. 创建ESLint配置文件

import globals from 'globals';
import pluginJs from '@eslint/js';
import pluginVue from 'eslint-plugin-vue';
import vueParser from 'vue-eslint-parser';
import prettier from 'eslint-plugin-prettier';export default [// 全局忽略配置{ignores: ['**/*.config.js','dist/**','node_modules/**','!**/eslint.config.js',],},// JavaScript文件配置{files: ['**/*.js', '**/*.mjs'],//针对.js和.mjs文件languageOptions: {globals: globals.browser,ecmaVersion: 'latest',sourceType: 'module',},plugins: {prettier,},rules: {'prettier/prettier': 'error','no-var': 'error',// 禁止使用var'no-multiple-empty-lines': ['warn', { max: 1 }],//最多允许1个空行'no-console': 'warn',//禁止使用console'no-debugger': 'warn',//禁止使用debugger'no-unexpected-multiline': 'error',//防止意外的多行语句'no-useless-escape': 'off',//关闭对不必要转义字符的检查'no-unused-vars': 'error',//禁止未使用的变量},},// Vue文件配置{files: ['**/*.vue'],languageOptions: {globals: globals.browser,parser: vueParser,parserOptions: {ecmaVersion: 'latest',sourceType: 'module',ecmaFeatures: {jsx: true,},},},plugins: {prettier,vue: pluginVue,},rules: {'prettier/prettier': 'error','no-var': 'error','no-multiple-empty-lines': ['warn', { max: 1 }],'no-console': 'warn','no-debugger': 'warn','no-unexpected-multiline': 'error','no-useless-escape': 'off','no-unused-vars': 'error',// Vue特定规则'vue/multi-word-component-names': 'off',//关闭组件名必须时多词的要求'vue/script-setup-uses-vars': 'error',//确保<script setup>中变量被正确使用'vue/no-mutating-props': 'off','vue/attribute-hyphenation': 'off','vue/valid-v-slot': ['error',{allowModifiers: true,},],},},// 推荐配置pluginJs.configs.recommended,//将使用区推荐的有关JavaScript的ESLint规则...pluginVue.configs['flat/essential'],// 使用Vue.js的基本ESLint规则
];

3. 配置package.json脚本

{"scripts": {"lint": "eslint . --fix","lint:check": "eslint .","format": "prettier --write ."}
}

4. 创建prettier配置文件

对代码进行格式化配置

{"semi": true,// 在每个语句的末尾添加分号"singleQuote": true,// 使用单引号"tabWidth": 2,// 设置缩进的空格数为2"useTabs": false,// 使用空格缩进"printWidth": 100,//每行的最大字符数为100"trailingComma": "all"//在多行结构的最后一个元素后添加逗号
}

5. 运行后检查

# 检查代码
npm run lint:check# 检查并自动修复
npm run lint# 格式化代码
npm run format
http://www.lryc.cn/news/587799.html

相关文章:

  • Why C# and .NET are still relevant in 2025
  • lightgbm算法学习
  • Python----NLP自然语言处理(中文分词器--jieba分词器)
  • 《大数据技术原理与应用》实验报告一 熟悉常用的Linux操作和Hadoop操作
  • .NET控制台应用程序中防止程序立即退出
  • 2025年大数据、建模与智能计算国际会议(ICBDMIC 2025)
  • spring-ai-alibaba 接入Tushare查询股票行情
  • 【C++进阶】---- 多态
  • SpringBoot3整合“Spring Security+JWT”快速实现demo示例与Apifox测试
  • 鸿蒙开发NDK之---- 如何将ArkTs的类型转化成C++对应的类型(基础类型,包含部分代码解释)
  • 系统化构建产品开发体系
  • androidstudio 高低版本兼容
  • 机构参与度及其Python数据获取示例
  • 迁移学习:知识复用的智能迁移引擎 | 从理论到实践的跨域赋能范式
  • 【Canvas与五星】六种五星画法
  • MIPI DSI (一) MIPI DSI 联盟概述
  • 【leetcode】231. 2的幂
  • ASP.NET Core中数据绑定原理实现详解
  • Android模块化架构:基于依赖注入和服务定位器的解耦方案
  • iOS如何查看电池容量?理解系统限制与开发者级能耗调试方法
  • H.264编解码(NAL)
  • 前端docx库实现将html页面导出word
  • 蜻蜓I即时通讯水银版系统直播功能模块二次开发文档-详细的直播功能模块文档范例-卓伊凡|麻子
  • 文档处理控件Aspose.Words教程:从 C# 中的 Word 文档中提取页面
  • 【飞牛云fnOS】告别数据孤岛:飞牛云fnOS私人资料管家
  • Python爬虫实战:研究PyMongo库相关技术
  • crawl4ai--bitcointalk爬虫实战项目
  • 嵌入式硬件篇---ne555定时器
  • 嵌入式硬件篇---晶体管的分类
  • Android 中 实现格式化字符串