eslint使用

  • 在vscode的配置
  1. 下载eslint插件
  2. 下载eslint全局插件
js 复制代码
npm install -g eslint

// 执行命令
esllint --init // 根据需要选择即可
  1. 配置eslint
js 复制代码
"eslint.enable": true, // 启用/禁用ESLint。
    "eslint.alwaysShowStatus": true,
    "eslint.debug": true, // 启用ESLint的调试模式
    "eslint.format.enable": true, // 启用ESLint作为已验证文件的格式化程序 快速修复
    "eslint.lintTask.enable": true,
    "editor.codeActionsOnSave": {
        // "source.fixAll.eslint": true // 设置保存时自动更改eslint错误
    },
    "eslint.codeAction.showDocumentation": {
        "enable": true
    },
    "eslint.options": { //指定eslint配置文件位置
        "configFile": ".eslintrc.js" //指定项目根目录中的eslint配置文件
    },
    "eslint.validate": [
        "javascript", "javascriptreact", "html", "vue", "typescript", "jsx",
    ],
}

更多在vscode中关于eslint的配置可查看文档

  • 在项目中的配置 在根目录添加.eslintrc.js .eslintignore两个文件
js 复制代码
// 在eslintrc.js中 这是vue的 eslint --init 都会自带的有 
module.exports = {
    root: true,
    "env": {
        "browser": true,
        "es2020": true
    },
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "plugins": [
        "vue"
    ],
    'extends': [
        'plugin:vue/essential',
        '@vue/standard',
        "eslint:recommended",
        "plugin:vue/essential"
    ],
    rules: { // 对项目进行规则控制
        // allow async-await
        // 'generator-star-spacing': 'off',
        // allow debugger during development
        // 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
        // 'vue/no-parsing-error': [2, { 'x-invalid-end-tag': false }],
        // 'no-undef': 'off',
        // 'camelcase': 'off'
    },
    parserOptions: {
        parser: 'babel-eslint'
    }
};


// 在.eslintignore 中
/src/*.js // 写路径即可

在vue.config.js 中开启项目的eslint

js 复制代码
// Type: boolean | 'warning' | 'default' | 'error'
module.exports = {
  lintOnSave: process.env.NODE_ENV !== 'production',
  
  devServer: {//也可以通过设置让浏览器 overlay 同时显示警告和错误:
    overlay: {
      warnings: true,
      errors: true
    }
  } 
}

相关文档

  1. vue-loader.vuejs.org/zh/guide/li...
  2. eslint.org/docs/user-g...
  3. eslint.cn/
  4. github.com/vuejs/vue-d...
  5. github.com/ecmadao/Cod...

有错之处 还请不吝赐教 万分感谢

相关推荐
草梅友仁9 天前
草梅 Auth 1.5.0 发布与自动化发包经验 | 2025 年第 35 周草梅周报
github·自动化运维·eslint
前端工作日常18 天前
以 Vue 项目为例串联eslint整个流程
前端·eslint
前端工作日常21 天前
我对eslint的进一步学习
前端·eslint
尖椒土豆sss1 个月前
关于vue3 项目中使用 eslint-plugin-vue 报错踩坑记录
vue.js·代码规范·eslint
前端工作日常1 个月前
我理解的eslint配置
前端·eslint
若梦plus1 个月前
Eslint中微内核&插件化思想的应用
前端·eslint
前端工作日常1 个月前
ESLint 配置深度解析:parserOptions、env 和 flowtype 的核心作用与实战指南
typescript·eslint
前端工作日常1 个月前
我学习到的ESLint 配置中root作用
eslint
angelQ2 个月前
针对"@antfu/eslint-config": "^4.17.0"最新版本使用报错Unexpected token 'with'的解决方法
前端·eslint
jason_yang2 个月前
代码规范-3大利器 prettier eslint husky
代码规范·eslint