ESLint plugin
This project is maintained by iliubinskii
ESLint plugin / typescript/no-restricted-syntax
Disallows AST syntax with additional type check.
type TypeGroup =
| "any"
| "array"
| "boolean"
| "complex"
| "function"
| "never"
| "null"
| "number"
| "object"
| "parameter"
| "readonly"
| "string"
| "symbol"
| "tuple"
| "undefined"
| "unknown";
module.exports = {
plugins: ["misc"],
rules: {
"misc/typescript/no-restricted-syntax": [
"error",
{
checkArrayType: boolean,
checkReturnType: boolean,
ignoreSelector: string | string[],
message: string,
replacement: string,
search: string,
selector: string | string[],
typeHas: TypeGroup,
typeHasNoneOf: TypeGroup[],
typeHasOneOf: TypeGroup[],
typeIs: TypeGroup,
typeIsNoneOf: TypeGroup[],
typeIsOneOf: TypeGroup[]
}
]
}
};
| Option | Description | Default | | :—– | :———- | :—— |
checkArrayType |
Check array argument type | false |
checkReturnType |
Check function return type | false |
ignoreSelector |
Allowed AST elements (AST selectors) | [] |
message |
Custom message | - |
replacement |
Replacement | - |
search |
Search term for replacement (regular expression) | - |
selector |
Disallowed AST elements (AST selectors) | - |
typeHas |
Restrict syntax only if AST element’s type includes given type | - |
typeHasNoneOf |
Restrict syntax only if AST element’s type includes none of given types | - |
typeHasOneOf |
Restrict syntax only if AST element’s type includes one of given types | - |
typeIs |
Restrict syntax only if AST element’s type is equal to given type | - |
typeIsNoneOf |
Restrict syntax only if AST element’s type is none of given types | - |
typeIsOneOf |
Restrict syntax only if AST element’s type is one of given types | - |
/*
eslint misc/no-restricted-syntax: [
error,
{
selector: "Identifier",
typeIs: "number"
}
]
*/
const x = 1;
/*
eslint misc/no-restricted-syntax: [
error,
{
selector: "Identifier",
typeIs: "number"
}
]
*/
const x = "";