# prefer-string-pad-start-end

Rule `unicorn/prefer-string-pad-start-end`. Prefer `String#padStart()` and `String#padEnd()` over manual string padding.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 9.9M weekly downloads of presets that enable it
- Trend: +28.3% last quarter
- Rank: #998 by reach, #1253 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-string-pad-start-end` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-string-pad-start-end.md) |

## Code examples

### Incorrect: the rule reports this

```js
const formatted = '*'.repeat(10 - name.length) + name;
```

```js
const padded = value + ' '.repeat(5 - value.length);
```

```js
const foo = ('*'.repeat(10) + bar).slice(-10);

// 💡
const foo = bar.padStart(10, '*');
```

### Correct: the rule accepts this

```js
const formatted = name.padStart(10, '*');
```

```js
const padded = value.padEnd(5, ' ');
```

```js
const col1 = 'ID'.padEnd(10);
const col2 = 'Name'.padEnd(20);
const col3 = 'Value'.padStart(10);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-string-pad-start-end": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-string-match-all](https://lintradar.dev/rules/unicorn/prefer-string-match-all.md): Prefer `String#matchAll()` over `RegExp#exec()` loops.
- [unicorn/prefer-string-repeat](https://lintradar.dev/rules/unicorn/prefer-string-repeat.md): Prefer `String#repeat()` for repeated whitespace.
- [unicorn/prefer-split-limit](https://lintradar.dev/rules/unicorn/prefer-split-limit.md): Prefer `String#split()` with a limit.
- [unicorn/prefer-switch](https://lintradar.dev/rules/unicorn/prefer-switch.md): Prefer `switch` over multiple `else-if`.
- [unicorn/prefer-single-replace](https://lintradar.dev/rules/unicorn/prefer-single-replace.md): Enforce combining multiple single-character replacements into a single `String#replaceAll()` with a regular expression.
- [unicorn/prefer-temporal-conversion](https://lintradar.dev/rules/unicorn/prefer-temporal-conversion.md): Prefer direct Temporal conversion methods.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-string-pad-start-end. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
