gpt4 book ai didi

装饰字段的 Angular ESLint 成员排序问题

转载 作者:行者123 更新时间:2023-12-05 03:29:09 24 4
gpt4 key购买 nike

我一直在将一个 TSLint Angular 项目迁移到 ESLint,我在尝试配置时遇到了一个问题 @typescript-eslint/member-ordering .我想在其他装饰字段之后保留装饰 setter :

// place before decorated setter
@Input() foo: boolean;
@Input() bar: boolean;

// place after decorated field
@Input() set fooBar(val: number) { ... }

为了实现这一点,我尝试了以下规则:

"@typescript-eslint/member-ordering": [
"warn",
{
"default": [
"signature",
...
"decorated-field",
"decorated-set", // throws an error
"field",
...
]
}
]

但是当我添加 "decorated-set" 时,我在 ESLint 输出控制台中收到此错误:

Configuration for rule "@typescript-eslint/member-ordering" isinvalid: Value [...] should be string. Value [...] should be equal toone of the allowed values. Value "decorated-set" should be equal toone of the allowed values. Value [...] should be object. Value [...]should match exactly one schema in oneOf.

此错误发生在以下任何成员类型中:

"public-decorated-set","protected-decorated-set","private-decorated-set","set","public-decorated-get","protected-decorated-get","private-decorated-get","get"

我做错了什么?如何应用预期的设置?

[更新] 完整的 ESLint 输出错误:

Uncaught exception received.
Error: spawn C:\Program Files\Microsoft VS Code\Code.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Uncaught exception received.
Error: spawn C:\Program Files\Microsoft VS Code\Code.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Uncaught exception received.
Error: spawn C:\Program Files\Microsoft VS Code\Code.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
at runNextTicks (internal/process/task_queues.js:62:3)
at processImmediate (internal/timers.js:434:9)
Uncaught exception received.
Error: spawn C:\Program Files\Microsoft VS Code\Code.exe ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
at onErrorNT (internal/child_process.js:465:16)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
at runNextTicks (internal/process/task_queues.js:62:3)
at processImmediate (internal/timers.js:434:9)
(node:24588) UnhandledPromiseRejectionWarning: Error: apps\testApp\.eslintrc.json » ../../.eslintrc.json#overrides[0]:
Configuration for rule "@typescript-eslint/member-ordering" is invalid:
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be string.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be equal to one of the allowed values.
Value "decorated-set" should be equal to one of the allowed values.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be object.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should match exactly one schema in oneOf.

at ConfigValidator.validateRuleOptions (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:144:23)
at c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:199:18
at Array.forEach (<anonymous>)
at ConfigValidator.validateRules (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:196:34)
at ConfigValidator.validateConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:322:18)
at CascadingConfigArrayFactory._finalizeConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:493:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:299:21)
at CLIEngine.getConfigForFile (c:\__PROJECTS\test-app\node_modules\eslint\lib\cli-engine\cli-engine.js:953:14)
at A.calculateConfigForFile (c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:167786)
at c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:176344
(Use `Code --trace-warnings ...` to show where the warning was created)
(node:24588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 32)
(node:24588) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:24588) UnhandledPromiseRejectionWarning: Error: apps\testApp\.eslintrc.json » ../../.eslintrc.json#overrides[0]:
Configuration for rule "@typescript-eslint/member-ordering" is invalid:
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be string.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be equal to one of the allowed values.
Value "decorated-set" should be equal to one of the allowed values.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be object.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should match exactly one schema in oneOf.

