quick-lint-js

quick-lint-js finds bugs in JavaScript programs.

quick-lint-js can find the following warnings and errors in your code:

E001: variable assigned before its declaration

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;
}

E002: assignment to const global variable

Infinity, NaN, and undefined are global variables which cannot be changed. Assignments to these variables are silently ignored.

NaN = 0;
undefined = null;

To fix this error, pick a different variable to assign to.

E003: assignment to const variable

You cannot reassign variables declared with const. The assignment will crash with a ReferenceError if you run the code.

const pi = 3.14;
pi = 6;

const friends = ["Alice"];
friends = ["Bob"];

To fix this error, assign to a different variable, declare a new variable with a different name, or change const to let:

let pi = 3.14;
pi = 6;

const friends = ["Alice"];
const acquaintances = ["Bob"];

E004: assignment to const variable before its declaration

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;

See also: E001, E003

E005: BigInt literal contains decimal point

BigInt literals are number literals with an n suffix. These literals must represent integers and cannot contain a decimal point (.).

let gallons = 3.50n;
let pennies = 100.00n;

To fix this error, make the number literal a Number literal by removing the n suffix, or remove the fractional portion of the number:

let gallons = 3.50;
let pennies = 100n;

E006: BigInt literal contains exponent

BigInt literals are number literals with an n suffix. These literals must represent integers and cannot contain exponents (e).

let atomDiameter = 1e-10n;
let score = 1e2n;

To fix this error, make the number literal a Number literal by removing the n suffix, or expand the exponent of the number:

let atomDiameter = 1e-10;
let score = 100n;

E007: classes cannot be named 'let'

Classes declared with class cannot be named let.

class let {
  bark() {
    console.log("woof");
  }
}

To fix this error, name the class something other than let, or declare the class with var:

class Dog {
  bark() {
    console.log("woof");
  }
}

var let = class {
  bark() {
    console.log("woof");
  }
};

E008: let statement cannot declare variables named 'let'

Variables declared with let cannot be named let.

function getLotNumber() { return 42; }

let let = getLotNumber();
console.log(let);

To fix this error, name the variable something other than let, or declare the variable with var:

function getLotNumber() { return 42; }

let lot = getLotNumber();
console.log(lot);

var let = getLotNumber();
console.log(let);

E009: cannot export variable named 'let'

An exported function cannot be named let:

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 };

E010: cannot import 'let'

An imported function or variable cannot be named let:

import { let } from "./security.mjs";

To fix this error, name the function or variable something other than let, or rename the function or variable using import-as:

import { allow } from "./security.mjs";

import { let as permit } from "./security.mjs";

E012: escaped character is not allowed in identifiers

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:

Characters after the initial character in a function or variable name can be any of the following:

E063: missing operator between expression and arrow function

The left-hand side of => must be a list of parameters. It is a syntax error if the left-hand side looks like a function call:

let fs = require("fs");
let path = process.argv[2];
fs.readFile(path (err, data) => {
  console.log(data);
});

To fix this error, 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.readFile(path, (err, data) => {
  console.log(data);
});

E077: function call before declaration in blocked scope

A function can't be called before its declaration in block scope in Safari.

f();
{
    function f() {}
}

To fix this error, move the function call below the block scope in which it is declared:

{
    function f() {}
}
f();

Another way to fix this error, move the function out of the block scope in which it is declared.

f();
function f() {}
{
}

OR

f();
{
}
function f() {}

E086: redundant delete statement on variable

The following delete statement is redundant on variable:

let x = 3;
delete x;
console.log(x);

To fix this warning, remove the delete statement:

let x = 3;
console.log(x);

E095: Unicode byte order mark (BOM) cannot appear before #! at beginning of script

A script cannot have Unicode byte order mark (BOM) before #!

#!/usr/bin/env node
let x = 3;
console.log(x);

To fix this error, remove the Unicode BOM before #!

#!/usr/bin/env node
let x = 3;
console.log(x);

E160: unexpected '=>'; expected parameter for arrow function, but got an expression instead

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"));

E202: missing '=' after variable

The following code has a missing equal '=' after variable name.

let x new Array();

To fix this error, add '=' after variable x.

let x = new Array();