zoukankan      html  css  js  c++  java
  • Vue中使用eslint

    .eslintrc.js

    module.exports = {
        root: true,
        parser: 'babel-eslint',
        "env": {
            "browser": true,
            "commonjs": true,
            "es6": true
        },
        extends: 'vue',
        "parserOptions": {
            "ecmaFeatures": {
                "jsx": false
            },
            "sourceType": "module"
        },
        "rules": {
            "indent": [
                "error",
                "tab"
            ],//tab空格
            eqeqeq: 0,//禁止检测等于比较
            'no-console': 0,//禁止检测console
            "linebreak-style": [
                "error",
                "unix"
            ],
            'camelcase':0,//禁止检测命名
            'consistent-this':0,//禁止检测命名
            'no-else-return': "error",
            "quotes": [
                "error",
                "single"
            ],//单引号
            "semi": [
                "warn",
                "never"
            ]//不适用分号
        }
    };

    webpack.config加入如下代码

    {
    			test: /.(js|vue)$/,
    			loader: 'eslint-loader',
    			enforce: 'pre',
    			include: [resolve('src'), resolve('test')],
    			options: {
              // formatter: require('eslint-friendly-formatter'),
              // 不符合Eslint规则时只警告(默认运行出错)
              // emitWarning: !config.dev.showEslintErrorsInOverlay
    			}
    		},
    

      下载editorconfig插件

      

    root = true
    # 对所有文件有效  //[*js]只对js文件有效
    [*]
    #设置编码格式
    charset = utf-8
    #缩进类型  可选space和tab
    indent_style = tab
    #缩进数量可选整数值2 or 4,或者tab
    indent_size = tab
    #换行符的格式
    end_of_line = lf
    # 是否在文件的最后插入一个空行  可选true和false
    insert_final_newline = false
    # 是否删除行尾的空格  可选择true和false
    trim_trailing_whitespace = true
    

      配置不希望eslint监测的文件

    .eslintignore

    # /node_modules/* and /bower_components/* in the project root are ignored by default
    
    # Ignore built files except build/index.js
    dist/*
    !dist/index.js
    src/vendor.js
    README.md
    

      

      vscode编译器在使用eslint的时候添加如下配置,可以减少fix

      

    "eslint.autoFixOnSave": true,
        "eslint.validate": [
            "javascript",
            "javascriptreact",
            {
                "language": "html",
                "autoFix": true
            },
            {
                "language": "vue",
                "autoFix": true
            }
        ]
    

      

      以上就是eslint的全部配置了!

  • 相关阅读:
    BZOJ 2120 数颜色
    BZOJ 3289 Mato的文件管理
    BZOJ 2038 小Z的袜子
    BZOJ 1878 HH的项链
    洛谷P2709 小B的询问
    6491: Daydream
    问题 L: An Invisible Hand
    HDU-2177 取(2堆)石子游戏 (威佐夫博奕)
    (POJ-3279)Fliptile (dfs经典---也可以枚举)
    问题 J: Palindromic Password ( 2018组队训练赛第十五场) (简单模拟)
  • 原文地址:https://www.cnblogs.com/yiyi17/p/9238072.html
Copyright © 2011-2022 走看看