disallow specified syntax (no-restricted-syntax)

JavaScript has a lot of language features, and not everyone likes all of them. As a result, some projects choose to disallow the use of certain language features altogether. For instance, you might decide to disallow the use of try-catch or class.

Rather than creating separate rules for every language feature you want to turn off, this rule allows you to configure the syntax elements you want to restrict use of. These elements are represented by their ESTree node types. For example, a function declaration is represented by FunctionDeclaration and the with statement is represented by WithStatement. You may find the full list of AST node names you can use on GitHub and use the online parser to see what type of nodes your code consists of.

Rule Details

This rule disallows specified (that is, user-defined) syntax.


This rule takes a list of strings:

    "rules": {
        "no-restricted-syntax": ["error", "FunctionExpression", "WithStatement"]

Examples of incorrect code for this rule with the "FunctionExpression", "WithStatement" options:

/* eslint no-restricted-syntax: ["error", "FunctionExpression", "WithStatement"] */

with (me) {

var doSomething = function () {};

Examples of correct code for this rule with the "FunctionExpression", "WithStatement" options:

/* eslint no-restricted-syntax: ["error", "FunctionExpression", "WithStatement"] */


function doSomething() {};

When Not To Use It

If you don’t want to restrict your code from using any JavaScript features or syntax, you should not use this rule.


This rule was introduced in ESLint 1.4.0.