Skip to content

Commit

Permalink
docs: rewrite var with const in rules examples (eslint#19317)
Browse files Browse the repository at this point in the history
* docs: rewrite var with const in rules examples

* docs: max-statements error fixed

* replace let to const
  • Loading branch information
ThiagoG8 authored Jan 7, 2025
1 parent 26c3003 commit 03f2f44
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 83 deletions.
124 changes: 62 additions & 62 deletions docs/src/rules/max-statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ The `max-statements` rule allows you to specify the maximum number of statements

```js
function foo() {
var bar = 1; // one statement
var baz = 2; // two statements
var qux = 3; // three statements
const bar = 1; // one statement
const baz = 2; // two statements
const qux = 3; // three statements
}
```

Expand Down Expand Up @@ -48,33 +48,33 @@ Examples of **incorrect** code for this rule with the default `{ "max": 10 }` op
/*eslint max-statements: ["error", 10]*/

function foo() {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;

var foo11 = 11; // Too many.
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
const foo10 = 10;

const foo11 = 11; // Too many.
}

let bar = () => {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;

var foo11 = 11; // Too many.
const bar = () => {
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
const foo10 = 10;

const foo11 = 11; // Too many.
};
```

Expand All @@ -88,43 +88,43 @@ Examples of **correct** code for this rule with the default `{ "max": 10 }` opti
/*eslint max-statements: ["error", 10]*/

function foo() {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
return function () { // 10

// The number of statements in the inner function does not count toward the
// statement maximum.

var bar;
var baz;
let bar;
let baz;
return 42;
};
}

let bar = () => {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
const bar = () => {
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
return function () { // 10

// The number of statements in the inner function does not count toward the
// statement maximum.

var bar;
var baz;
let bar;
let baz;
return 42;
};
}
Expand Down Expand Up @@ -170,17 +170,17 @@ Examples of additional **correct** code for this rule with the `{ "max": 10 }, {
/*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/

function foo() {
var foo1 = 1;
var foo2 = 2;
var foo3 = 3;
var foo4 = 4;
var foo5 = 5;
var foo6 = 6;
var foo7 = 7;
var foo8 = 8;
var foo9 = 9;
var foo10 = 10;
var foo11 = 11;
const foo1 = 1;
const foo2 = 2;
const foo3 = 3;
const foo4 = 4;
const foo5 = 5;
const foo6 = 6;
const foo7 = 7;
const foo8 = 8;
const foo9 = 9;
const foo10 = 10;
const foo11 = 11;
}
```

Expand Down
40 changes: 20 additions & 20 deletions docs/src/rules/new-cap.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rule_type: suggestion
The `new` operator in JavaScript creates a new instance of a particular type of object. That type of object is represented by a constructor function. Since constructor functions are just regular functions, the only defining characteristic is that `new` is being used as part of the call. Native JavaScript functions begin with an uppercase letter to distinguish those functions that are to be used as constructors from functions that are not. Many style guides recommend following this pattern to more easily determine which functions are to be used as constructors.

```js
var friend = new Person();
const friend = new Person();
```

## Rule Details
Expand Down Expand Up @@ -64,7 +64,7 @@ Examples of **incorrect** code for this rule with the default `{ "newIsCap": tru
```js
/*eslint new-cap: ["error", { "newIsCap": true }]*/

var friend = new person();
const friend = new person();
```

:::
Expand All @@ -76,7 +76,7 @@ Examples of **correct** code for this rule with the default `{ "newIsCap": true
```js
/*eslint new-cap: ["error", { "newIsCap": true }]*/

var friend = new Person();
const friend = new Person();
```

:::
Expand All @@ -88,7 +88,7 @@ Examples of **correct** code for this rule with the `{ "newIsCap": false }` opti
```js
/*eslint new-cap: ["error", { "newIsCap": false }]*/

var friend = new person();
const friend = new person();
```

:::
Expand All @@ -102,7 +102,7 @@ Examples of **incorrect** code for this rule with the default `{ "capIsNew": tru
```js
/*eslint new-cap: ["error", { "capIsNew": true }]*/

var colleague = Person();
const colleague = Person();
```

:::
Expand All @@ -114,7 +114,7 @@ Examples of **correct** code for this rule with the default `{ "capIsNew": true
```js
/*eslint new-cap: ["error", { "capIsNew": true }]*/

var colleague = new Person();
const colleague = new Person();
```

:::
Expand All @@ -126,7 +126,7 @@ Examples of **correct** code for this rule with the `{ "capIsNew": false }` opti
```js
/*eslint new-cap: ["error", { "capIsNew": false }]*/

var colleague = Person();
const colleague = Person();
```

:::
Expand All @@ -140,9 +140,9 @@ Examples of additional **correct** code for this rule with the `{ "newIsCapExcep
```js
/*eslint new-cap: ["error", { "newIsCapExceptions": ["events"] }]*/

var events = require('events');
const events = require('events');

var emitter = new events();
const emitter = new events();
```

:::
Expand All @@ -156,9 +156,9 @@ Examples of additional **correct** code for this rule with the `{ "newIsCapExcep
```js
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "^person\\.." }]*/

var friend = new person.acquaintance();
const friend = new person.acquaintance();

var bestFriend = new person.friend();
const bestFriend = new person.friend();
```

:::
Expand All @@ -170,7 +170,7 @@ Examples of additional **correct** code for this rule with the `{ "newIsCapExcep
```js
/*eslint new-cap: ["error", { "newIsCapExceptionPattern": "\\.bar$" }]*/

var friend = new person.bar();
const friend = new person.bar();
```

:::
Expand Down Expand Up @@ -200,8 +200,8 @@ Examples of additional **correct** code for this rule with the `{ "capIsNewExcep
```js
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^person\\.." }]*/

var friend = person.Acquaintance();
var bestFriend = person.Friend();
const friend = person.Acquaintance();
const bestFriend = person.Friend();
```

:::
Expand All @@ -225,11 +225,11 @@ Examples of additional **correct** code for this rule with the `{ "capIsNewExcep
```js
/*eslint new-cap: ["error", { "capIsNewExceptionPattern": "^Foo" }]*/

var x = Foo(42);
const x = Foo(42);

var y = Foobar(42);
const y = Foobar(42);

var z = Foo.Bar(42);
const z = Foo.Bar(42);
```

:::
Expand All @@ -243,7 +243,7 @@ Examples of **incorrect** code for this rule with the default `{ "properties": t
```js
/*eslint new-cap: ["error", { "properties": true }]*/

var friend = new person.acquaintance();
const friend = new person.acquaintance();
```

:::
Expand All @@ -255,7 +255,7 @@ Examples of **correct** code for this rule with the default `{ "properties": tru
```js
/*eslint new-cap: ["error", { "properties": true }]*/

var friend = new person.Acquaintance();
const friend = new person.Acquaintance();
```

:::
Expand All @@ -267,7 +267,7 @@ Examples of **correct** code for this rule with the `{ "properties": false }` op
```js
/*eslint new-cap: ["error", { "properties": false }]*/

var friend = new person.acquaintance();
const friend = new person.acquaintance();
```

:::
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/no-alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ customConfirm("Are you sure?");
customPrompt("Who are you?");

function foo() {
var alert = myCustomLib.customAlert;
const alert = myCustomLib.customAlert;
alert();
}
```
Expand Down

0 comments on commit 03f2f44

Please sign in to comment.