Skip to content

Commit

Permalink
Update: report class evaluation TDZ errors in no-use-before-define
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Oct 4, 2021
1 parent d867f81 commit 3b8fda5
Show file tree
Hide file tree
Showing 3 changed files with 734 additions and 78 deletions.
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;
}
```

0 comments on commit 3b8fda5

Please sign in to comment.