sindresorhus/eslint-plugin-unicorn
Rule proposal: `prefer-string-repeat`
Chiusa
#1708 aperta il 28 gen 2022
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
Description
There are legacy ways to repeat string, we should replace them with .repeat(), but this proposal is not about that. I want enforce .repeat() for unreadable repeating string literals.
Fail
const string = ' '; // I can't see how many are there
const string = 'unicorn unicorn unicorn unicorn';
Pass
const string = ' '.repeat(4);
const string = 'unicorn '.repeat(4).trim(); // This?
const string = Array.from({length: 4}).fill('unicorn').join(' '); // Or this?
const string = Array.from({length: 4}, () => 'unicorn').join(' '); // Or this?