at ConfigValidator.validateRuleOptions (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:144:23)
at c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:199:18
at Array.forEach (<anonymous>)
at ConfigValidator.validateRules (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:196:34)
at ConfigValidator.validateConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:322:18)
at CascadingConfigArrayFactory._finalizeConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:493:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:299:21)
at CLIEngine.isPathIgnored (c:\__PROJECTS\test-app\node_modules\eslint\lib\cli-engine\cli-engine.js:973:18)
at A.isPathIgnored (c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:167532)
at c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:177304
(node:24588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 34)
(node:24588) UnhandledPromiseRejectionWarning: Error: apps\testApp\.eslintrc.json » ../../.eslintrc.json#overrides[0]:
Configuration for rule "@typescript-eslint/member-ordering" is invalid:
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be string.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be equal to one of the allowed values.
Value "decorated-set" should be equal to one of the allowed values.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be object.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should match exactly one schema in oneOf.

at ConfigValidator.validateRuleOptions (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:144:23)
at c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:199:18
at Array.forEach (<anonymous>)
at ConfigValidator.validateRules (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:196:34)
at ConfigValidator.validateConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:322:18)
at CascadingConfigArrayFactory._finalizeConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:493:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:299:21)
at CLIEngine.getConfigForFile (c:\__PROJECTS\test-app\node_modules\eslint\lib\cli-engine\cli-engine.js:953:14)
at A.calculateConfigForFile (c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:167786)
at c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:176344
(node:24588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 37)
(node:24588) UnhandledPromiseRejectionWarning: Error: apps\testApp\.eslintrc.json » ../../.eslintrc.json#overrides[0]:
Configuration for rule "@typescript-eslint/member-ordering" is invalid:
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be string.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be equal to one of the allowed values.
Value "decorated-set" should be equal to one of the allowed values.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should be object.
Value ["signature","private-static-field","protected-static-field","private-instance-field","protected-instance-field","private-abstract-field","protected-abstract-field","private-field","protected-field","static-field","instance-field","abstract-field","decorated-field","decorated-set","field","public-static-field","public-instance-field","public-abstract-field","public-field","public-constructor","protected-constructor","private-constructor","constructor","public-static-method","protected-static-method","private-static-method","public-decorated-method","protected-decorated-method","private-decorated-method","public-instance-method","protected-instance-method","private-instance-method","public-abstract-method","protected-abstract-method","private-abstract-method","public-method","protected-method","private-method","static-method","instance-method","abstract-method","decorated-method","method"] should match exactly one schema in oneOf.

at ConfigValidator.validateRuleOptions (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:144:23)
at c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:199:18
at Array.forEach (<anonymous>)
at ConfigValidator.validateRules (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:196:34)
at ConfigValidator.validateConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\shared\config-validator.js:322:18)
at CascadingConfigArrayFactory._finalizeConfigArray (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:493:23)
at CascadingConfigArrayFactory.getConfigArrayForFile (c:\__PROJECTS\test-app\node_modules\@eslint\eslintrc\lib\cascading-config-array-factory.js:299:21)
at CLIEngine.getConfigForFile (c:\__PROJECTS\test-app\node_modules\eslint\lib\cli-engine\cli-engine.js:953:14)
at A.calculateConfigForFile (c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:167786)
at c:\Users\ricky\.vscode\extensions\dbaeumer.vscode-eslint-2.2.2\server\out\eslintServer.js:1:176344
(node:24588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 40)

最佳答案

这是我目前使用的没有错误的配置:

"@typescript-eslint/member-ordering": [
"error",
{
"default": {
"memberTypes": [
"public-decorated-field",
"protected-decorated-field",
"private-decorated-field",
"public-static-field",
"protected-static-field",
"private-static-field",
"public-instance-field",
"public-abstract-field",
"protected-instance-field",
"protected-abstract-field",
"private-instance-field",
"private-abstract-field",
"static-field",
"public-field",
"instance-field",
"protected-field",
"private-field",
"abstract-field",
"constructor",
"public-static-method",
"protected-static-method",
"private-static-method",
"public-method",
"protected-method",
"private-method"
]
}
}
]

它没有我想要的那么完整,但它完成了工作。如果我使用官方文档中推荐的配置,我会收到与您报告的相同的错误。

关于装饰字段的 Angular ESLint 成员排序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71070059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com