unicorn/no-console-spaces
Disallow spaces at the edges of strings where console.log() already adds one
fixable
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#
example.js3 problems
console.log("Total: Do not use trailing spaces with console.log parameters", total);
console.error(path, " was not foundDo not use leading spaces with console.error parameters");
console.info(`Saved ${count} files `Do not use trailing spaces with console.info parameters, "in", elapsed);example.jsNo problems
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:
example.jsNo problems
console.log(" Total:", total);
console.log("Done ");