sindresorhus/eslint-plugin-unicorn

Improve `prefer-string-slice` autofix

Open

#2,505 opened on Dec 6, 2024

View on GitHub
 (4 comments) (1 reaction) (0 assignees)JavaScript (5,022 stars) (468 forks)user submission
enhancementhelp wanted

Description

unicorn/prefer-string-slice is good when all the parameters are constants, or when there is only one parameter. But when there are two parameters and they're variables, the autofixes will do things like this:

editsummary = editsummary.substr(0, editsummary.length - 2); // remove trailing comma -> editsummary = editsummary.slice(0, Math.max(0, editsummary.length - 2)); // remove trailing comma

I find the Math.max pretty hard to read. I'd prefer that it not autofix that particular sub-pattern. Any interest in adding an option to this rule so that it can be configured to skip that particular sub-pattern when autofixing?

Contributor guide

Improve `prefer-string-slice` autofix · sindresorhus/eslint-plugin-unicorn#2505 | Good First Issue