no-restricted-syntax
Added in v0.5.2Configuration
Rule Details
Disallows specified syntax. The rule accepts a list of esquery selectors; any AST node matching one of the listed selectors triggers a diagnostic with either a default or user-supplied message.
This is the catch-all rule for restricting language constructs (e.g. banning
with, banning for-in, requiring named function declarations) without
having to write a dedicated rule. The core selector grammar follows ESLint's
esquery-based implementation.
Examples of incorrect code for this rule:
Examples of correct code for the same configuration:
Options
The rule accepts an array of restriction entries. Each entry is either:
- A bare string — the esquery selector. The diagnostic message is
Using '<selector>' is not allowed.. - An object
{ "selector": <string>, "message"?: <string> }. Whenmessageis provided it replaces the default text verbatim.
Supported selector forms
The implementation covers the subset of esquery used in real-world ESLint
configurations and in the upstream no-restricted-syntax test suite:
- ESTree node names (e.g.
Identifier,FunctionDeclaration,BinaryExpression). - Wildcard
*. - Field selectors, including nested fields (e.g.
Literal.keyand.body.declarations.init). - Attribute selectors with presence (
[label]), equality ([name="x"],[kind='using']), inequality (!=), numeric comparisons ([params.length>2]), numeric path segments ([arguments.0.type='Literal']),type(...), and regex matching ([regex.flags=/i/]). Attribute paths may inspect ESLint'sparentlink. - Combinators
>(direct child), descendant whitespace,+(adjacent sibling),~(general sibling). - Pseudo-classes
:is(),:matches(),:not(),:has(),:first-child,:last-child,:nth-child(N),:nth-last-child(N), and the semantic classes:statement,:expression,:declaration,:function, and:pattern.
Differences from ESLint
- ESLint rejects the configuration when a selector has invalid syntax. rslint ignores only that selector and continues with the remaining selectors, so its restriction is not enforced.
- Selectors that target TS-ESTree-only nodes or fields may report fewer
diagnostics than ESLint. For example,
ClassBody > MethodDefinitionproduces no diagnostics in rslint because tsgo has no separateClassBodynode. - rslint ignores selectors using the
!subject marker, such as!IfStatement > BlockStatement, while ESLint accepts them.