typescript 抱怨“解析错误:枚举成员名称不能以小写“a”到“z”开头“

rjee0c15  于 2023-02-10  发布在  TypeScript
关注(0)|答案(2)|浏览(169)

在我的 typescript 项目a中,我有以下枚举类型:

export enum ModelAttributeTypes {
  binary = 'binary',
  binarySet = 'binarySet',
  bool = 'bool',
  list = 'list',
  map = 'map',
  number = 'number',
  numberSet = 'numberSet',
  string = 'string',
  stringSet = 'stringSet',
  _null = '_null'
}

我的项目没有编译,出现错误Parsing error: Enum member names cannot start with lowercase 'a' through 'z'
我不能自己更新枚举类型,因为它是由第三方框架生成的。
如何禁用这个抱怨Parsing error: Enum member names cannot start with lowercase 'a' through 'z'的规则。
以下是我的mydev与typescript相关的依赖项:

"@babel/cli": "^7.14.8",
    "@babel/core": "^7.15.0",
    "@babel/plugin-proposal-class-properties": "^7.14.5",
    "@babel/plugin-proposal-object-rest-spread": "^7.14.7",
    "@babel/plugin-transform-runtime": "^7.15.0",
    "@babel/plugin-transform-typescript": "^7.15.0",
    "@babel/preset-env": "^7.15.0",
    "@babel/preset-flow": "^7.14.5",
    "@babel/preset-react": "^7.14.5",
    "@babel/preset-typescript": "^7.15.0",
    "@dazn/lambda-powertools-logger": "^1.28.1",
    "@testing-library/cypress": "^7.0.7",
    "@testing-library/dom": "^7.31.2",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "@types/react": "^17.0.18",
    "@types/react-dom": "^17.0.9",
    "@types/styled-components": "^5.1.12",
    "babel-eslint": "^10.1.0",
    "babel-jest": "^26.6.3",
    "babel-plugin-add-module-exports": "^1.0.4",
    "eslint-plugin-cypress": "^2.11.3",
    "eslint-plugin-jest-dom": "^3.9.0",
    "eslint-webpack-plugin": "2.4.1",
    "typescript": "^4.3.5",

这是我的eslint配置。

{
  "plugins": ["jest-dom"],
  "extends": ["plugin:cypress/recommended", "plugin:jest-dom/recommended", "eslint:recommended"],
  "parser": "babel-eslint",
  "rules": {
    "jest-dom/prefer-checked": "error",
    "jest-dom/prefer-enabled-disabled": "error",
    "jest-dom/prefer-required": "error",
    "jest-dom/prefer-to-have-attribute": "error",
    "no-unused-vars": "off",
    "max-len": ["warn", { "code": 120 }]
  },
  "env": {
    "browser": true,
    "node": true,
    "es6": true
  }
}

我的tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es6",
    "lib": ["es2015", "dom.iterable", "es2016.array.include", "es2017.object", "dom"],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "ES6",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "types": ["cypress", "@testing-library/cypress"],
    "strict": true
  },
  "include": [
    "src/**/*",
    "cypress/integration/auth.spec.js",
    "cypress/integration/home_page_spec.js",
    "cypress/integration/cypress_access_local_storage.js",
    "custom.back.ts"
  ],
  "exclude": [".history/**/*"]
}

有人能帮我解释为什么我一直得到Parsing error: Enum member names cannot start with lowercase 'a' through 'z'以及我如何修复它吗?

k2fxgqgv

k2fxgqgv1#

对于任何人谁是遇到这个问题,我发现另一个职位在这里:Eslint rises unexpected "EnumInvalidMemberName" error帮助我解决了这个问题,他发布的解决方案是更改eslint配置:

//.eslintrc
{
-  "parser": "babel-eslint"
+  "parser": "@typescript-eslint/parser"
}
cbwuti44

cbwuti442#

已解决,是eslint导致了错误。通过将不符合规则的文件添加到.eslintignore解决了此问题

相关问题