Skip to content

docs: replace var with const in rule examples #19299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy