no-restricted-syntax
Disallow syntax matched by configured AST selectors.
Targeted pattern scopeโ
This rule reports any AST node matched by configured selector entries.
Each entry can be:
- a selector string, or
- an object with
selectorand optional custommessage.
What this rule reportsโ
This rule reports nodes selected by any configured selector in selectors.
Why this rule existsโ
It provides a general escape hatch for enforcing project-specific syntax bans.
โ Incorrectโ
if (x) {
y();
}
with options:
{
selectors: ["IfStatement"];
}
โ Correctโ
for (;;) {
break;
}
with options:
{
selectors: ["IfStatement"];
}
Deprecatedโ
- Lifecycle: Deprecated and frozen.
- Deprecated since:
v1.0.0 - Available until:
v2.0.0 - Use instead:
no-restricted-syntax
Behavior and migration notesโ
This rule is deprecated in favor of ESLint core no-restricted-syntax.
It reports only and does not provide an autofix.
Optionsโ
type Options = [
{
selectors?: Array<
| string
| {
message?: string;
selector: string;
}
>;
},
];
Default configurationโ
[{ selectors: [] }];
With the default empty selector list, this rule does not report anything until you configure selectors.
Statusโ
Use the Deprecated section above for lifecycle details.
Additional examplesโ
// config:
// {
// selectors: [
// { selector: "CallExpression[callee.name='setTimeout']", message: "Use scheduler API" }
// ]
// }
setTimeout(() => {}, 1000);
// โ reported with custom message
ESLint flat config exampleโ
import etcMisc from "eslint-plugin-etc-misc";
export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/no-restricted-syntax": ["error", { selectors: ["IfStatement"] }],
},
},
];
When not to use itโ
Disable this rule if your project does not rely on selector-based syntax restrictions.
Package documentationโ
Rule catalog ID: R037
Further readingโ
Adoption resourcesโ
- Start at warning level in CI, then move to error after cleanup.
- Use focused codemods/autofix batches per package or directory.