Skip to content

noConsoleSpaces (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noConsoleSpaces": "error"
}
}
}
}

Disallow leading and trailing spaces in console method arguments.

console.log(), console.debug(), console.info(), console.warn(), and console.error() put a space between their arguments when printing them. A string argument that starts or ends with a space next to another argument prints two spaces instead of one.

The first argument may start with a space, and the last argument may end with one, because nothing is printed before or after them. Strings that contain only one space, or that start or end with two or more spaces, are allowed because the extra spacing is likely intentional.

console.log("abc ", "def");
code-block.js:1:17 lint/nursery/noConsoleSpaces  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This argument ends with a space.

> 1 │ console.log("abc ", "def");
│ ^
2 │

ℹ console.log() already prints a space between its arguments, so this space adds a second one.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the trailing space.

1 │ console.log("abc·",·"def");
│ -
console.error("abc", " def");
code-block.js:1:23 lint/nursery/noConsoleSpaces  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This argument starts with a space.

> 1 │ console.error("abc", " def");
│ ^
2 │

ℹ console.error() already prints a space between its arguments, so this space adds a second one.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the leading space.

1 │ console.error("abc",·"·def");
│ -
console.warn(`abc `, "def");
code-block.js:1:18 lint/nursery/noConsoleSpaces  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This argument ends with a space.

> 1 │ console.warn(`abc `, "def");
│ ^
2 │

ℹ console.warn() already prints a space between its arguments, so this space adds a second one.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the trailing space.

1 │ console.warn(`abc·`,·"def");
│ -
console.log("abc", "def");
console.log(" abc", "def ");
console.log("abc ", "def");
console.log("abc\t", "def");
console.log("abc", " ", "def");