Skip to content

Commit

Permalink
docs: replace var with const in rule examples (eslint#19299)
Browse files Browse the repository at this point in the history
* docs: replace var with const in rule example

* revert changes in no-else-block

* replace var in no-empty-pattern
  • Loading branch information
Tanujkanti4441 authored Jan 1, 2025
1 parent a559009 commit 8e00305
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/src/rules/no-dupe-class-members.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Foo {
bar() { console.log("goodbye"); }
}

var foo = new Foo();
const foo = new Foo();
foo.bar(); // goodbye
```

Expand Down
10 changes: 5 additions & 5 deletions docs/src/rules/no-dupe-keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ handled_by_typescript: true
Multiple properties with the same key in object literals can cause unexpected behavior in your application.

```js
var foo = {
const foo = {
bar: "baz",
bar: "qux"
};
Expand All @@ -26,17 +26,17 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-dupe-keys: "error"*/

var foo = {
const foo = {
bar: "baz",
bar: "qux"
};

var foo = {
const bar = {
"bar": "baz",
bar: "qux"
};

var foo = {
const baz = {
0x1: "baz",
1: "qux"
};
Expand All @@ -51,7 +51,7 @@ Examples of **correct** code for this rule:
```js
/*eslint no-dupe-keys: "error"*/

var foo = {
const foo = {
bar: "baz",
quxx: "qux"
};
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/no-duplicate-case.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-duplicate-case: "error"*/

var a = 1,
const a = 1,
one = 1;

switch (a) {
Expand Down Expand Up @@ -64,7 +64,7 @@ Examples of **correct** code for this rule:
```js
/*eslint no-duplicate-case: "error"*/

var a = 1,
const a = 1,
one = 1;

switch (a) {
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/no-empty-character-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rule_type: problem
Because empty character classes in regular expressions do not match anything, they might be typing mistakes.

```js
var foo = /^abc[]/;
const foo = /^abc[]/;
```

## Rule Details
Expand Down Expand Up @@ -73,5 +73,5 @@ Example of a *false negative* when this rule reports correct code:
```js
/*eslint no-empty-character-class: "error"*/

var abcNeverMatches = new RegExp("^abc[]");
const abcNeverMatches = new RegExp("^abc[]");
```
30 changes: 15 additions & 15 deletions docs/src/rules/no-empty-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ When using destructuring, it's possible to create a pattern that has no effect.

```js
// doesn't create any variables
var {a: {}} = foo;
const {a: {}} = foo;
```

In this code, no new variables are created because `a` is just a location helper while the `{}` is expected to contain the variables to create, such as:

```js
// creates variable b
var {a: { b }} = foo;
const {a: { b }} = foo;
```

In many cases, the empty object pattern is a mistake where the author intended to use a default value instead, such as:

```js
// creates variable a
var {a = {}} = foo;
const {a = {}} = foo;
```

The difference between these two patterns is subtle, especially because the problematic empty pattern looks just like an object literal.
Expand All @@ -39,10 +39,10 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-empty-pattern: "error"*/

var {} = foo;
var [] = foo;
var {a: {}} = foo;
var {a: []} = foo;
const {} = foo;
const [] = foo;
const {a: {}} = foo;
const {a: []} = foo;
function foo({}) {}
function bar([]) {}
function baz({a: {}}) {}
Expand All @@ -58,8 +58,8 @@ Examples of **correct** code for this rule:
```js
/*eslint no-empty-pattern: "error"*/

var {a = {}} = foo;
var {a = []} = foo;
const {a = {}} = foo;
const {b = []} = foo;
function foo({a = {}}) {}
function bar({a = []}) {}
```
Expand All @@ -84,10 +84,10 @@ Examples of **incorrect** code for this rule with the `{"allowObjectPatternsAsPa
/*eslint no-empty-pattern: ["error", { "allowObjectPatternsAsParameters": true }]*/

function foo({a: {}}) {}
var bar = function({a: {}}) {};
var bar = ({a: {}}) => {};
var bar = ({} = bar) => {};
var bar = ({} = { bar: 1 }) => {};
const bar = function({a: {}}) {};
const qux = ({a: {}}) => {};
const quux = ({} = bar) => {};
const item = ({} = { bar: 1 }) => {};

function baz([]) {}
```
Expand All @@ -102,8 +102,8 @@ Examples of **correct** code for this rule with the `{"allowObjectPatternsAsPara
/*eslint no-empty-pattern: ["error", { "allowObjectPatternsAsParameters": true }]*/

function foo({}) {}
var bar = function({}) {};
var bar = ({}) => {};
const bar = function({}) {};
const qux = ({}) => {};

function baz({} = {}) {}
```
Expand Down

0 comments on commit 8e00305

Please sign in to comment.