Skip to content

Commit 6987dc5

Browse files
authored
docs: Fix formatting in Custom Rules docs (#17097)
1 parent 4ee92e5 commit 6987dc5

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

docs/src/extend/custom-rules.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ The `context` object has the following properties:
132132

133133
Additionally, the `context` object has the following methods:
134134

135-
* `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.
136-
* `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.
137-
* `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.
135+
* `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.
136+
* `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.
137+
* `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.
138138
* If the node is a `VariableDeclaration`, all variables declared in the declaration are returned.
139139
* If the node is a `VariableDeclarator`, all variables declared in the declarator are returned.
140140
* If the node is a `FunctionDeclaration` or `FunctionExpression`, the variable for the function name is returned, in addition to variables for the function parameters.
@@ -148,7 +148,7 @@ Additionally, the `context` object has the following methods:
148148
* `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.
149149
* `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.
150150
* `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)).
151-
* `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`.
151+
* `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`.
152152
* `report(descriptor)`. Reports a problem in the code (see the [dedicated section](#reporting-problems)).
153153

154154
**Note:** Earlier versions of ESLint supported additional methods on the `context` object. Those methods were removed in the new format and should not be relied upon.
@@ -257,7 +257,7 @@ var rule = require("../../../lib/rules/avoid-name");
257257
var RuleTester = require("eslint").RuleTester;
258258

259259
var ruleTester = new RuleTester();
260-
ruleTester.run("my-rule", rule, {
260+
ruleTester.run("avoid-name", rule, {
261261
valid: ["bar", "baz"],
262262
invalid: [
263263
{
@@ -318,22 +318,21 @@ Best practices for fixes:
318318
1. Make fixes as small as possible. Fixes that are unnecessarily large could conflict with other fixes, and prevent them from being applied.
319319
1. Only make one fix per message. This is enforced because you must return the result of the fixer operation from `fix()`.
320320
1. Since all rules are run again after the initial round of fixes is applied, it's not necessary for a rule to check whether the code style of a fix will cause errors to be reported by another rule.
321+
* For example, suppose a fixer would like to surround an object key with quotes, but it's not sure whether the user would prefer single or double quotes.
321322

322-
* For example, suppose a fixer would like to surround an object key with quotes, but it's not sure whether the user would prefer single or double quotes.
323+
```js
324+
({ foo : 1 })
323325

324-
```js
325-
({ foo : 1 })
326+
// should get fixed to either
326327

327-
// should get fixed to either
328+
({ 'foo': 1 })
328329

329-
({ 'foo': 1 })
330+
// or
330331

331-
// or
332+
({ "foo": 1 })
333+
```
332334

333-
({ "foo": 1 })
334-
```
335-
336-
* This fixer can just select a quote type arbitrarily. If it guesses wrong, the resulting code will be automatically reported and fixed by the [`quotes`](../rules/quotes) rule.
335+
* This fixer can just select a quote type arbitrarily. If it guesses wrong, the resulting code will be automatically reported and fixed by the [`quotes`](../rules/quotes) rule.
337336

338337
Note: Making fixes as small as possible is a best practice, but in some cases it may be correct to extend the range of the fix in order to intentionally prevent other rules from making fixes in a surrounding range in the same pass. For instance, if replacement text declares a new variable, it can be useful to prevent other changes in the scope of the variable as they might cause name collisions.
339338

0 commit comments

Comments
 (0)