refactor: enables linter rule ST1003 'poorly chosen identifier'#69
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #69 +/- ##
=======================================
Coverage 63.00% 63.00%
=======================================
Files 210 210
Lines 22186 22186
=======================================
Hits 13978 13978
Misses 7116 7116
Partials 1092 1092 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
mwbrooks
left a comment
There was a problem hiding this comment.
I'm super sorry for the long read! Opening this PR in my browser brings my computer to a crawl. 🐜 There is no change to functionality, but I've made a few notes on a few minor naming decisions that I made.
| staticcheck: | ||
| checks: | ||
| - all | ||
| - '-ST1003' # disable rule 'Poorly chosen identifier' |
There was a problem hiding this comment.
note: This is the main change. I enabled this rule and then updates all linting errors.
| if err != nil { | ||
| return err | ||
| } | ||
| if manifestSource.Equals(config.MANIFEST_SOURCE_REMOTE) { |
There was a problem hiding this comment.
note: All capital constants are not allowed.
There was a problem hiding this comment.
This is a sensible rule IMO! While it's not as clear that these are constants at a glance, I do believe it'll encourage better patterns overall.
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{Auth: mockAuthTeam1}, nil) | ||
|
|
||
| // Mock valid session for team1 | ||
| cm.ApiInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ |
There was a problem hiding this comment.
note: acronyms should be capitalized - this is where most of the changes occurred because we consistently stuck with Api, Http, etc.
There was a problem hiding this comment.
I am so glad for this change. No longer will I have questions about these casings 👾
| User string "json:\"user,omitempty\"" | ||
| }{}, | ||
| }, | ||
| types.SUCCESS, |
There was a problem hiding this comment.
note: Since types.SUCCESS has no indication that it's a install success, I've prefixed all InstallState types to be InstallSuccess. I did the same for Permissions.
There was a problem hiding this comment.
While outside the scope of this PR, this makes me think certain types might be better suited for different packages.
The prefix makes it clear for now though!
There was a problem hiding this comment.
100% agree. I'd like to see the shared/types package removed entirely. Instead, the types/interfaces/etc should belong to the package they're intended for. It would also allow for self-documentation, such as install.Success.
zimeg
left a comment
There was a problem hiding this comment.
@mwbrooks These are wonderful improvements to the health of this codebase. It is so good to find the oddities a linter might catch!
I requested changes on this with a few notes. The first is important IMO, but the others I think are worth addressing before we can merge this:
- Within
sampleswe should not change the HTTP headers - reference - A few instances of
Cliwere found, butCLIto me is more correct - An instance of "CallBack" might be changed to "Callback" AFAICT
- A similar note on "metaData" versus "metadata" might be worth changing
All superb efforts on these changes, I can tell, but please let me know what you think or these suggestions. I am of course open to discussion 🙏 ✨
| if err != nil { | ||
| return err | ||
| } | ||
| if manifestSource.Equals(config.MANIFEST_SOURCE_REMOTE) { |
There was a problem hiding this comment.
This is a sensible rule IMO! While it's not as clear that these are constants at a glance, I do believe it'll encourage better patterns overall.
| appSelectMock.On("TeamAppSelectPrompt").Return(prompts.SelectedApp{Auth: mockAuthTeam1}, nil) | ||
|
|
||
| // Mock valid session for team1 | ||
| cm.ApiInterface.On("ValidateSession", mock.Anything, mock.Anything).Return(api.AuthSession{ |
There was a problem hiding this comment.
I am so glad for this change. No longer will I have questions about these casings 👾
| User string "json:\"user,omitempty\"" | ||
| }{}, | ||
| }, | ||
| types.SUCCESS, |
There was a problem hiding this comment.
While outside the scope of this PR, this makes me think certain types might be better suited for different packages.
The prefix makes it clear for now though!
| }, nil) | ||
| // Mock delete API call | ||
| cm.ApiInterface.On("DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID).Return(fmt.Errorf("something went terribly wrong")) | ||
| cm.APIInterface.On("DeleteApp", mock.Anything, mock.Anything, fakeDeployedApp.AppID).Return(fmt.Errorf("something went terribly wrong")) |
There was a problem hiding this comment.
I'm super curious if a later linter change might check specific formatting of errors 🔍
There was a problem hiding this comment.
Yes! ST1005 checks the formatting of an error. It requires the first letter to be lowercase, unless it's a proper Noun (e.g. Slack) and it cannot end with a period. The reason is that errors in Golang are often fmt.Sprintf("HTTP Request %s return an error: %s", req.URL, err) embedded in a message.
So far, I don't see too much emphasize on whether we use fmt.Errorf or other error methods.
|
|
||
| // Mock API calls | ||
| clientsMock.AuthInterface.On("ResolveApiHost", mock.Anything, mock.Anything, mock.Anything). | ||
| clientsMock.AuthInterface.On("ResolveAPIHost", mock.Anything, mock.Anything, mock.Anything). |
There was a problem hiding this comment.
String replacements seem like quite a tedious change! 🧵
| var SIXTY_FOUR_KB_STRING = string(make([]byte, (64*1024)+1)) | ||
| var FIVE_HUNDRED_TWELVE_KB_STRING = string(make([]byte, (512*1024)+1)) | ||
| var mockBoundaryString = "boundary-string" | ||
| var sixtyFourKBString = string(make([]byte, (64*1024)+1)) |
| } | ||
| req.Header.Set("Accept", "application/vnd.github+json") | ||
| req.Header.Set("X-GitHub-Api-Version", "2022-11-28") | ||
| req.Header.Set("X-GitHub-API-Version", "2022-11-28") |
There was a problem hiding this comment.
| req.Header.Set("X-GitHub-API-Version", "2022-11-28") | |
| req.Header.Set("X-GitHub-Api-Version", "2022-11-28") |
We might not want to make this change without an upstream fix 🐙
An option to exclude this entire string might be an option, but I am not certain...
https://docs.github.com/en/rest/about-the-rest-api/api-versions?apiVersion=2022-11-28
| // Internal dependencies | ||
|
|
||
| ApiInterface func() api.ApiInterface | ||
| APIInterface func() api.APIInterface |
There was a problem hiding this comment.
Since we now have just the interface implementation attached to clients I am almost wanting to rename this to API 😳
Of course, this would be a change better for another PR but I am also so curious about what you might think?
There was a problem hiding this comment.
Yes, please. I cringe every time I see a method called on an interface. I'll make a note for a follow-up PR. 📝
| ) | ||
|
|
||
| const metaDataUrl = "https://api.slack.com/slackcli/metadata.json" | ||
| const metaDataURL = "https://api.slack.com/slackcli/metadata.json" |
There was a problem hiding this comment.
| const metaDataURL = "https://api.slack.com/slackcli/metadata.json" | |
| const metadataURL = "https://api.slack.com/slackcli/metadata.json" |
Without referencing this exact comment, I believe we can lowercase most of this 🥀
There was a problem hiding this comment.
Great eyes! PR #71 updates metaData → metadata and MetaData → Metadata for easier review! 🌹
| // Test_CLI_Metadata_CheckForUpdate tests different responses from Slack CLI metadata. | ||
| func Test_CLI_Metadata_CheckForUpdate(t *testing.T) { | ||
| const metaDataUrl = "https://api.slack.com/slackcli/metadata.json" | ||
| const metaDataURL = "https://api.slack.com/slackcli/metadata.json" |
There was a problem hiding this comment.
| const metaDataURL = "https://api.slack.com/slackcli/metadata.json" | |
| const metadataURL = "https://api.slack.com/slackcli/metadata.json" |
Same change in a different scope 🦠
|
@zimeg Wow, I can't believe you carefully read through this entire PR! 🫨 Thank you for the thorough review, because the request header for I've created PR #71 to address your other suggestions, because the changes can get lost in this PR. I've left it as a draft until we merge this one, but it's ready to be opened! 😆 |
zimeg
left a comment
There was a problem hiding this comment.
@mwbrooks Heh it was a good excuse to read a lot of code 🤓
I'm glad these efforts might've paid off too! I find the browser UI to be unforgiving on these diff and stumbled upon an exciting tool called delta that deserves most of the credit:
At a glance, the changes of #71 are great follow ups! I agree that these are additional improvements that deserve separate comment. Thanks for keeping things tidy 📚
And this is also such an exciting PR to merge! I don't recall changes of this magnitude in recent commits, but these changes are still somehow so focused 🧠 ✨
|
Woo woo! Thanks for the final approval @zimeg! 🍎 I'm still super impressed that you found the GitHub Header issue :amaze:
Once merged, I'll open PR #71 and I've left a few comments on some open questions for us to decide! 🙇🏻 |
Summary
This pull request enables the Linter Rule ST1003 "Poorly Chosen Identifier" and updates all identifiers to match the new rule.
For the most part, this changing
Id → ID,Http → HTTP,SOME_CONSTANT → SomeConstant, etc.There is no change to functionality. 🚳
Reviewers
I'm so so so so sorry for the HUGE PR. I think this will be a common theme as we enable more of the default linter rules. 😆
Requirements