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


    1. 安装 pnpm i -D eslint @antfu/eslint-config
    2. 创建 eslint.config.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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    1. 创建 .vscode/settings.json 文件 配置保存自动修复 (如果不需要可以跳过)
    {
      // 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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    1. 修改规则(适用于uniapp)
    module.exports = antfu({
      overrides: {
        vue: {
          'vue/component-name-in-template-casing': ['off'],
        },
      },
    })
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    解释:

    • vue/component-name-in-template-casing 为了解决在uniapp 里面驼峰命名组件无效的问题

    eslint规则备注

    ban-ts-comment

    在使用ts校验忽略的时候需要加上注解就不会报错了

    错误

    // @ts-expect-error
    
    • 1

    正确

    // @ts-expect-error 插件类型不匹配
    
    • 1
  • 相关阅读:
    【Matlab】数据统计分析
    【笔记】从零开始大模型开发与微调:基于PyTorch与ChatGLM
    HTML5响应式网站模板源码 自助建站平台系统源码 可视化后台+700多套模板+安装部署教程
    教你制作微信公众号天气推送服务
    3.29每日一题(微分方程的几何应用题:重点考察)
    JVM学习笔记
    【二分查找生活应用】
    Selenium定向爬取PubMed生物医学摘要信息
    Android在app中实现蓝牙服务Service的案例
    .net 转 JAVA ssm java整合
  • 原文地址:https://blog.csdn.net/weixin_43191327/article/details/134080114