Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer-string-slice bad autofix from .substr() #2291

Open
alex-kinokon opened this issue Feb 25, 2024 · 0 comments
Open

prefer-string-slice bad autofix from .substr() #2291

alex-kinokon opened this issue Feb 25, 2024 · 0 comments
Labels

Comments

@alex-kinokon
Copy link

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)
@fregante fregante changed the title prefer-string-slice fix produces false result from substr prefer-string-slice bad autofix from .substr() Feb 29, 2024
@fregante fregante added the bug label Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants