Rule: ban
Bans the use of specific functions or global methods.
Config
A list of banned functions or methods in the following format:
- banning functions:
- just the name of the function:
"functionName" - the name of the function in an array with one element:
["functionName"] - an object in the following format:
{"name": "functionName", "message": "optional explanation message"}
- just the name of the function:
- banning methods:
- an array with the object name, method name and optional message:
["objectName", "methodName", "optional message"] - an object in the following format:
{"name": ["objectName", "methodName"], "message": "optional message"}- you can also ban deeply nested methods:
{"name": ["foo", "bar", "baz"]}bansfoo.bar.baz() - the first element can contain a wildcard (
*) that matches everything.{"name": ["*", "forEach"]}bans[].forEach(...),$(...).forEach(...),arr.forEach(...), etc.
- you can also ban deeply nested methods:
- an array with the object name, method name and optional message:
Config examples
"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."},
{"name": ["*", "_id", "toString"], "message": "Use 'toHexString' instead."}
]
Schema
{
"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"
]
}
]
}
}