Variables declared with let can only be reassigned by code below the
declaration. The assignment will crash with a ReferenceError if you assign to
the variable.
function getNumberOfChocolates() { return 3; }
let shouldEatChocolates = true;
if (shouldEatChocolates) {
chocolates = 0;
}
let chocolates = getNumberOfChocolates();
To fix this error, move the declaration above the assignment:
function getNumberOfChocolates() { return 3; }
let shouldEatChocolates = true;
let chocolates = getNumberOfChocolates();
if (shouldEatChocolates) {
chocolates = 0;
}
You cannot reassign variables declared with const, and you cannot reference a
variable declared with const above its declaration. The assignment will crash
with a ReferenceError if you run the code.
let timeElapsed = 31;
let pie = "cooking";
if (timeElapsed > 30) {
pi = "cooked";
}
const pi = 3.14;
To fix this error, assign to a different variable or declare a new variable with
a different name:
let timeElapsed = 31;
let pie = "cooking";
if (timeElapsed > 30) {
pie = "cooked";
}
const pi = 3.14;
export function let() {
console.log("access permitted");
}
To fix this error, name the function something other than let, or declare the
function separately with a different name and use export-as:
export function allow() {
console.log("access permitted");
}
function allowAccess() {
console.log("access permitted");
}
export { allowAccess as let };
A function or variable name includes a Unicode escape sequence, and the escape sequence
refers to a character which isn't allowed in a function or variable name:
let guitar\u2604 = "\uD83C\uDFB8";
let handc\uffed = true;
To fix this error, use the code point of a Unicode character which is allowed,
or remove the extraneous backslash from the name:
let guitar\u3604 = "\uD83C\uDFB8";
let handcuffed = true;
The initial character in a function or variable name can be any of the
following:
ID_Start
$
_
Characters after the initial character in a function or variable name can be
any of the following:
A function or variable name includes a Unicode escape sequence, and the escape
sequence refers to a character which is beyond the range of valid Unicode code
points (U+0000 to U+10FFFF):
class ChirpSound {}
let bird\u{360000} = new ChirpSound();
To fix this error, use the code point of a Unicode character which is in range:
class ChirpSound {}
let bird\u{3600} = new ChirpSound();
In variable names and strings, a Unicode escape sequence must contain only
hexadecimal digits (any of 0123456789abcdefABCDEF). It is an error if other
characters appear within a Unicode escape sequence:
console.log("List of Pok\ue9mon by weight:");
console.log("Nidoran\u{2642 {male}");
For an escape sequence without { and }, add { and }:
console.log("List of Pok\u{e9}mon by weight:");
Alternatively, for an escape sequence without { and }, include 0 digits
such that the escape sequence contains exactly four hexadecimal digits:
console.log("List of Pok\u00e9mon by weight:");
For an escape sequence with { and }, ensure the } appears after the
hexadecimal digits:
const, let, and var can only declare variables directly or by
destructuring an array or an object. Number literals and keywords are not
allowed where a variable name is expected:
let wordCounts = {for: 4, if: 5, while: 0};
let {for, if} = wordCounts;
let queue = ["first", "second", "third"];
let {first: 0} = queue;
To fix this error when destructuring an object with keyword keys, pick a
variable name which is not a keyword:
let wordCounts = {for: 4, if: 5, while: 0};
let {for: forWordCount, if: ifWordCount} = wordCounts;
When destructuring an object, it's common to confuse the variable name with the
key. Make sure the variable name comes after the ::
let queue = ["first", "second", "third"];
let {0: first} = queue;
An object literal entry must either be a key: value pair, a method, or
variable short-hand. It is an error to use the short-hand syntax with anything
except a variable name:
// A tasty enum
const FRUITS = {
"BANANA",
"ORANGE",
"STRAWBERRY",
"KIWI",
};
// Pre-computed for speed
let smallPrimes = {2, 3, 5, 7, 11, 13, 17, 19};
To fix this error, either use the key: value pair syntax, or use [] to
create an array literal instead of an object literal:
Outside a string or template literal, Unicode escape sequences (like \u{65})
can be used in identifiers. However, Unicode escape sequences are not allowed if
they would make an identifier look like a keyword when unescaped:
let \u{69}\u{66} = "if";
let which = \u{66}inally;
To fix this error, either pick a different variable name, or make a string:
let _\u{69}\u{66} = "if";
let which = "\u{66}inally";
Binary operators (such as * and >>) require an expression (e.g. a variable
or number) on both sides of the operator. Unary operators require an expression
before or after the operator (depending on the operator). Ternary operators
require three expressions. With some exceptions, it is an error to exclude an
expression:
let ripe = true;
let tasty = true;
if (ripe && ) {
console.log("delicious!")+;
}
To fix this error, add an expression, or remove the extraneous operator:
let ripe = true;
let tasty = true;
if (ripe && tasty) {
console.log("delicious!");
}
Note that sometimes, it appears that expressions can be omitted, but some
operators are binary and unary, and some operators look like other operators
conjoined. In these cases, the code might be completely valid, so quick-lint-js
won't report any error:
3**5 // different than: 3 * * 5
3<<5 // different than: 3 < < 5
7 + - 8 // same as: 7 + (-8)
Global variables listed in quick-lint-js.config with "shadowable": false
cannot be re-declared in the global scope by a JavaScript module or script:
let window = new windowlib.Window();
let $ = (selector) => document.querySelectorAll(selector);
$('#banana')[0].peel();
To fix this error, choose a different variable name, or put the variable (and
code which uses the variable) into a function:
let qsa = (selector) => document.querySelectorAll(selector);
qsa('#banana')[0].peel();
function createUI() {
let myWindow = new windowlib.Window();
}
createUI();
In a given function or {} block, a variable can only be declared multiple
times if it is declared with var or function. Other types of variables can
be declared only once:
let x, y, y, w;
const friends = loadFriends();
const friends = friends.filter(friend => friend.name !== "strager");
class Orange { name = "orange" }
class Orange { name = "banana" }
function jump(player, height) {
let height = height || player.height/2;
}
To fix this error, assign to the existing variable, choose a different variable
name, or delete the extra variable:
let x, y, z, w;
let friends = loadFriends();
friends = friends.filter(friend => friend.name !== "strager");
class Orange { name = "orange" }
class Banana { name = "banana" }
function jump(player, height) {
height = height || player.height/2;
}
Regular expression literals start with / and end with /. The / symbol is
also used for the division operator. It is a syntax error to omit the trailing
/ from a regular expression literal:
// The final / is escaped by \.
let LINE_CONTINUATION_RE = / +\/m;
function feetToCentimeters(feet) {
// The / is interpreted as the start of a regular
// expression, not the division operator.
return / 3.28 * 100;
}
To fix this error, close the regular expression literal:
let LINE_CONTINUATION_RE = / +\\/m;
Alternatively, include an expression before / to treat the / as a division
operator:
function feetToCentimeters(feet) {
return feet / 3.28 * 100;
}
String literals start with " or ' and end with " or ', respectively.
It is a syntax error to omit the trailing " or ' from a string literal. A
missing terminator can happen for a number of reasons:
// The final " is escaped by \.
let temp = "c:\temp\";
// String literals cannot span multiple lines.
let poemByIanJohnson = "My code fails. I do not know why.
My code works. I do not know why.";
let unfinishedThought = "The solution to all of our problems is
To fix this error, ensure a backslash (\) is not escaping the terminator,
use a template literal for multi-line strings, or just include a terminator:
let temp = "c:\\temp\\";
let poemByIanJohnson = `My code fails. I do not know why.
My code works. I do not know why.`;
let unfinishedThought = "The solution to all of our problems is";
Identifiers (variable names, etc.) can contain Unicode escape sequences
(\u{69} for example). It is an error for an identifier to have a backslash
which is not part of a Unicode escape sequence:
function identity\(x) { return x; }
let bird\U3600 = new ChirpSound();
To fix this error, remove the backslash, or complete the Unicode escape
sequence:
function identity(x) { return x; }
let bird\u3600 = new ChirpSound();
The left-hand side of => must be a list of parameters. It is a syntax error if
the left-hand side is instead an expression (such as a property access or a
function call):
if (this.mapSize => this.capacity) {
throw new Error("too many items");
}
let fs = require("fs");
let path = process.argv[2];
fs.mkdir(path () => console.log("done"));
To fix this error, replace => with the intended operator, such as >=:
if (this.mapSize >= this.capacity) {
throw new Error("too many items");
}
Alternatively, make the left-hand side of => valid by adding an operator
(usually ,) before the parameter list:
let fs = require("fs");
let path = process.argv[2];
fs.mkdir(path, () => console.log("done"));
In a quick-lint-js configuration file, a entry in "globals" can have a
descriptor object. A descriptor's "shadowable" property must be either true,
false, or omitted.
{
"globals": {
"gsap": {
"shadowable": 0
}
}
}
To fix this error, make the "shadowable" property true or false:
In a quick-lint-js configuration file, a entry in "globals" can have a
descriptor object. A descriptor's "writable" property must be either true,
false, or omitted.
{
"globals": {
"gsap": {
"writable": 0
}
}
}
To fix this error, make the "writable" property true or false:
In a quick-lint-js configuration file, "globals" must be an object or
omitted. It is an error if "globals" is an array, a boolean, a number, a
string, or null:
In a quick-lint-js configuration file, "global-groups" must be an array of
strings, a boolean, or omitted. It is an error if "global-groups" is a
boolean, a number, an object, a string, or null:
In a quick-lint-js configuration file, items in the "global-groups" array
must be strings. It is an error if an item is an array, a boolean, a number, an
object, or null:
In a quick-lint-js configuration file, each entry in "globals"
must be a boolean or a descriptor object. It is an error if a "globals" item
is an array, a number, a string, or null:
{
"globals": {
"gsap": "true"
}
}
To fix this error, make the "globals" entry true or false: