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

CI: Add linter job to CI workflow #166

Merged

Conversation

TheodosiouTh
Copy link
Contributor

@TheodosiouTh TheodosiouTh commented Sep 4, 2021

Closes #165

@TheodosiouTh TheodosiouTh marked this pull request as draft September 4, 2021 22:02
@preslavmihaylov
Copy link
Owner

@TheodosiouTh it seems there are some more linting issues once I ran it locally.

Note that the github action you've just added doesn't run on this PR's CI so we have to make sure the check passes locally.

Pasting the output:
image

@TheodosiouTh
Copy link
Contributor Author

TheodosiouTh commented Sep 5, 2021

@preslavmihaylov Thank you for your input.
The pr is still a "work in progress" as I could not get it done yesterday. I will add WIP to the title and remove it when I am done.

@TheodosiouTh TheodosiouTh changed the title CI: Add linter job to CI workflow WIP: CI: Add linter job to CI workflow Sep 5, 2021
@preslavmihaylov
Copy link
Owner

Also, could you tweak the linter config a bit and include the golint and gofmt linters which are disabled by default.

Additionally, once you make that change, you can remove the gofmt step from the CI pipeline as its a subset of the step you're adding.

@preslavmihaylov
Copy link
Owner

Actually, we should use revive as it seems golint is deprecated

@TheodosiouTh
Copy link
Contributor Author

TheodosiouTh commented Sep 5, 2021

@preslavmihaylov I added revive and gofmt as you requested. I also removed the gofmt step and fixed all the linting errors and warnings.
Here is the final run of the workflow.
The tests fail but I don't know why (on this PR and when I run them locally they pass). I will keep looking at it to see what the issue is.

@TheodosiouTh
Copy link
Contributor Author

@preslavmihaylov I have checked the code again and I do not get why the make test would fail after all the tests pass. My guess is that the error occurs because of the environment variables. So I think this will not be an issue when we merge the PR.

@TheodosiouTh TheodosiouTh marked this pull request as ready for review September 5, 2021 10:29
@TheodosiouTh TheodosiouTh changed the title WIP: CI: Add linter job to CI workflow CI: Add linter job to CI workflow Sep 6, 2021
@TheodosiouTh
Copy link
Contributor Author

@preslavmihaylov I think the PR is ready for review, feel free to check it and give me feedback.

main.go Outdated
printTodoErrs(todoErrs, *format)
err = printTodoErrs(todoErrs, *format)
if err != nil {
logger.Info("Error when printing todo errors" + err.Error())
Copy link
Owner

Choose a reason for hiding this comment

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

This should be a panic as we should never get here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the code to panic if this point is reached during execution.

w.Write(issuetracker.BuildResponseFor(s.issueTracker, issue, s.issues[issue]))
_, err := w.Write(issuetracker.BuildResponseFor(s.issueTracker, issue, s.issues[issue]))
if err != nil {
logger.Info("Error " + err.Error() + " occured, when writing issuetracker response of issue:" + issue)
Copy link
Owner

Choose a reason for hiding this comment

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

This should be a panic as it should never happen

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the code to panic if this point is reached during execution.

todoErrCallback(todoErr)
err = todoErrCallback(todoErr)
if err != nil {
logger.Info("couldn't run todo error callback: " + err.Error())
Copy link
Owner

Choose a reason for hiding this comment

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

We should instead return fmt.Errorf("received error from todo err callback: %w", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the code according to your suggestion.

prev = curr
}

curr = next
next = 0
t.handleStateChange(filename, line, linecnt, prev, curr, next)
err := t.handleStateChange(filename, line, linecnt, prev, curr, next)
if err != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

These errors shouldn't be handled here as they are handled via the last return t.callbackErr.

Does the linter allow ignoring the error via _ = t.handleStateChange(...)?

Alternatively, you can change the signature of the function to not return an error and update it accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The linter does allow _ = t.handleStageChange(...) so I updated the code.

@TheodosiouTh
Copy link
Contributor Author

TheodosiouTh commented Sep 13, 2021

@preslavmihaylov I updated the code according to your suggestions.

Also, I found a logic bug in printTodoErrs, it was always returning an error even if an accepted format was provided (caused missing early return statements). I added the early return statements and changed the if-else if to a switch-case as I find the switch case easier to read. You can see the bug fix on this commit .

Feel free to check the rest of the changes.

Copy link
Owner

@preslavmihaylov preslavmihaylov left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

@preslavmihaylov preslavmihaylov merged commit ad0199a into preslavmihaylov:master Sep 18, 2021
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.

Add a go linter CI step
2 participants