zoukankan      html  css  js  c++  java
  • vue-cli构建的项目手动添加eslint配置

    一、package.json里配置添加

    1.scripts里添加快捷eslint检查命令

    "lint": "eslint --ext .js,.vue src"

    2.添加eslint依赖包

        "babel-eslint": "^8.2.1",
        "eslint": "^4.15.0",
        "eslint-config-standard": "^10.2.1",
        "eslint-friendly-formatter": "^3.0.0",
        "eslint-loader": "^1.7.1",
        "eslint-plugin-import": "^2.7.0",
        "eslint-plugin-node": "^5.2.0",
        "eslint-plugin-promise": "^3.4.0",
        "eslint-plugin-standard": "^3.0.1",
        "eslint-plugin-vue": "^4.0.0",
    View Code

    二、根目录下添加检测配置js文件.eslintrc.js

    // https://eslint.org/docs/user-guide/configuring
    
    module.exports = {
      root: true,
      parserOptions: {
        parser: 'babel-eslint'
      },
      env: {
        browser: true,
      },
      extends: [
        // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
        // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
        'plugin:vue/essential', 
        // https://github.com/standard/standard/blob/master/docs/RULES-en.md
        'standard'
      ],
      // required to lint *.vue files
      plugins: [
        'vue'
      ],
      // add your custom rules here
      rules: {
        // allow async-await
        'generator-star-spacing': 'off',
        // allow debugger during development
        'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
      }
    }
    View Code

    三、添加忽略检测配置文件.eslintignore

    /build/
    /config/
    /dist/
    /*.js

    四、webpack.base.conf.js rules里添加eslint-loader配置

    const createLintingRule = () => ({
      test: /.(js|vue)$/,
      loader: 'eslint-loader',
      enforce: 'pre',
      include: [resolve('src'), resolve('test')],
      options: {
        formatter: require('eslint-friendly-formatter'),
        emitWarning: !config.dev.showEslintErrorsInOverlay
      }
    })
    module.exports = {
      //.......
      module: {
        rules: [
          ...(config.dev.useEslint ? [createLintingRule()] : []),
        //.....

    五、config->index.js的dev里添加

    useEslint: true,
    showEslintErrorsInOverlay: false,
  • 相关阅读:
    c语言中 fgetc函数、fputc函数实现文件的复制
    c语言 13-7 利用fgetc函数输出文件的字符数
    c语言 13-6 利用fgetc函数输出文件的行数
    c语言中fgetc函数:显示文件内容
    c语言 13-5
    c语言 获取程序上一次运行时间的程序
    hzwer模拟赛 虫洞
    LYDSY热身赛 escape
    bzoj2330 糖果
    繁华模拟赛 Vicent坐电梯
  • 原文地址:https://www.cnblogs.com/ryans/p/8409502.html
Copyright © 2011-2022 走看看