eslintrc.js语法错误(Unexpected token ':')及修复配置方案
解决predeploy执行时ESLint配置语法错误问题
执行predeploy函数时出现错误,命令以非零退出码2终止,具体报错为eslintrc.js文件第4行"parserOptions": {处存在语法错误:意外的令牌':'。
将你的ESLint配置文件内容替换为以下正确配置即可解决问题:
/* eslint disable */ { "parserOptions": { "parser": "@babel/eslint-parser", "requireConfigFile": false, // <== 添加此项,解决Babel配置文件依赖问题 "ecmaVersion": 2018, // 允许解析现代ECMAScript特性 "sourceType": "module", // 允许使用import语法 "babelOptions": { "presets": ["@babel/preset-react"] } }, "root": true, "plugins": ["promise"], "extends": "eslint:recommended", "rules": { // 从ESLint推荐规则中移除"禁止使用console"规则 "no-console": "off", // 从ESLint推荐规则中移除"禁止正则表达式中出现多个空格"规则 "no-regex-spaces": "off", // 从ESLint推荐规则中移除"禁止使用debugger"规则 "no-debugger": "off", // 从ESLint推荐规则中移除"禁止未使用变量"规则 "no-unused-vars": "off", // 从ESLint推荐规则中移除"禁止缩进混用空格和制表符"规则 "no-mixed-spaces-and-tabs": "off", // 从ESLint推荐规则中移除"禁止使用未声明变量(除非在/*global */注释中声明)"规则 "no-undef": "off", // 警告常规字符串中出现模板字面量占位符语法 "no-template-curly-in-string": 1, // 若return语句未保持一致(要么始终返回值要么从不返回)则警告 "consistent-return": 0, // 若数组方法的回调中无return语句则警告 "array-callback-return": 1, // 要求使用===和!== "eqeqeq": 2, // 禁止使用alert、confirm和prompt "no-alert": 2, // 禁止使用arguments.caller或arguments.callee "no-caller": 2, // 禁止无类型检查运算符的null比较 "no-eq-null": 2, // 禁止使用eval() "no-eval": 2, // 警告扩展原生类型的行为 "no-extend-native": 1, // 警告不必要的.bind()调用 "no-extra-bind": 1, // 警告不必要的标签 "no-extra-label": 1, // 禁止数字字面量出现前导或尾随小数点 "no-floating-decimal": 2, // 警告 shorthand 类型转换 "no-implicit-coercion": 1, // 警告循环语句内的函数声明和表达式 "no-loop-func": 1, // 禁止使用new操作符调用Function对象 "no-new-func": 2, // 警告使用new操作符调用String、Number和Boolean对象 "no-new-wrappers": 1, // 禁止抛出字面量作为异常 "no-throw-literal": 2, // 要求使用Error对象作为Promise拒绝原因 "prefer-promise-reject-errors": 2, // 强制for循环更新子句使计数器朝正确方向移动 "for-direction": 2, // 强制getter中包含return语句 "getter-return": 2, // 禁止在循环内使用await "no-await-in-loop": 2, // 禁止与-0进行比较 "no-compare-neg-zero": 2, // 警告catch子句参数遮蔽外部作用域变量 "no-catch-shadow": 1, // 禁止标识符遮蔽受限名称 "no-shadow-restricted-names": 2, // 强制数组方法的回调中包含return语句 "callback-return": 2, // 要求回调中处理错误 "handle-callback-err": 2, // 警告__dirname和__filename与字符串拼接的行为 "no-path-concat": 1, // 优先使用箭头函数作为回调 "prefer-arrow-callback": 1, // 在每个then()内返回值以创建可读且可复用的Promise链。 // 强制开发者在Promise中返回console日志和HTTP调用。 "promise/always-return": 2, // 强制对未返回的Promise使用catch() "promise/catch-or-return": 2, // 警告嵌套的then()或catch()语句 "promise/no-nesting": 1 } }
内容的提问来源于stack exchange,提问作者Md Arif Khan
相关产品推荐
相关产品推荐

