使用 @antfu/eslint-config 配置 eslint (包含兼容uniapp方法)

  1. 安装 pnpm i -D eslint @antfu/eslint-config
  2. 创建 eslint.config.js 文件
js 复制代码
// 如果没有在 page.json 配置 "type": "module" 
const antfu = require('@antfu/eslint-config').default
module.exports = antfu()

// 配置了 "type": "module" 
import antfu from '@antfu/eslint-config'
export default antfu()
  1. 创建 .vscode/settings.json 文件 配置保存自动修复 (如果不需要可以跳过)
js 复制代码
{
  // Enable the ESlint flat config support
  "eslint.experimental.useFlatConfig": true,

  // Disable the default formatter, use eslint instead
  "prettier.enable": false,
  "editor.formatOnSave": false,

  // Auto fix
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit",
    "source.organizeImports": "never"
  },

  // Silent the stylistic rules in you IDE, but still auto fix them
  "eslint.rules.customizations": [
    { "rule": "style/*", "severity": "off" },
    { "rule": "*-indent", "severity": "off" },
    { "rule": "*-spacing", "severity": "off" },
    { "rule": "*-spaces", "severity": "off" },
    { "rule": "*-order", "severity": "off" },
    { "rule": "*-dangle", "severity": "off" },
    { "rule": "*-newline", "severity": "off" },
    { "rule": "*quotes", "severity": "off" },
    { "rule": "*semi", "severity": "off" }
  ],

  // Enable eslint for all supported languages
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "vue",
    "html",
    "markdown",
    "json",
    "jsonc",
    "yaml"
  ]
}
  1. 修改规则(适用于uniapp)
js 复制代码
module.exports = antfu({
  overrides: {
    vue: {
      'vue/component-name-in-template-casing': ['error', 'PascalCase' | 'kebab-case', { registeredComponentsOnly: false, ignores: [] }],
    },
  },
})

解释:

  • vue/component-name-in-template-casing 为了解决在uniapp 里面驼峰命名组件无效的问题
相关推荐
lhldsg1 小时前
智慧场馆解决方案小程序开发实战:从架构设计到部署指南
java·小程序·uni-app
独立开发之道2 小时前
【three.js教程】Three.js 运行时更新:矩阵、几何体、材质怎么改才不卡
javascript·矩阵·材质
skiyee2 小时前
🚀 用 17 行代码给 UniApp 加上全局登录拦截
前端·uni-app
默_笙3 小时前
🌃 HTTP 不认识你:JWT 登录鉴权的完整"酒店入住"指南
前端·javascript
奋斗吧程序媛3 小时前
CSV文件导入功能
开发语言·javascript·ecmascript
天道kabuto3 小时前
vue-i18n 升级 9.x 踩坑:正则表达式引发的“花括号”惨案
vue.js
梨想橙汁3 小时前
JS 核心语法:运算符流程控制、函数、数组与对象实战详解
前端·javascript
七牛开发者3 小时前
拆解 dsh:Turn 与 Step 如何组织 Agent 主循环
前端·javascript·人工智能
空想兔3 小时前
前端网络请求的前世今生:从 Ajax、XHR 到 Fetch 和 Axios
javascript
梨想橙汁3 小时前
JavaScript 零基础入门:引入方式、变量与数据类型,吃透原始与引用类型
前端·javascript