8000 feat(code-quality): add golangci-lint to CI and lint project by darkweak · Pull Request #245 · symfony-cli/symfony-cli · GitHub
[go: up one dir, main page]

Skip to content

feat(code-quality): add golangci-lint to CI and lint project #245

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

Closed
wants to merge 6 commits into from
Closed

Conversation

darkweak
Copy link

Hello, this PR is here to have a better code quality/code style using golangci-lint. It adds the CI job to ensure every other PR will be as well written as possible.

Copy link
Member
@tucksaun tucksaun 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 @darkweak for working on this 🙏
This has been on my mind for a while 👍

Just a couple of thoughts:

  • I believe we should tweak the settings to match our use case though.
    For example, unusedresult should probably be disabled (at least for several functions from terminal).

  • We should also take the opportunity to some of those issues instead of masking them (not checking errors for example) which makes me believe it would be better to add the configuration in this PR, maybe fix the obvious issues (ioutil-> os for example) and fix the other issues with other PRs.

any thought @fabpot ?

@darkweak
Copy link
Author

I believe we should tweak the settings to match our use case though.
For example, unusedresult should probably be disabled (at least for several functions from terminal).

IMHO if that's unused that should be removed 😄

We should also take the opportunity to some of those issues instead of masking them

That's the first iteration and was to implement asap the golangci-lint. I plan to add some error handling (for those I just disabled checks).

@darkweak darkweak requested a review from tucksaun December 24, 2022 07:13
@tucksaun
Copy link
Member

IMHO if that's unused that should be removed 😄

I'm not referring to unused but unused results that are not always useful and I personally find having tons of _, _ = unreadable (see all the changes for functions as terminal.Printfln)

That's the first iteration and was to implement asap the golangci-lint. I plan to add some error handling (for those I just disabled checks).

That is the reason why I mentioned enabling only-new-issues. By doing so we can more quickly merge this PR that would only add configuration and most obvious fix and then we can fix other issues in dedicated PRs

@darkweak
Copy link
Author

Oh sorry, I misunderstood what you said then, thank you for your explanations.
I'll try to find time to update the PR during this week-end 👍

@darkweak
Copy link
Author

@tucksaun the PR is ready.

@darkweak
Copy link
Author

@fabpot @tucksaun any update?

@darkweak
Copy link
Author

Ping @tucksaun

Copy link
Member
@tucksaun tucksaun left a comment

Choose a reason for hiding this comment

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

I'm stopping here because reviewing this kind of PR is complicated 😖.
Also, the PR needs rebasing.
Would you reconsider opening a new PR with only the configuration and then creating one PR per topic fixed (one by one)?
That would help a lot IMO as they are a couple of fixes that could be merged quickly then.

# We already make sure your own packages wrap errors properly
- github.com/symfony-cli/*
errcheck:
ignore: github.com/symfony-cli/terminal:^(Ep|P)rint
Copy link
Member

Choose a reason for hiding this comment

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

missing newline at the end of the file

Comment on lines +38 to +40
if err := os.Chdir(b.Dir); err != nil {
return errors.WithStack(err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if err := os.Chdir(b.Dir); err != nil {
return errors.WithStack(err)
}
if err := errors.WithStack(os.Chdir(b.Dir)); err != nil {
return err
}

I'm not saying we have to do it, but we can do it when there's only a single return value, this also better preserve stack traces IIRC

}
} else {
terminal.Println("Skipped for this step")
}

printBanner("<comment>[WEB]</> Stopping the Local Web Server", b.Debug)
executeCommand([]string{"symfony", "server:stop"}, b.Debug, true, nil)
Copy link
Member

Choose a reason for hiding this comment

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

I would tend to think that @fabpot deliberately skip this one

}

printBanner("<comment>[SPA]</> Stopping the Local Web Server", b.Debug)
if _, err := os.Stat(filepath.Join(b.Dir, "spa")); err == nil {
executeCommand([]string{"symfony", "server:stop", "--dir", filepath.Join(b.Dir, "spa")}, b.Debug, true, nil)
Copy link
Member

Choose a reason for hiding this comment

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

same

@@ -40,16 +41,16 @@ var localProxyAttachDomainCmd = &console.Command{
Action: func(c *console.Context) error {
projectDir, err := getProjectDir(c.String("dir"))
if err != nil {
return err
return errors.WithStack(err)
Copy link
Member

Choose a reason for hiding this comment

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

this one should be wrapped in the parent function

}

homeDir := util.GetHomeDir()
config, err := proxy.Load(homeDir)
if err != nil {
return err
return errors.WithStack(err)
Copy link
Member

Choose a reason for hiding this comment

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

same

@@ -68,7 +68,7 @@ var localProxyStartCmd = &console.Command{
}
if err := reexec.Background(varDir); err != nil {
if _, isExitCoder := err.(console.ExitCoder); isExitCoder {
return err
return errors.WithStack(err)
Copy link
Member

Choose a reason for hiding this comment

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

IIRC console.ExitCoder errors must not be wrapped as we have special handling for them in symfony-cli/console

@darkweak
Copy link
Author

@tucksaun I'll open some PRs to review easier. I'll start with one that add only golangci-lint in the project with the given configuration without noises. The PR should be ready this evening. ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0