Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

no-const-assign

Disallow reassigning const, using and await using variables

Assigning to a variable declared with const, using or await using throws a TypeError when that line runs. The rule catches it earlier, including in branches your tests never reach.

=, compound assignments such as +=, ++ and -- all count.

This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.

Configure

On by default as an error. To turn it off:

bunfig.toml
[lint.rules]
"no-const-assign" = "off" # or "warn"

Examples

Reported:

const retries = 0;

function onFailure() {
  retries += 1;
}

function reset() {
  retries = 0;
}

Not reported:

let retries = 0;

function onFailure() {
  retries += 1;
}

const protects the variable, not the value it holds. Changing a property is fine:

const settings = { theme: "light" };
settings.theme = "dark";