You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/extend/custom-rules.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,6 +125,7 @@ The `context` object has the following properties:
125
125
126
126
*`id`: (`string`) The rule ID.
127
127
*`filename`: (`string`) The filename associated with the source.
128
+
*`cwd`: (`string`) The `cwd` option passed to the [Linter](../integrate/nodejs-api#linter). It is a path to a directory that should be considered the current working directory.
128
129
*`options`: (`array`) An array of the [configured options](../use/configure/rules) for this rule. This array does not include the rule severity (see the [dedicated section](#accessing-options-passed-to-a-rule)).
129
130
*`settings`: (`object`) The [shared settings](../use/configure/configuration-files#adding-shared-settings) from the configuration.
130
131
*`parserPath`: (`string`) The name of the `parser` from the configuration.
@@ -134,7 +135,7 @@ The `context` object has the following properties:
134
135
Additionally, the `context` object has the following methods:
135
136
136
137
*`getAncestors()`: (**Deprecated:** Use `SourceCode#getAncestors(node)` instead.) Returns an array of the ancestors of the currently-traversed node, starting at the root of the AST and continuing through the direct parent of the current node. This array does not include the currently-traversed node itself.
137
-
*`getCwd()`: Returns the `cwd` option passed to the [Linter](../integrate/nodejs-api#linter). It is a path to a directory that should be considered the current working directory.
138
+
*`getCwd()`: (**Deprecated:** Use `context.cwd` instead.) Returns the `cwd` option passed to the [Linter](../integrate/nodejs-api#linter). It is a path to a directory that should be considered the current working directory.
138
139
*`getDeclaredVariables(node)`: (**Deprecated:** Use `SourceCode#getDeclaredVariables(node)` instead.) Returns a list of [variables](./scope-manager-interface#variable-interface) declared by the given node. This information can be used to track references to variables.
139
140
* If the node is a `VariableDeclaration`, all variables declared in the declaration are returned.
140
141
* If the node is a `VariableDeclarator`, all variables declared in the declarator are returned.
Copy file name to clipboardExpand all lines: docs/src/integrate/nodejs-api.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -510,7 +510,7 @@ The `Linter` object does the actual evaluation of the JavaScript code. It doesn'
510
510
511
511
The `Linter` is a constructor, and you can create a new instance by passing in the options you want to use. The available options are:
512
512
513
-
*`cwd` - Path to a directory that should be considered as the current working directory. It is accessible to rules by calling `context.getCwd()` (see [The Context Object](../extend/custom-rules#the-context-object)). If `cwd` is `undefined`, it will be normalized to `process.cwd()` if the global `process` object is defined (for example, in the Node.js runtime) , or `undefined` otherwise.
513
+
*`cwd` - Path to a directory that should be considered as the current working directory. It is accessible to rules from `context.cwd` or by calling `context.getCwd()` (see [The Context Object](../extend/custom-rules#the-context-object)). If `cwd` is `undefined`, it will be normalized to `process.cwd()` if the global `process` object is defined (for example, in the Node.js runtime) , or `undefined` otherwise.
In this example, rules run on `linter1` will get `path/to/project` when calling `context.getCwd()`.
523
+
In this example, rules run on `linter1` will get `path/to/project`from `context.cwd` or when calling `context.getCwd()`.
524
524
Those run on `linter2` will get `process.cwd()` if the global `process` object is defined or `undefined` otherwise (e.g. on the browser <https://eslint.org/demo>).
0 commit comments