NodeJs class Static atribute eslint Parsing error: Unexpected token =
NodeJs class Static atribute eslint Parsing error: Unexpected token =
我正在使用 express.js 创建一个 NodeJs 应用程序,我创建了一个具有静态属性的 class。
class ErrorCode {
static userPasswordLength = {
error: "ERROR_USER_PASSWORD_LENGTH"
};
}
我正在使用 eslint,这是我的 .eslintrc.json
{
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"overrides": [
{
"env" : {
"browser": true
},
"files": [ "client/**/*.js" ],
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
"ecmaFeatures": {
"jsx": true
},
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"plugins": [
"jsx"
],
"rules": {
"react/prop-types": "off"
}
}
],
"rules": {
"block-scoped-var": ["error"],
"callback-return": ["error", ["done", "proceed", "next", "onwards", "callback", "cb"]],
"comma-style": ["warn", "last"],
"curly": ["warn"],
"eqeqeq": ["error", "always"],
"eol-last": ["warn"],
"handle-callback-err": ["error"],
"indent": ["warn", 2, {
"SwitchCase": 1,
"MemberExpression": "off",
"FunctionDeclaration": {"body":1, "parameters":"off"},
"FunctionExpression": {"body":1, "parameters":"off"},
"CallExpression": {"arguments":"off"},
"ArrayExpression": 1,
"ObjectExpression": 1,
"ignoredNodes": ["ConditionalExpression"]
}],
"linebreak-style": ["error", "unix"],
"no-dupe-keys": ["error"],
"no-duplicate-case": ["error"],
"no-extra-semi": ["warn"],
"no-labels": ["error"],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"no-redeclare": ["warn"],
"no-return-assign": ["error", "always"],
"no-sequences": ["error"],
"no-trailing-spaces": ["warn"],
"no-undef": ["off"],
"no-unexpected-multiline": ["warn"],
"no-unreachable": ["warn"],
"no-unused-vars": ["warn", {"caughtErrors":"all", "caughtErrorsIgnorePattern": "^unused($|[A-Z].*$)", "argsIgnorePattern": "^unused($|[A-Z].*$)", "varsIgnorePattern": "^unused($|[A-Z].*$)" }],
"no-use-before-define": ["error", {"functions":false}],
"one-var": ["warn", "never"],
"prefer-arrow-callback": ["warn", {"allowNamedFunctions":true}],
"quotes": ["warn", "single", {"avoidEscape":false, "allowTemplateLiterals":true}],
"semi": ["warn", "always"],
"semi-spacing": ["warn", {"before":false, "after":true}],
"semi-style": ["warn", "last"]
}
}
我的静态属性 eslint 在等号处显示错误。但是我的代码工作正常,我使用它并且没有任何崩溃,所以我不明白为什么我会出现这个错误。
error Parsing error: Unexpected token =
我应该禁用或添加哪些规则?或者我应该更改我的代码中的某些内容吗?
我将我的代码更改为这个,现在错误已修复:
class ErrorCode {
static get(name) {
let error;
switch (name) {
case 'userPasswordLength':
error = {
error: 'ERROR_USER_PASSWORD_LENGTH'
};
break;
}
return error;
}
}
我正在使用 express.js 创建一个 NodeJs 应用程序,我创建了一个具有静态属性的 class。
class ErrorCode {
static userPasswordLength = {
error: "ERROR_USER_PASSWORD_LENGTH"
};
}
我正在使用 eslint,这是我的 .eslintrc.json
{
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"overrides": [
{
"env" : {
"browser": true
},
"files": [ "client/**/*.js" ],
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
"ecmaFeatures": {
"jsx": true
},
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"plugins": [
"jsx"
],
"rules": {
"react/prop-types": "off"
}
}
],
"rules": {
"block-scoped-var": ["error"],
"callback-return": ["error", ["done", "proceed", "next", "onwards", "callback", "cb"]],
"comma-style": ["warn", "last"],
"curly": ["warn"],
"eqeqeq": ["error", "always"],
"eol-last": ["warn"],
"handle-callback-err": ["error"],
"indent": ["warn", 2, {
"SwitchCase": 1,
"MemberExpression": "off",
"FunctionDeclaration": {"body":1, "parameters":"off"},
"FunctionExpression": {"body":1, "parameters":"off"},
"CallExpression": {"arguments":"off"},
"ArrayExpression": 1,
"ObjectExpression": 1,
"ignoredNodes": ["ConditionalExpression"]
}],
"linebreak-style": ["error", "unix"],
"no-dupe-keys": ["error"],
"no-duplicate-case": ["error"],
"no-extra-semi": ["warn"],
"no-labels": ["error"],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"no-redeclare": ["warn"],
"no-return-assign": ["error", "always"],
"no-sequences": ["error"],
"no-trailing-spaces": ["warn"],
"no-undef": ["off"],
"no-unexpected-multiline": ["warn"],
"no-unreachable": ["warn"],
"no-unused-vars": ["warn", {"caughtErrors":"all", "caughtErrorsIgnorePattern": "^unused($|[A-Z].*$)", "argsIgnorePattern": "^unused($|[A-Z].*$)", "varsIgnorePattern": "^unused($|[A-Z].*$)" }],
"no-use-before-define": ["error", {"functions":false}],
"one-var": ["warn", "never"],
"prefer-arrow-callback": ["warn", {"allowNamedFunctions":true}],
"quotes": ["warn", "single", {"avoidEscape":false, "allowTemplateLiterals":true}],
"semi": ["warn", "always"],
"semi-spacing": ["warn", {"before":false, "after":true}],
"semi-style": ["warn", "last"]
}
}
我的静态属性 eslint 在等号处显示错误。但是我的代码工作正常,我使用它并且没有任何崩溃,所以我不明白为什么我会出现这个错误。
error Parsing error: Unexpected token =
我应该禁用或添加哪些规则?或者我应该更改我的代码中的某些内容吗?
我将我的代码更改为这个,现在错误已修复:
class ErrorCode {
static get(name) {
let error;
switch (name) {
case 'userPasswordLength':
error = {
error: 'ERROR_USER_PASSWORD_LENGTH'
};
break;
}
return error;
}
}