Skip to content

Commit

Permalink
docs: note that no-restricted-syntax can be used with any language (#…
Browse files Browse the repository at this point in the history
…19148)

* docs: note that `no-restricted-syntax` can be used with any language

* Apply suggestions from code review

Co-authored-by: Nicholas C. Zakas <[email protected]>

---------

Co-authored-by: Nicholas C. Zakas <[email protected]>
  • Loading branch information
mdjermanovic and nzakas authored Nov 19, 2024
1 parent 6f37b07 commit 742d054
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion docs/src/rules/no-restricted-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ related_rules:

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`, or you might decide to disallow the use of the `in` operator.

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](https://github.com/estree/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](https://github.com/eslint/js/blob/main/packages/eslint-visitor-keys/lib/visitor-keys.js) and use [AST Explorer](https://astexplorer.net/) with the espree parser to see what type of nodes your code consists of.
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. For the JavaScript language, these elements are represented by their [ESTree](https://github.com/estree/estree) node types. For example, a function declaration is represented by `FunctionDeclaration` and the `with` statement is represented by `WithStatement`. You may use [Code Explorer](https://explorer.eslint.org) to determine the nodes that represent your code.

You can also specify [AST selectors](../extend/selectors) to restrict, allowing much more precise control over syntax patterns.

Note: This rule can be used with any language you lint using ESLint. To see what type of nodes your code in another language consists of, you can use:

* [typescript-eslint Playground](https://typescript-eslint.io/play) if you're using ESLint with `typescript-eslint`.
* [ESLint Code Explorer](https://explorer.eslint.org/) if you're using ESLint to lint JavaScript, JSON, or Markdown.

## Rule Details

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

0 comments on commit 742d054

Please sign in to comment.