Skip to content

Add ifshort linter #1587

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

Merged
merged 3 commits into from
Jan 20, 2021
Merged

Add ifshort linter #1587

merged 3 commits into from
Jan 20, 2021

Conversation

esimonov
Copy link
Contributor

@esimonov esimonov commented Dec 28, 2020

ifshort is a linter for checking that the short syntax for if-statements is used whenever possible. For example, it will tell that the variables ok and err are unnecessarily defined outside the scope of the if-statements - the only places where they are referred to:

func someFunc(k string, m map[string]interface{}) {
	_, ok := m[k]
	if !ok { // could be `if _, ok := m[k]; !ok`
		return
	}

	err := otherFunc1()
	if err != nil { // could be `if err := otherFunc1(); err != nil`
		otherFunc2(err)
	}
}

At the same time, it won't complain about the variables that actually require to be present in a wider scope.

https://github.com/esimonov/ifshort

@boring-cyborg
Copy link

boring-cyborg bot commented Dec 28, 2020

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Dec 28, 2020

CLA assistant check
All committers have signed the CLA.

@ldez ldez added the linter: new Support new linter label Dec 28, 2020
@esimonov

This comment has been minimized.

@ldez

This comment has been minimized.

@esimonov

This comment has been minimized.

@SVilgelm

This comment has been minimized.

@SVilgelm

This comment has been minimized.

@esimonov

This comment has been minimized.

@ldez
Copy link
Member

ldez commented Jan 15, 2021

Hello,

have you thought about using tag/version?

There are several advantages:

  • it's more "Go module idiomatic"
  • that allow the dependabot to update automatically golangci-lint when you release a new version

@ldez ldez added the feedback required Requires additional feedback label Jan 15, 2021
@esimonov
Copy link
Contributor Author

@ldez Thank you for your suggestion. I updated my PR.

Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldez ldez merged commit 750309d into golangci:master Jan 20, 2021
@golangci-automator
Copy link

Hey, @esimonov — we just merged your PR to golangci-lint! 🔥🚀

golangci-lint is built by awesome people like you. Let us say “thanks”: we just invited you to join the GolangCI organization on GitHub.
This will add you to our team of maintainers. Accept the invite by visiting this link.

By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.
More information about contributing is here.

Thanks again!

ashanbrown pushed a commit to ashanbrown/golangci-lint that referenced this pull request Feb 20, 2021
@ldez ldez added this to the v1.36 milestone Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feedback required Requires additional feedback linter: new Support new linter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants