我在一个使用knockout.js(使用TypeScript)的项目中,由于knockout observables 只是函数,人们经常会遇到length错误地访问observable 函数的length属性而不是访问他们自定义对象模型的属性的问题。
是否有一些 tslint 规则可以禁止使用某种类型的特定属性?我见过“禁止”规则,但这似乎只适用于禁止使用函数和方法,而不适用于属性。
gat*_*byz -1
有一条 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."}
]
Run Code Online (Sandbox Code Playgroud)
模式
{
"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"
]
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
861 次 |
| 最近记录: |