eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

`prefer-string-slice` bad autofix from `.substr()`

Open alex-kinokon opened this issue 4 months ago • 0 comments

let string = "::";

// Prefer `String#slice()` over `String#substr()`.
// eslint(unicorn/prefer-string-slice)
let eslintError = string.substr(-2, 2);
                  ^^^^^^^^^^^^^^^^^^^^
// After applying fix:
let fixed = string.slice(-2, -2 + 2);

eslintError // "::"
fixed // ""

// Uncaught AssertionError [ERR_ASSERTION]: '::' == ''
assert.equal(eslintError, fixed)

alex-kinokon avatar Feb 25 '24 00:02 alex-kinokon