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

Check unvendored version of package paths for ignore parameter #109

Merged
merged 1 commit into from Sep 17, 2016

Conversation

nmiyake
Copy link
Contributor

@nmiyake nmiyake commented Sep 15, 2016

Fixes #102

Copy link
Contributor Author

@nmiyake nmiyake left a comment

Choose a reason for hiding this comment

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

Explanation of thought process and a few comments on my own PR for the issue

// does not represent a vendored path). The second return value is true if the provided package was vendored, false
// otherwise.
func nonVendoredPkgPath(pkgPath string) (string, bool) {
lastVendorIndex := strings.LastIndex(pkgPath, "/vendor/")
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 think the path-based approach here is reasonable given that core Go code does something similar: https://github.com/golang/go/blob/81dfcba331f43bd14c8933eca83c433e53cb7b55/src/cmd/go/build.go#L2324

The other approach would be to iterate over all of the v.ignore keys and try to import them and see if they resolve to a vendored package, but this requires more information (need a source directory from which to try to resolve import), so I think this approach is reasonable. However, would be happy to hear other feedback.

// if current package being considered is vendored, check to see if it should be ignored based
// on the unvendored path.
if nonVendoredPkg, ok := nonVendoredPkgPath(pkg.Path()); ok {
if re, ok := v.ignore[nonVendoredPkg]; ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding this as a second check so that any existing ignore entries that use fully qualified vendor paths will still work just as they did before. This extra check basically just "unvendors" the package being considered and uses the ignore entry there.

I think this is the correct behavior and reflects the intent of #102.


func TestIgnore(t *testing.T) {
// copy testvendor directory into current directory for test
if err := os.MkdirAll("testvendor", 0755); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Writing out files directly in test because it's not possible to test vendor behavior within the testdata directory because Go hard-codes behavior that doesn't resolve vendored imports within a testdata directory.

@nmiyake nmiyake force-pushed the fix102 branch 2 times, most recently from 1b6dc98 to fbf65d9 Compare September 15, 2016 06:08
Copy link
Owner

@kisielk kisielk left a comment

Choose a reason for hiding this comment

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

Just some proposed style changes.

It would be good to have a few people test this to see if it works as expected before merging.

"testing"
)

const testPackage = "github.com/kisielk/errcheck/testdata"
const (
Copy link
Owner

Choose a reason for hiding this comment

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

Just as a matter of style, I don't think the const blocks are necessary

@@ -83,6 +90,94 @@ func TestAll(t *testing.T) {
test(t, CheckAsserts|CheckBlank)
}

const (
Copy link
Owner

Choose a reason for hiding this comment

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

ditto here, since it's just one constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually 2 constants here (testVendorMain and testLog), but don't feel strongly, so removed block.

t.SkipNow()
}

// copy testvendor directory into current directory for test
Copy link
Owner

Choose a reason for hiding this comment

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

I would prefer to use ioutil.TempDir for this.

@nmiyake
Copy link
Contributor Author

nmiyake commented Sep 16, 2016

Updated PR to address feedback.

@nmiyake
Copy link
Contributor Author

nmiyake commented Sep 16, 2016

Thanks for the review! Makes sense to have others test as well -- is there an existing process for this? Happy to try to do anything to help this out on my end.

@kisielk
Copy link
Owner

kisielk commented Sep 16, 2016

Well, you've already pinged a couple of people, hopefully they can try out the changes and give some feedback 👍

@nmiyake
Copy link
Contributor Author

nmiyake commented Sep 17, 2016

OK, I tested this on the the 2 major projects that @bmoylan and I work on, and also tried it on the project that @dtolnay works on (all of these projects have pre-existing verification scripts that use errcheck invoked with specific -ignore parameters). On all 3 of these projects, confirmed that:

  • The existing -ignore invocation for the projects that specify full vendor paths still works
  • Changing the -ignore invocations to be the non-vendored paths of the packages works

Based on these tests and the logic of the change, I'm pretty confident that it should work as intended.

@kisielk kisielk merged commit 1e7eb64 into kisielk:master Sep 17, 2016
@kisielk
Copy link
Owner

kisielk commented Sep 17, 2016

Sounds good, let's see how it goes :)

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.

None yet

2 participants