Skip to content

Commit

Permalink
docs: mark context#getSourceCode() as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Apr 22, 2023
1 parent a186f48 commit a0c8e6e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/src/extend/code-path-analysis.md
Expand Up @@ -259,7 +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
7 changes: 4 additions & 3 deletions docs/src/extend/custom-rules.md
Expand Up @@ -147,7 +147,8 @@ 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)).
* `sourceCode`: 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 @@ -511,7 +512,7 @@ The `SourceCode` object is the main object for getting more information about th
```js
module.exports = {
create: function(context) {
var sourceCode = context.getSourceCode();
var sourceCode = context.sourceCode; // or use "context.getSourceCode()", but that is deprecated.

// ...
}
Expand Down Expand Up @@ -706,7 +707,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
2 changes: 1 addition & 1 deletion tests/lib/linter/linter.js
Expand Up @@ -116,7 +116,7 @@ describe("Linter", () => {

it("has all the `parent` properties on nodes when the rule listeners are created", () => {
const spy = sinon.spy(context => {
const ast = context.getSourceCode().ast;
const ast = context.sourceCode.ast;

assert.strictEqual(ast.body[0].parent, ast);
assert.strictEqual(ast.body[0].expression.parent, ast.body[0]);
Expand Down

0 comments on commit a0c8e6e

Please sign in to comment.