sindresorhus/eslint-plugin-unicorn

Improve `prefer-string-slice` autofix

Open

#2.505 aberto em 6 de dez. de 2024

Ver no 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?

Guia do colaborador