使用 @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 里面驼峰命名组件无效的问题
相关推荐
Qhappy13 分钟前
某加密企业版过frida检测
javascript
用户5798547697117 分钟前
02:Agent Loop 深度剖析:ReAct 循环的工程实现
vue.js
用户57573033462424 分钟前
🔥 一文搞懂 JavaScript 包装类(面试必考)
javascript
滕青山32 分钟前
Base64编码/解码 核心JS实现
前端·javascript·vue.js
sww_10261 小时前
SAA ReactAgent工作原理
开发语言·前端·javascript
linux_cfan1 小时前
拒绝“黑屏”与“哑剧”:Web视频播放器UX体验与自动播放选型指南 (2026版)
前端·javascript·音视频·html5·ux
be or not to be1 小时前
假期js学习汇总
前端·javascript·学习
SuperEugene1 小时前
日期与时间处理:不用库和用 dayjs 的两种思路
前端·javascript
rfidunion1 小时前
springboot+VUE+部署(13。创建多表查询)
vue.js·spring boot·后端
Highcharts.js2 小时前
如何根据派生数据创建钟形曲线图表?highcharts正态分布曲线使用指南:从创建到设置一文搞定
开发语言·javascript·开发文档·正态分布·highcharts·图表类型·钟形图