Skip to content
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

[Issue 188] Add golangci-lint to subo #189

Merged
merged 12 commits into from
Feb 7, 2022
Merged

[Issue 188] Add golangci-lint to subo #189

merged 12 commits into from
Feb 7, 2022

Conversation

javorszky
Copy link
Contributor

Closes #188

@javorszky
Copy link
Contributor Author

So this one fails because of deadcode issues in the following three places:

Can y'all provide more context on what they are (supposed to be) used for? 🙂

@javorszky
Copy link
Contributor Author

Okay, so after a bit more digging

handlerData

There is no mention of anywhere else in the codebase. It is also not exported, so nothing that imports subo could potentially use it anyways.

I recommend removing it.

resourceFlag

This is not exported from the subo/command package, so scn can't use it. The usage of the property is not found in the entirety of my projects folder which has most of the suborbital repos cloned locally. This is truly not being used anywhere.

I recommend removing it.

updateFlag

This is being used in two other places within subo itself: here and here, but both places are commented out.

They were removed in this commit: 198ad21

This is not being used in any of the other projects either. Recommend removing and maybe adding a @todo comment?

@javorszky
Copy link
Contributor Author

I removed the unused pieces of code and created issues to track them:

The linter unparam also flagged up a bunch of issues in the docs builder. The function getCodeText received both the docTemplate and actionTemplate, but every caller passed in a constant which doesn't change.

Commit d664574 moves them out from being function arguments so the constants themselves can be used as args in whatever functionality needs them within the getCodeText function.

An alternative solution to the unparam, if we want to keep them as function arguments, is to write a test to the getCodeText function and pass in different templates for both and test that the text that comes out is what we expect to happen given the template we passed in. cc @denopink

@denopink
Copy link
Contributor

denopink commented Feb 7, 2022

@javorszky that totally works for me. We do need the params s.t. it could be used for other types of docs (requiring us to swap out the template/action).
When you say tests, are we thinking go unit tests? atm subo's tests are written and ran in GitHub (more like integration tests):

- name: Create project and runnable
run: |
export PATH=$PATH:$(go env GOPATH)/bin
git config --global init.defaultBranch main
subo create project smoketest
subo create runnable rs-test --lang rust --dir ./smoketest
subo create runnable swift-test --lang swift --dir ./smoketest
subo create runnable as-test --lang typescript --dir ./smoketest
subo create runnable tinygo-test --lang tinygo --dir ./smoketest

I can totally take care of the integration test for subo doc, but should we start introducing unit tests starting with getCodeText (to resolve the unparam)?

I'm all for it and I can take care of it, want me to create a separate ticket for that?

@javorszky
Copy link
Contributor Author

@denopink Ideally we should be unit testing every piece of code as well. I'm a fan of table driven tests, and the stretchify/assert package (this one: https://github.com/stretchr/testify), and mockery (https://github.com/vektra/mockery) if we need to create controllable mocks of interfaces. Let me know if I can help with any of it.

I tried creating a test function for the getCodeText function in the same directory in a file called docs_test.go, but as I'm not entirely familiar with all the pieces that the functions accept and what data looks like, I opted for the easier removal of arguments while still preserving the functionality. If you'd like I can push up a stub test file.

@javorszky
Copy link
Contributor Author

Also, thank you for the link to the integration tests 🙂

@denopink
Copy link
Contributor

denopink commented Feb 7, 2022

@javorszky I agree with just removing the params for now so it doesn't block this pr (it'll be just as easy to add them later).

@javorszky
Copy link
Contributor Author

@denopink awesome. I've opened #194 to track readding them with tests.

@denopink
Copy link
Contributor

denopink commented Feb 7, 2022

I haven't done table driven tests outside of basic tutorials, so I would love to help with that.
that includes interface mockeries as well!

@javorszky
Copy link
Contributor Author

All right, I'll put some documentation / examples together and share it here later today :)

Copy link
Contributor

@danielledeleo danielledeleo left a comment

Choose a reason for hiding this comment

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

Looks reasonable!

Makefile Show resolved Hide resolved
Copy link
Contributor

@danielledeleo danielledeleo left a comment

Choose a reason for hiding this comment

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

Approved

@javorszky javorszky merged commit f7bdee0 into main Feb 7, 2022
@javorszky javorszky deleted the issue-188 branch February 7, 2022 17:02
@javorszky javorszky mentioned this pull request Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(chore) Introduce golangci-lint rules
3 participants