在vue项目中自定义eslint,创建.eslintrc.js文件,放到项目根目录下module.exports={root:true,//这个是用来告诉eslint去findthecurrentconfigurationThefilecannotbesearchedattheparentlevel//此项用于指定javaScript语言类型和样式,sourceType用于指定js导入方式,默认为script,这里设置为module,即引用某个导入方法parserOptions:{parser:'babel-eslint',sourceType:'module'},//此项指定环境的全局变量,下面的配置指定为浏览器环境env:{browser:true,node:true,es6:true,},extends:\['plugin:vue/recommended','eslint:recommended'\],//在此处添加您的自定义规则//它基于https://github.com/vuejs/eslint-config-vue//下面的规则是用来设置插件规范代码的规则。前缀eslint-plugin-//主要有以下设置规则,可以设置字符串也可以设置数字,两者效果一样//"off"->0关闭规则//"warn"->1关闭onwarningrules//"error"->2打开错误规则rules:{"vue/max-attributes-per-line":\[2,{"singleline":10,"multiline":{"max":1,"allowFirstLine":false}}\],"vue/html-indent":\["error",2,{//输入数字:缩进的空格数tab:tabindent"attribute":1,"baseIndent":1,"closeBracket":0,"alignAttributesVertically":true,"ignores":\[\]}\],"vue/singleline-html-element-content-newline":"off",//单行元素内容前后需要换行"vue/multiline-html-element-content-newline":"off",//前后需要换行多行元素的内容Newline"vue/name-property-casing":\["error","PascalCase"\],//JS/JSX中的组件名称应该始终是Pascal命名法"vue/no-v-html":"off","vue/html-self-closing":\["error",{"html":{"void":"never","normal":"any","component":"always"},"svg":"always","math":"always"}\],'accessor-pairs':2,//在对象中强制使用getter/setter'arrow-spacing':\[2,{'before':true,'after':true}\],'block-spacing':\[2,'always'\],//强制在同一行的开始块令牌内和下一个令牌内一致间距此规则还强制在同一行上的结束块标记和先前标记内保持一致的间距'brace-style':\[2,'1tbs',{'allowSingleLine':true//允许打开和关闭块上的括号sameline}\],//块级花括号样式'camelcase':\[0,{//Camelcaseisrequired'properties':'always'}\],'comma-dangle':\[2,'never'\],//要求或禁止尾随逗号;最后一个属性不需要逗号'comma-spacing':\[2,{//强制逗号旁边的间距:左右空格'before':false,'after':true}\],'comma-style':\[2,'last'\],//逗号样式'constructor-super':2,//在构造方法中使用super方法'curly':\[2,'multi-line'\],//Mustuse{}'dot-location'inif(){}:\[2,'property'\],//在dot前后强制换行'eol-last':2,//requireordisallow文件末尾换行'eqeqeq':\["error","always",{"null":"ignore"}\],//是否使用同余'generator-star-spacing':\[2,{//在生成器函数'before':true,'after':true}\],'handle-callback-err':\[0,'^(err|error)$'\],//强制执行回调错误处理'indent':\[2,2,{//强制执行一致的缩进'SwitchCase':1}\],'jsx-quotes':\[2,'prefer-single'\],//在JSX文件中强制使用单引号'key-spacing':\[2,{//在keywo前后强制使用一致的间距rds'beforeColon':false,'afterColon':true}\],'keyword-spacing':\[2,{//对象字面量中冒号前空格后'before':true,'after':true}\],'new-cap':\[2,{//函数名第一行大写必须用new调用,第一个小写必须在没有new的情况下调用Call'newIsCap':true,'capIsNew':false}\],'new-parens':2,//new时必须加括号'no-array-constructor':2,//禁止theuseofarrayconstructors'no-caller':2,//禁止使用arguments.caller或arguments.callee'no-console':'off',//禁止使用console'no-class-assign':2,//禁止给类赋值'no-cond-assign':2,//禁止在条件表达式中使用赋值语句'no-const-assign':2,//禁止修改const声明的变量'no-control-regex':0,//禁止在正则表达式中使用控制符'no-delete-var':2,//删除操作符不能用于var'no-dupe-args声明的变量':2,//函数参数不能重复'no-dupe-class-members':2,'no-dupe-keys':2,//不允许重复atekeyswhencreatingobjectliterals{a:1,a:1}'no-duplicate-case':2,//开关中的case标签不能重复'no-empty-character-class':2,//正则表达式中\[\]的内容不能为空'no-empty-pattern':2,//禁止使用Empty解构模式no-empty-pattern'no-eval':2,//禁止使用ofeval'no-ex-assign':2,//禁止将'no-extend-native'赋值给catch语句中的异常参数:2,//禁止扩展native对象'no-extra-bind':2,//禁止不必要的函数绑定'no-extra-boolean-cast':2,//禁止不必要的bool转换'no-extra-parens':\[2,'functions'\],//禁止不必要的括号'no-fallthrough':2,//禁止case语句失败'no-floating-decimal':2,//禁止在数字文字中使用前导和尾随小数点'no-func-assign':2,//不允许重新赋值函数声明'no-implied-eval':2,//禁止使用像eval()这样的方法'no-inner-declarations':\[2,'functions'\],//禁止在嵌套块中声明函数'no-invalid-regexp':2,//禁止在RegExp构造函数中使用无效的正则表达式字符串'no-irregular-whitespace':2,//捕获无效的空格'no-iterator':2,//防止使用\_\_iterator\_时可能出现的错误\_attributes'no-label-var':2,//抑制创建与范围内的变量共享名称的标签的不良做法,以创建更清晰的代码'no-labels':\[2,{'allowLoop':false,//Ignorethelabelpasteedtotheloopstatement'allowSwitch':false//忽略贴在switch语句上的标签}\],//Disallowtheuseofthelabeledstatement'no-lone-blocks':2,//消除不必要的和潜在的confusingblocks'no-mixed-spaces-and-tabs':2,//此规则不允许使用混合空格和制表符进行缩进'no-multi-spaces':2,//禁止在逻辑表达式、条件表达式、声明周围使用多个空格,数组元素、对象属性、序列和函数参数'no-multi-str':2,//旨在防止使用多行字符串的规则'no-multiple-empty-lines':\[2,{'max':1}\],//强制连续空行的最大数量'no-native-reassign':2,//规则不允许修改只读全局变量window,undefined...'no-negated-in-lhs':2,//不允许修改否定in表达式中的左操作Number'no-new-object':2,//禁止newObject()'no-new-require':2,//杜绝使用newrequire表达式'no-new-symbol':2,//使用new运算符防止Symbol意外调用'no-new-wrappers':0,//结束使用new运算符'no-obj-calls'的字符串、数字和布尔值:2,//不允许将Math、JSON和Reflect对象作为函数调用'no-octal':2,//不允许八进制文字'no-octal-escape':2,//不允许八进制转义序列instringliterals'no-path-concat':2,//不使用\_\_dirname或\_\_filename进行路径拼接'no-proto':2,//禁止使用\_\_proto\_\_attribute'no-redeclare':2,//禁止重复声明变量'no-regex-spaces':2,//禁止在正则表达式字面量中使用多个空格/foobar/'no-return-assign':\[2,'except-parens'\],//返回语句不能有赋值表达式'no-self-assign':2,//自赋值是invalid(cannotbeassignedtoitself)'no-self-compare':2,//不能比较自己'no-sequences':2,//逗号运算符被禁止'no-shadow-restricted-names':2,//严格模式下指定的受限标识符在声明时不能作为变量名(NaN,Infinity,undefined,evalandarguments等)'no-spaced-func':2,//调用函数时,必须有befunctionnameand()'no-sparse-arrays':2,//禁止稀疏数组,\[1,,2\]'no-this-before-super':2,//不能在调用super()之前使用这个或super'no-throw-literal':2,//禁止抛出文字错误throw"error";'no-trailing-spaces':2,//行尾后不要有空格'no-undef':2,//CannothaveUndefinedvariable'no-undef-init':2,//变量初始化时不能直接赋值undefined'no-unexpected-multiline':2,//避免多行表达式'no-unmodified-loop-condition':2,'no-unneeded-ternary':\[2,{//禁止不必要的嵌套varisYes=answer===1?true:false;'defaultAssignment':false}\],'no-unreachable':2,//不能有不能执行的代码'no-unsafe-finally':2,//return,throw,break,finallyblock'no-unused-vars':\[2,{//声明后不能有未使用的变量或参数'vars':'all','args':'none'}\],'no-useless-call':2,//禁止不必要的调用并应用'no-useless-computed-key':2,'no-useless-constructor':2,'no-useless-escape':0,'no-whitespace-before-property':2,'no-with':2,//禁用with'one-var':\[0,{//连续语句'initialized':'never'}\],'operator-linebreak':\[2,'before',{//换行时运算符在行尾或行首'overrides':{'?':'before',':':'before'}}\],'padded-blocks':\[2,'never'\],//首尾是否要空行块语句中的行'quotes':\[2,'single',{//Quotetype\`\`""'''avoidEscape':特ue,'allowTemplateLiterals':true}\],'semi':\[2,'never'\],//语句强制以分号结尾'semi-spacing':\[2,{//和之前的空格分号后'before':false,'after':true}\],'space-before-blocks':\[2,'always'\],//不换行开始的块{是否有前面是空格'space-before-function-paren':\[2,'never'\],//定义函数时括号前是否应该有空格'space-in-parens':\[2,'never'\],//ParentsDoyouwanttohavespacesinit'space-infix-ops':2,//Doyouwantspacesaroundtheinfixoperator(required)'space-unary-ops':\[2,{//一元运算符前/'words'后是否加空格:true,'nonwords':false}\],'spaced-comment':\[2,'always',{//注释样式中是否要有空格'markers':\['global','globals','eslint','eslint-disable','\*package','!',','\]}\],'template-curly-spacing':\[2,'never'\],//大括号中不允许有空格'use-isnan':2,//禁止NaN进行比较,只有isNaN()'valid-typeof':2,//必须使用typeof'wrap-iife'的合法值:\[2,'any'\],//括号style'yield-star-spacing'oftheimmediatelyexecutedfunctionexpression:\[2,'both'\],'yoda':\[2,'never'\],//禁止yoda条件'prefer-const':2,//preferconst'no-debugger':process.env.NODE\_ENV\==='production'?2:0,//禁止使用debugger'object-curly-spacing':\[2,'always',{//是否允许在花括号内RequiredspacesobjectsInObjects:false}\],'array-bracket-spacing':\[2,'never'\]//非空数组是否允许有额外空格}}
