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

Catch unnecessary strings.HasPrefix/strings.HasSuffix calls #359

andy-js opened this Issue Oct 29, 2018 · 3 comments


None yet
3 participants

andy-js commented Oct 29, 2018

This is a feature request more than a bug.

It would be nice of megacheck produced a warning for code that does:

if strings.HasPrefix(something, somethingElse) {
    something = strings.TrimPrefix(somethng, somethingElse)


if strings.HasSuffix(something, somethingElse) {
    something = strings.TrimSuffix(something, somethingElse)


if strings.Contains(something, somethingElse) {
    something = strings.Replace(something, somethingElse, replacement, -1)

There's probably a few more too, but I can't think of them right now.


This comment has been minimized.


dmitshur commented Oct 29, 2018

Have you seen Is it not working for those snippets?


This comment has been minimized.

andy-js commented Oct 31, 2018

It does not complain about these snippets.


This comment has been minimized.


dominikh commented Oct 31, 2018

S1017 is (currently) concerned with using predicates and manual slicing, not predicates and TrimPrefix/Suffix.

@dominikh dominikh added the new-check label Oct 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment