Skip to content

Commit

Permalink
docs: resubmit pr 17115 doc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jun 15, 2023
1 parent 9e3d77c commit d67e307
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions docs/src/extend/code-path-analysis.md
Expand Up @@ -259,8 +259,7 @@ Please use a map of information instead.
```js
function hasCb(node, context) {
if (node.type.indexOf("Function") !== -1) {
const sourceCode = context.getSourceCode();

const sourceCode = context.sourceCode;
return sourceCode.getDeclaredVariables(node).some(function(v) {
return v.type === "Parameter" && v.name === "cb";
});
Expand Down
10 changes: 6 additions & 4 deletions docs/src/extend/custom-rules.md
Expand Up @@ -147,7 +147,7 @@ Additionally, the `context` object has the following methods:
* `getFilename()`: Returns the filename associated with the source.
* `getPhysicalFilename()`: When linting a file, it returns the full path of the file on disk without any code block information. When linting text, it returns the value passed to `—stdin-filename` or `<text>` if not specified.
* `getScope()`: (**Deprecated:** Use `SourceCode#getScope(node)` instead.) Returns the [scope](./scope-manager-interface#scope-interface) of the currently-traversed node. This information can be used to track references to variables.
* `getSourceCode()`: Returns a `SourceCode` object that you can use to work with the source that was passed to ESLint (see [Accessing the Source Code](#accessing-the-source-code)).
* `getSourceCode()`: (**Deprecated:** Use `context.sourceCode` instead.) Returns a `SourceCode` object that you can use to work with the source that was passed to ESLint (see [Accessing the Source Code](#accessing-the-source-code)).
* `markVariableAsUsed(name)`: (**Deprecated:** Use `SourceCode#markVariableAsUsed(name, node)` instead.) Marks a variable with the given name in the current scope as used. This affects the [no-unused-vars](../rules/no-unused-vars) rule. Returns `true` if a variable with the given name was found and marked as used, otherwise `false`.
* `report(descriptor)`. Reports a problem in the code (see the [dedicated section](#reporting-problems)).

Expand Down Expand Up @@ -506,18 +506,20 @@ When using options, make sure that your rule has some logical defaults in case t

### Accessing the Source Code

The `SourceCode` object is the main object for getting more information about the source code being linted. You can retrieve the `SourceCode` object at any time by using the `context.getSourceCode()` method:
The `SourceCode` object is the main object for getting more information about the source code being linted. You can retrieve the `SourceCode` object at any time by using the `context.sourceCode` property:

```js
module.exports = {
create: function(context) {
var sourceCode = context.getSourceCode();
var sourceCode = context.sourceCode;

// ...
}
};
```

**Deprecated:** The `context.getSourceCode()` method is deprecated; make sure to use `context.sourceCode` property instead.

Once you have an instance of `SourceCode`, you can use the following methods on it to work with the code:

* `getText(node)`: Returns the source code for the given node. Omit `node` to get the whole source (see the [dedicated section](#accessing-the-source-text)).
Expand Down Expand Up @@ -706,7 +708,7 @@ To help with this, you can use the `sourceCode.markVariableAsUsed()` method. Thi
```js
module.exports = {
create: function(context) {
var sourceCode = context.getSourceCode();
var sourceCode = context.sourceCode;

return {
ReturnStatement(node) {
Expand Down

0 comments on commit d67e307

Please sign in to comment.