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的全部配置了!

  • 相关阅读:
    Linux内存管理 —— 为buddy做准备:MMU, TLB, ZONE【转】
    Linux内存管理 —— 文件系统缓存和匿名页的交换【转】
    linux内存源码分析
    Linux中匿名页的反向映射【转】
    zram 简介【转】
    Linux Swap 与 Zram 详解【转】
    Linux中的mmap映射 [一]【转】
    Linux中的mmap映射 [二]【转】
    python测试开发django-rest-framework-95.文件上传接口开发
    Airtest IDE 自动化测试8
  • 原文地址:https://www.cnblogs.com/yiyi17/p/9238072.html
Copyright © 2011-2022 走看看