Skip to content

Move errcheck package out of internal#185

Merged
kisielk merged 25 commits into
masterfrom
publish-api
Dec 10, 2020
Merged

Move errcheck package out of internal#185
kisielk merged 25 commits into
masterfrom
publish-api

Conversation

@echlebek
Copy link
Copy Markdown
Collaborator

@echlebek echlebek commented Aug 2, 2020

Allows using errcheck as a library. This will be more feasible now that we have versioning.

Signed-off-by: Eric Chlebek eric@sensu.io

Signed-off-by: Eric Chlebek <eric@sensu.io>
@echlebek echlebek requested a review from kisielk August 2, 2020 05:30
@echlebek echlebek self-assigned this Aug 2, 2020
Eric Chlebek added 2 commits August 3, 2020 21:09
Signed-off-by: Eric Chlebek <eric@sensu.io>
Signed-off-by: Eric Chlebek <eric@sensu.io>
Comment thread errcheck/errcheck.go Outdated
@SVilgelm
Copy link
Copy Markdown

@kisielk @echlebek So, I have tested it with golangci-lint, everything works. Here is the PR: golangci/golangci-lint#1319

But I see a huge degradation in the performance due to loading the packages twice. @echlebek Could you split the CheckPackages function to two but moving this code: https://github.com/kisielk/errcheck/blob/master/internal/errcheck/errcheck.go#L241-L260 to a separate function. Or I can raise a PR to this branch with the changes

@kisielk
Copy link
Copy Markdown
Owner

kisielk commented Aug 18, 2020

@SVilgelm glad to hear it works. I think we'll be making some changes to the API as in the comments above, let me know what you think.

As far as the performance aspect, I think CheckPackages could probably be renamed to CheckPaths and then we could add a CheckPackage(*packages.Package) method would be called in that inner loop you referenced. Would that address the performance concerns?

@echlebek
Copy link
Copy Markdown
Collaborator Author

@dtcaciuc do you want to make a PR to this branch with the proposed changes?

@echlebek
Copy link
Copy Markdown
Collaborator Author

@SVilgelm @kisielk CheckPackage(*packages.Package) makes sense to me.

@SVilgelm
Copy link
Copy Markdown

SVilgelm commented Aug 19, 2020

hmm, I just found that you are using the *packages.Package when golangci-lint uses *types.Package, so need more time to figure out what to do with it

@SVilgelm
Copy link
Copy Markdown

found a workaround, @echlebek I will raise a pr to this branch with my changes

@SVilgelm
Copy link
Copy Markdown

@echlebek @kisielk Here is the PR for this branch: #188
I crate CheckPackage function and move some code from checkPaths to separated functions, like updating Ignore wit non verdure packages and implement isGoMod helper to use instead of go111module variable

@SVilgelm
Copy link
Copy Markdown

I understand, that you are going to change the configuration, but may I ask you to do it in separate pull request? That changes are backward incompatible and I'm not sure we can easy incorporate new config structure in golangci-lint, but will see

@kisielk
Copy link
Copy Markdown
Owner

kisielk commented Aug 19, 2020

I understand that, but I don't really want to mKe the API public and then immediately change it afterwards. Apart from naming it shouldn't be that different from the current one so I don't really see why it would be any more difficult to integrate.

@SVilgelm
Copy link
Copy Markdown

ok, if only naming, then probably we can keep old names in current release and update them in v2 of golangci-lint

Making the api public is not backward incompatible, but changing the config structure is

@echlebek
Copy link
Copy Markdown
Collaborator Author

I've merged @SVilgelm's PR to this branch. We can move forward from there.

I'd like to merge @dtcaciuc's branch next. I want to make sure I understand all the configuration changes fully first.

Eric Chlebek and others added 4 commits August 30, 2020 23:38
I've taken the liberty of modifying the incoming changes somewhat.
The UpdateNonVendoredIgnore function has been renamed, unexported,
and made to return data instead of setting it.
Independent of whether go mod is used or not, simply
strip off vendor directory prefix from both imports
and excludes if it was found.
Simplify vendored package resolution.
@echlebek
Copy link
Copy Markdown
Collaborator Author

I've merged Dimitri's PR and I've tagged this branch at v1.5.0-alpha.

The errcheck project now has a stable API, in the errcheck package, that can be used by linter aggregators. We don't expect to break this API until v2, once it is published as v1.5.0.

The errcheck package stutters a bit, because it is nested in the top level directory of the repository. Since errcheck was originally published as a tool, with package main in the repo root, we felt that it would be a breaking change to move the API to the repository root, even if it would result in a nicer looking import path.

The errcheck tool remains the same as before, with no functionality removed.

I've reviewed the godoc for the API and it looks fairly usable. More importantly, it is fairly minimal, which should make future expansions less troublesome.

@echlebek
Copy link
Copy Markdown
Collaborator Author

I've been doing a bit more work on this.

We may want to revisit the signature of CheckPackage. It returns []UncheckedErrors, but it should probably just return error, and expect the user to do a type assertion for more information. Any thoughts on this?

I'm about to make a PR to this branch that removes CheckPaths, and reimplement what it does in package main, using CheckPackage. This will shrink the API surface even more. Since CheckPaths goes away, LoadPackages appears, giving the API user an simple way to load a bunch of packages for errcheck checking.

@kisielk
Copy link
Copy Markdown
Owner

kisielk commented Oct 24, 2020

Probably would be better to make a Result struct that contains []UncheckedErrors and then change the return type to (Result, error). The error return could be used to return any actual errors from the checking process. Technically the failed checks are not "errors" in the usual sense of a Go program.

@echlebek
Copy link
Copy Markdown
Collaborator Author

I've encountered some difficulty with the tests while refactoring. They're tightly coupled to CheckPaths so they'll need some refactoring too.

@kisielk
Copy link
Copy Markdown
Owner

kisielk commented Oct 25, 2020

Maybe just a helper function for the tests would do the job?

Eric Chlebek and others added 7 commits October 25, 2020 14:06
This commit removes the CheckPaths method of Checker. It also
adds a method called LoadPackages, and exports more of the logic
that errcheck uses to do aggregation.

The UncheckedErrors type has been renamed to Result, and the
CheckPackage function now returns a *Result instead of
[]UncheckedErrors.

Signed-off-by: Eric Chlebek <eric@sensu.io>
Signed-off-by: Eric Chlebek <eric@sensu.io>
Signed-off-by: Eric Chlebek <eric@sensu.io>
Signed-off-by: Eric Chlebek <eric@sensu.io>
As suggested by dtcaciuc

Signed-off-by: Eric Chlebek <eric@sensu.io>
Signed-off-by: Eric Chlebek <eric@sensu.io>
@leventov
Copy link
Copy Markdown

leventov commented Dec 3, 2020

Is there anything left to do before this PR could be merged?

Eric Chlebek added 2 commits December 9, 2020 22:25
Signed-off-by: Eric Chlebek <eric@sensu.io>
Signed-off-by: Eric Chlebek <eric@sensu.io>
@kisielk kisielk merged commit bc93895 into master Dec 10, 2020
leventov added a commit to leventov/golangci-lint that referenced this pull request Dec 27, 2020
ldez pushed a commit to golangci/golangci-lint that referenced this pull request Dec 27, 2020
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.

5 participants