Skip to content

Commit dd104eb

Browse files
nzakassnitin315mdjermanovic
authored
docs: Add API docs to README (#654)
* docs: Add API docs to README fixes #653 * Update packages/eslint-scope/README.md Co-authored-by: Nitin Kumar <[email protected]> * Update packages/eslint-scope/README.md Co-authored-by: Nitin Kumar <[email protected]> * Apply suggestions * Update packages/eslint-scope/README.md Co-authored-by: Milos Djermanovic <[email protected]> * Update packages/eslint-scope/README.md Co-authored-by: Milos Djermanovic <[email protected]> * Update packages/eslint-scope/README.md Co-authored-by: Milos Djermanovic <[email protected]> --------- Co-authored-by: Nitin Kumar <[email protected]> Co-authored-by: Milos Djermanovic <[email protected]>
1 parent eb0c9c9 commit dd104eb

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

packages/eslint-scope/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,95 @@ estraverse.traverse(ast, {
7474
});
7575
```
7676

77+
## API
78+
79+
The following section describes the API for this package. You can also read [the docs](https://eslint.org/docs/latest/extend/scope-manager-interface).
80+
81+
### ScopeManager
82+
83+
The `ScopeManager` class is at the core of eslint-scope and is returned when you call `eslintScope.analyze()`. It manages all scopes in a given AST.
84+
85+
#### Properties
86+
87+
- `scopes` - An array of all scopes.
88+
- `globalScope` - Reference to the global scope.
89+
90+
#### Methods
91+
92+
- **`acquire(node, inner)`**
93+
Acquires the appropriate scope for a given node.
94+
- `node` - The AST node to acquire the scope from.
95+
- `inner` - Optional boolean. When `true`, returns the innermost scope, otherwise returns the outermost scope. Default is `false`.
96+
- Returns: The acquired scope or `null` if no scope is found.
97+
98+
- **`acquireAll(node)`**
99+
Acquires all scopes for a given node.
100+
- `node` - The AST node to acquire scopes from.
101+
- Returns: An array of scopes or `undefined` if none are found.
102+
103+
- **`release(node, inner)`**
104+
Returns the upper scope for a given node.
105+
- `node` - The AST node to release.
106+
- `inner` - Optional boolean. When `true`, returns the innermost upper scope, otherwise returns the outermost upper scope. Default is `false`.
107+
- Returns: The upper scope or `null` if no upper scope exists.
108+
109+
- **`getDeclaredVariables(node)`**
110+
Get variables that are declared by the node.
111+
- `node` - The AST node to get declarations from.
112+
- Returns: An array of variable objects declared by the node. If the node doesn't declare any variables, it returns an empty array.
113+
114+
- **`isGlobalReturn()`**
115+
Determines if the global return statement should be allowed.
116+
- Returns: `true` if the global return is enabled.
117+
118+
- **`isModule()`**
119+
Checks if the code should be handled as an ECMAScript module.
120+
- Returns: `true` if the sourceType is "module".
121+
122+
- **`isImpliedStrict()`**
123+
Checks if implied strict mode is enabled.
124+
- Returns: `true` if implied strict mode is enabled.
125+
126+
- **`isStrictModeSupported()`**
127+
Checks if strict mode is supported based on ECMAScript version.
128+
- Returns: `true` if the ECMAScript version supports strict mode.
129+
130+
### Scope Objects
131+
132+
Scopes returned by the ScopeManager methods have the following properties:
133+
134+
- `type` - The type of scope (e.g., "function", "block", "global").
135+
- `variables` - Array of variables declared in this scope.
136+
- `set` - A Map of variable names to Variable objects for variables declared in this scope.
137+
- `references` - Array of references in this scope.
138+
- `through` - Array of references in this scope and its child scopes that aren't resolved in this scope or its child scopes.
139+
- `variableScope` - Reference to the closest variable scope.
140+
- `upper` - Reference to the parent scope.
141+
- `childScopes` - Array of child scopes.
142+
- `block` - The AST node that created this scope.
143+
144+
### GlobalScope
145+
146+
The `GlobalScope` class is a specialized scope representing the global execution context. It extends the base `Scope` class with additional functionality for handling implicitly defined global variables.
147+
148+
#### Properties
149+
150+
- **`implicit`** - Tracks implicitly defined global variables (those used without declaration).
151+
- `set` - A Map of variable names to Variable objects for implicitly defined globals.
152+
- `variables` - Array of implicit global Variable objects.
153+
- `left` - Array of References that need to be linked to the variable they refer to.
154+
155+
### Variable Objects
156+
157+
Each variable object has the following properties:
158+
159+
- `name` - The variable name.
160+
- `identifiers` - Array of identifier nodes declaring this variable.
161+
- `references` - Array of references to this variable.
162+
- `defs` - Array of definition objects for this variable.
163+
- `scope` - The scope object where this variable is defined.
164+
165+
77166
## Contributing
78167

79168
Issues and pull requests will be triaged and responded to as quickly as possible. We operate under the [ESLint Contributor Guidelines](http://eslint.org/docs/developer-guide/contributing), so please be sure to read them before contributing. If you're not sure where to dig in, check out the [issues](https://github.com/eslint/js/issues).

0 commit comments

Comments
 (0)