Skip to content

Commit e6e2523

Browse files
committed
Docs: document E057, E058, E059
1 parent c0430ac commit e6e2523

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

docs/errors/E057.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# E057: use of undeclared variable
2+
3+
```config-for-examples
4+
{
5+
"globals": {
6+
"isHappy": true
7+
}
8+
}
9+
```
10+
11+
It is an error to use a function or variable without declaring it:
12+
13+
consol.write("Hello, world!");
14+
const one = Math.sin(pi/2);
15+
16+
function encrypt() {
17+
return data ^ 0x13371337;
18+
}
19+
20+
if (isHappy) {
21+
let emotion = "happy";
22+
} else {
23+
let emotion = "sad";
24+
}
25+
console.log("I am " + emotion);
26+
27+
function MyComponent({}) {
28+
let [pressed, setPressed] = useState(false);
29+
}
30+
31+
google.charts.load('current', {'packages':['corechart']});
32+
33+
To fix this error, fix the name of the function or variable:
34+
35+
console.write("Hello, world!");
36+
const one = Math.sin(Math.pi/2);
37+
38+
Alternatively, declare the function or variable:
39+
40+
function encrypt(data) {
41+
return data ^ 0x13371337;
42+
}
43+
44+
Alternatively, move the declaration of the variable into an outer scope:
45+
46+
let emotion;
47+
if (isHappy) {
48+
emotion = "happy";
49+
} else {
50+
emotion = "sad";
51+
}
52+
console.log("I am " + emotion);
53+
54+
Alternatively, import the function or variable:
55+
56+
import { useState } from "react";
57+
function MyComponent({}) {
58+
let [pressed, setPressed] = useState(false);
59+
}
60+
61+
Alternatively, if the function or variable is global in your environment, [write
62+
a quick-lint-js.config file](https://quick-lint-js.com/config/).

docs/errors/E058.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# E058: variable used before declaration
2+
3+
```config-for-examples
4+
{
5+
"globals": {
6+
"person": true
7+
}
8+
}
9+
```
10+
11+
Variables can be declared in many ways. For variables declared with `class`,
12+
`const`, or `let`, it is an error to use the variable before/above its
13+
declaration:
14+
15+
let firstName = person.firstName;
16+
if (firstName === "") {
17+
firstName = lastName;
18+
}
19+
let lastName = person.lastName;
20+
21+
function printAdjacentPairs(items) {
22+
let first = true;
23+
for (let current of items) {
24+
if (!first) {
25+
console.log(previous, current);
26+
}
27+
let previous = current;
28+
first = false;
29+
}
30+
}
31+
32+
To fix this error, move the variable's declaration up above its use:
33+
34+
let firstName = person.firstName;
35+
let lastName = person.lastName;
36+
if (firstName === "") {
37+
firstName = lastName;
38+
}
39+
40+
Alternatively, declare the variable in an outer scope:
41+
42+
function printAdjacentPairs(items) {
43+
let first = true;
44+
let previous;
45+
for (let current of items) {
46+
if (!first) {
47+
console.log(previous, current);
48+
}
49+
previous = current;
50+
first = false;
51+
}
52+
}

docs/errors/E059.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# E059: assignment to undeclared variable
2+
3+
```config-for-examples
4+
{
5+
"globals": {
6+
"isHappy": true
7+
}
8+
}
9+
```
10+
11+
It is an error to assign to a variable without declaring it:
12+
13+
tau = Math.pi * 2;
14+
15+
let emotion;
16+
if (isHappy) {
17+
emotion = "happy";
18+
} else {
19+
emotio = "sad";
20+
}
21+
console.log("I am " + emotion);
22+
23+
To fix this error, declare the variable using `const` or `let`:
24+
25+
let emotion;
26+
if (isHappy) {
27+
emotion = "happy";
28+
} else {
29+
emotion = "sad";
30+
}
31+
console.log("I am " + emotion);
32+
33+
Alternatively, if the variable is global in your environment, [write a
34+
quick-lint-js.config file](https://quick-lint-js.com/config/).

0 commit comments

Comments
 (0)