使用 @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 里面驼峰命名组件无效的问题
相关推荐
行云&流水19 分钟前
Vue3 Lifecycle Hooks
前端·javascript·vue.js
老虎062735 分钟前
JavaWeb(苍穹外卖)--学习笔记04(前端:HTML,CSS,JavaScript)
前端·javascript·css·笔记·学习·html
烛阴1 小时前
Babel 完全上手指南:从零开始解锁现代 JavaScript 开发的超能力!
前端·javascript
CN-Dust2 小时前
[FMZ][JS]第一个回测程序--让时间轴跑起来
javascript
盛夏绽放2 小时前
Vue3 中 Excel 导出的性能优化与实战指南
vue.js·excel
全宝3 小时前
🎨前端实现文字渐变的三种方式
前端·javascript·css
yanlele3 小时前
前端面试第 75 期 - 2025.07.06 更新前端面试问题总结(12道题)
前端·javascript·面试
妮妮喔妮3 小时前
【无标题】
开发语言·前端·javascript
fie88893 小时前
浅谈几种js设计模式
开发语言·javascript·设计模式
巴巴_羊5 小时前
React Ref使用
前端·javascript·react.js