Skip to main content

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 selector and optional custom message.

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.