unicorn/prefer-split-limit
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-split-limit": "error",
},
},
];const protocol = url.split(':')[0]; // Could be long URLconst [, filename] = path.split('/');const part = csvLine.split(',')[3];const protocol = url.split(':', 1)[0]; // More efficientconst [, filename] = path.split('/', 2);const part = csvLine.split(',', 4)[3];Examples from the ESLint documentation.
unicorn/prefer-split-limit
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-split-limit": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Enforce combining multiple single-character replacements into a single String#replaceAll() with a regular expression.
Prefer String#matchAll() over RegExp#exec() loops.
Prefer a single Array#some() or Array#every() with a combined predicate.
Prefer String#padStart() and String#padEnd() over manual string padding.
Prefer String#repeat() for repeated whitespace.