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

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

Comments

Projects
None yet
3 participants
@andy-js

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)
}

And:

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

And:

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.

@dmitshur

This comment has been minimized.

Contributor

dmitshur commented Oct 29, 2018

Have you seen https://staticcheck.io/docs/gosimple#S1017? Is it not working for those snippets?

@andy-js

This comment has been minimized.

andy-js commented Oct 31, 2018

It does not complain about these snippets.

@dominikh

This comment has been minimized.

Owner

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