Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve context.getScope() docs #16417

Merged
merged 7 commits into from Oct 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 15 additions & 6 deletions docs/src/developer-guide/working-with-rules.md
Expand Up @@ -160,7 +160,10 @@ Additionally, the `context` object has the following methods:

### context.getScope()

This method returns the scope which has the following types:
This method returns the scope of the current node.
The following table contains a list of AST node types and the scope type that they
correspond to. For more information about the scope types, refer to the
[`Scope` object documentation](./scope-manager-interface.md#scope-interface).

| AST Node Type | Scope Type |
|:--------------------------|:-----------|
Expand All @@ -179,11 +182,17 @@ This method returns the scope which has the following types:
| `CatchClause` | `catch` |
| others | ※3 |

**※1** Only if the configured parser provided the block-scope feature. The default parser provides the block-scope feature if `parserOptions.ecmaVersion` is not less than `6`.<br>
**※2** Only if the `for` statement defines the iteration variable as a block-scoped variable (E.g., `for (let i = 0;;) {}`).<br>
**※3** The scope of the closest ancestor node which has own scope. If the closest ancestor node has multiple scopes then it chooses the innermost scope (E.g., the `Program` node has a `global` scope and a `module` scope if `Program#sourceType` is `"module"`. The innermost scope is the `module` scope.).

The returned value is a [`Scope` object](scope-manager-interface) defined by the `eslint-scope` package. The `Variable` objects of global variables have some additional properties.
**※1** Only if the configured parser provided the block-scope feature.
The default parser provides the block-scope feature if `parserOptions.ecmaVersion`
is not less than `6`.<br>
**※2** Only if the `for` statement defines the iteration variable as
a block-scoped variable (E.g., `for (let i = 0;;) {}`).<br>
**※3** The scope of the closest ancestor node which has own scope.
If the closest ancestor node has multiple scopes then it chooses the innermost scope
(E.g., the `Program` node has a `global` scope and a `module` scope
if `Program#sourceType` is `"module"`. The innermost scope is the `module` scope.).

The `Variable` objects of global variables have the following additional properties:
bpmutter marked this conversation as resolved.
Show resolved Hide resolved

* `variable.writeable` (`boolean | undefined`) ... If `true`, this global variable can be assigned arbitrary value. If `false`, this global variable is read-only.
* `variable.eslintExplicitGlobal` (`boolean | undefined`) ... If `true`, this global variable was defined by a `/* globals */` directive comment in the source code file.
Expand Down