unicorn/prefer-string-repeat
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-string-repeat": "error",
},
},
];const indentation = ' ';const padding = '\t\t\t';const spaces = '\u2003\u2003\u2003';const indentation = ' '.repeat(4);const padding = '\t'.repeat(3);const spaces = '\u2003'.repeat(3);Examples from the ESLint documentation.
unicorn/prefer-string-repeat
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-string-repeat": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer String#padStart() and String#padEnd() over manual string padding.
Prefer String#matchAll() over RegExp#exec() loops.
Prefer direct Temporal conversion methods.
Prefer using Element#toggleAttribute() to toggle attributes.