我在一个使用基因敲除.js(使用TypeScript)的项目中,由于基因敲除的可观察变量只是函数,所以人们经常会遇到错误地访问可观察函数的length
属性的问题,而不是访问其自定义对象模型的length
属性。
是否有一些tslint规则可以禁止使用某种类型的特定属性?我已经看到了“禁止”规则,但这似乎仅适用于禁止使用函数和方法,而不适用于属性。
答案 0 :(得分:0)
有一条tslint规则禁止使用特定功能或全局方法。
以下格式的禁止功能或方法列表:
{"name": "functionName", "message": "optional explanation message"}
["functionName", "methodName", "optional message"]
{"name": ["objectName", "methodName"], "message": "optional message"}
- 您还可以禁止深度嵌套的方法:
{"name": ["foo", "bar", "baz"]}
禁止foo.bar.baz()- 第一个元素可以包含与所有内容匹配的通配符(*)。
{"name": ["*", "forEach"]}
禁止[].forEach(...), $(...).forEach(...), arr.forEach(...), etc.
配置示例
"ban": [
true,
"eval",
{"name": "$", "message": "please don't"},
["describe", "only"],
{"name": ["it", "only"], "message": "don't focus tests"},
{
"name": ["chai", "assert", "equal"],
"message": "Use 'strictEqual' instead."
},
{"name": ["*", "forEach"], "message": "Use a regular for loop instead."}
]
模式
{
"type": "list",
"listType": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
},
"minLength": 1,
"maxLength": 3
},
{
"type": "object",
"properties": {
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
},
"minLength": 1
}
]
},
"message": {
"type": "string"
}
},
"required": [
"name"
]
}
]
}
}