英文:
How do I specify eslint rule schema with array of objects
问题
尝试为我的 eslint 规则设置模式。
预期的配置如下:
'my-rule': ['error', [
{'any-key': ['array', 'of', 'strings']},
{'some-other-key': ['array', 'of', 'strings']},
...等等
]]
我发现可以允许任何非枚举属性名称,但我不确定如何指定它们的值类型:
schema: [
{
type: 'array',
items: {
type: 'object',
propertyNames: {
type: 'string',
// ??? - how do I specify array of strings here?
},
},
},
],
这是否可能?
英文:
Trying to set a schema for my eslint rule.
The intended configuration is as follows:
'my-rule': ['error', [
{'any-key': ['array', 'of', 'strings']},
{'some-other-key': ['array', 'of', 'strings']},
...etc
]]
I found out that it is possible to allow any non-enum property names, but I'm not sure how to specify their value types:
schema: [
{
type: 'array',
items: {
type: 'object',
propertyNames: {
type: 'string',
// ??? - how do I specify array of strings here?
},
}
}
],
Is this possible at all?
答案1
得分: 2
I don't think you can use propertyNames
to specify the value types.
Wouldn't patternProperties
work better for your purpose?
schema: [
{
type: 'array',
items: {
type: 'object',
patternProperties: {
".": {
type: "array",
items: {type: "string"}
}
},
}
}
]
英文:
I don't think you can use propertyNames
to specify the value types.
Wouldn't patternProperties
work better for your purpose?
schema: [
{
type: 'array',
items: {
type: 'object',
patternProperties: {
".": {
type: "array",
items: {type: "string"}
}
},
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论