sindresorhus/eslint-plugin-unicorn

Improve `prefer-string-slice` autofix

Open

#2,505 创建于 2024年12月6日

在 GitHub 查看
 (4 评论) (1 反应) (0 负责人)JavaScript (5,022 star) (468 fork)user submission
enhancementhelp wanted

描述

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?

贡献者指南

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