Skip to content
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

feat: report class evaluation TDZ errors in no-use-before-define #15134

Merged
merged 1 commit into from Nov 5, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 71 additions & 4 deletions docs/rules/no-use-before-define.md
Expand Up @@ -12,7 +12,6 @@ Examples of **incorrect** code for this rule:

```js
/*eslint no-use-before-define: "error"*/
/*eslint-env es6*/

alert(a);
var a = 10;
Expand All @@ -29,13 +28,29 @@ var b = 1;
alert(c);
let c = 1;
}

{
class C extends C {}
}

{
class C {
static x = "foo";
[C.x]() {}
}
}

{
const C = class {
static x = C;
}
}
```

Examples of **correct** code for this rule:

```js
/*eslint no-use-before-define: "error"*/
/*eslint-env es6*/

var a;
a = 10;
Expand All @@ -53,6 +68,24 @@ function g() {
let c;
c++;
}

{
class C {
static x = C;
}
}

{
const C = class C {
static x = C;
}
}

{
const C = class {
x = C;
}
}
```

## Options
Expand Down Expand Up @@ -103,18 +136,32 @@ Examples of **incorrect** code for the `{ "classes": false }` option:

```js
/*eslint no-use-before-define: ["error", { "classes": false }]*/
/*eslint-env es6*/

new A();
class A {
}

{
class C extends C {}
}

{
class C extends D {}
class D {}
}

{
class C {
static x = "foo";
[C.x]() {}
}
}
```

Examples of **correct** code for the `{ "classes": false }` option:

```js
/*eslint no-use-before-define: ["error", { "classes": false }]*/
/*eslint-env es6*/

function foo() {
return new A();
Expand All @@ -139,6 +186,19 @@ const f = () => {};

g();
const g = function() {};

{
const C = class {
static x = C;
}
}

{
const C = class {
static x = foo;
}
const foo = 1;
}
```

Examples of **correct** code for the `{ "variables": false }` option:
Expand All @@ -158,4 +218,11 @@ const f = () => {};

const e = function() { return g(); }
const g = function() {}

{
const C = class {
x = foo;
}
const foo = 1;
}
```