sindresorhus/eslint-plugin-unicorn
View on GitHubImprove `prefer-string-slice` autofix
Open
#2,505 opened on Dec 6, 2024
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?