-
Notifications
You must be signed in to change notification settings - Fork 24
refactor: enable linter rule ST1016 for 'consistent method receiver names' #86
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #86 +/- ##
==========================================
+ Coverage 63.17% 63.19% +0.01%
==========================================
Files 210 210
Lines 22186 22186
==========================================
+ Hits 14017 14020 +3
+ Misses 7082 7081 -1
+ Partials 1087 1085 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // auth or an app that corresponds. E.g. when you are comparing to --team flags | ||
| func (t *TeamApps) authOrAppTeamDomain() string { | ||
| if t.Auth.TeamDomain != "" && (t.Auth.TeamID == t.Hosted.App.TeamID || t.Auth.TeamID == t.Local.App.TeamID) { | ||
| func (apps *TeamApps) authOrAppTeamDomain() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The apps receiver name is used the majority of the time. However, I noticed that Golang encourages short, 1-or-2 letter receiver names. In this case a, t, or ta would be more appropriate. However, this file is quite long and apps reads well. So I leaned toward less changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In implementations having a more complete variable name seems better to me. Thanks for linking these docs though. It makes for interesting considerations... 🎁
The name need not be as descriptive as that of a method argument, as its role is obvious and serves no documentary purpose.
Sometimes I find it a hassle to search for single letter variables FWIW but this is the most interesting consideration. Perhaps I am needing to read more go 🙏 ✨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: Wow I find the change that follows this in os.go makes sense as a single letter. So much to consider.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I'm with you. Sometimes the single letter just doesn't feel right. For TeamApps, maybe rethinking the struct's name (or purpose) will help? But, overall I'm cool with apps :)
zimeg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mwbrooks Once more a wonderful PR to improve the health of code 🏥 ✨
These are appreciated and it's motivating to find a few of these landing so often - I'm feeling better and better about the code and hadn't even realized these linting rules were broken before the latest golangci-lint updates 🔍
| - '-QF1004' # disable rule 'Use strings.ReplaceAll instead of strings.Replace' | ||
| - '-QF1008' # disable rule 'Omit embedded fields from selector' | ||
| - '-QF1011' # disable rule 'Omit redundant type from variable declaration' | ||
| - '-ST1016' # disable rule 'Use consistent method receiver names' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🪓 ✨
| // SetExitCode sets the desired exit code in a thread-safe way | ||
| func (io *IOStreamsMock) SetExitCode(code ExitCode) { | ||
| atomic.StoreInt32((*int32)(&io.exitCode), int32(code)) | ||
| func (m *IOStreamsMock) SetExitCode(code ExitCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧪 Nice! I like mock being m if this is what's found elsewhere!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, m seems to be a common receiver name for mocks. Makes sense to me and keeps it consistent.
| // auth or an app that corresponds. E.g. when you are comparing to --team flags | ||
| func (t *TeamApps) authOrAppTeamDomain() string { | ||
| if t.Auth.TeamDomain != "" && (t.Auth.TeamID == t.Hosted.App.TeamID || t.Auth.TeamID == t.Local.App.TeamID) { | ||
| func (apps *TeamApps) authOrAppTeamDomain() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In implementations having a more complete variable name seems better to me. Thanks for linking these docs though. It makes for interesting considerations... 🎁
The name need not be as descriptive as that of a method argument, as its role is obvious and serves no documentary purpose.
Sometimes I find it a hassle to search for single letter variables FWIW but this is the most interesting consideration. Perhaps I am needing to read more go 🙏 ✨
| // auth or an app that corresponds. E.g. when you are comparing to --team flags | ||
| func (t *TeamApps) authOrAppTeamDomain() string { | ||
| if t.Auth.TeamDomain != "" && (t.Auth.TeamID == t.Hosted.App.TeamID || t.Auth.TeamID == t.Local.App.TeamID) { | ||
| func (apps *TeamApps) authOrAppTeamDomain() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: Wow I find the change that follows this in os.go makes sense as a single letter. So much to consider.
|
Thanks for the review @zimeg! While we don't have to take every linting rule to heart, it definitely helps to keep the code more consistent and readable. For the most part, I think we're already following the short receiver names, so I don't think we'll have trouble keeping with it! 🚀 |
Summary
This pull request enables the linter staticcheck rule ST1016: 'Use consistent method receiver names'.
For each, I choose the receiver name that was used the majority of the time.
Requirements