eslint

52 阅读1分钟

针对代码格式,使用eslint

配置文件

.eslintrc
.eslintrc.js
.eslintrc.json  使用eslintConfig配置

区别在于配置格式不一样

eslintrc.js配置

module.exports = {
    parserOptions: {},
    rules: {},
    extends: []
}

parserOptions: {
    ecmaVersion: 6, es语法版本
    sourceType: "module",//es模块化
        ecmaFeatures: {//es其他特性
        jsx: true  //开启jsx语法
    }
}

rules

off或0 关闭规则
warn或1 开启规则,警告错误
error或2 开启规则,终止打包

详情配置使用数组,第一个是级别,第二个是具体配置

rules: {
    semi: "error",
        'defaule-case': [
            'warn',
            { comentpattern: '^no default$' }
        ]
}

extends

使用现有规则,rules覆盖不需要的规则

eslint规则 eslint:recommended
vue cli规则 plugin:vue/essential
react cli规则 react-app

extends:["react-app"],
rules:{}