Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

unicorn/no-console-spaces

Disallow spaces at the edges of strings where console.log() already adds one

console.log() puts a space between its arguments. If a string ends with a space before the next argument, or starts with one after the previous argument, you get two spaces. For example, console.log("Total: ", 5) prints Total: 5.

The rule checks console.log(), console.debug(), console.info(), console.warn(), and console.error().

--fix trims the reported string at both ends.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"unicorn/no-console-spaces" = "error" # or "warn"

Examples

Reported:

console.log("Total: ", total);
console.error(path, " was not found");
console.info(`Saved ${count} files `, "in", elapsed);

Not reported:

console.log("Total:", total);
console.error(path, "was not found");
console.info(`Saved ${count} files`, "in", elapsed);

Spaces at the start of the first argument and at the end of the last one are allowed, because nothing is printed next to them:

console.log("  Total:", total);
console.log("Done ");