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

inlined nosec comments fails linting #9

Closed
bgehman opened this issue Mar 23, 2020 · 1 comment · Fixed by #10
Closed

inlined nosec comments fails linting #9

bgehman opened this issue Mar 23, 2020 · 1 comment · Fixed by #10

Comments

@bgehman
Copy link

bgehman commented Mar 23, 2020

This example, should pass (I hope):

test.go

package test

import (
	"crypto/hmac"
	"crypto/md5"  // #nosec
	"crypto/sha1" // #nosec
	"encoding/base64"
)

but it fails: $ impi --scheme stdThirdPartyLocal test.go

- Import group 0 is not sorted
-- Got:
crypto/hmac
 // #nosec
// #nosec
encoding/base64

-- Expected:
 // #nosec
// #nosec
crypto/hmac
encoding/base64

We need to inline the // #nosec on import statements (for gosec -- "safe" usage of md5/sha1 in out codebase). This utility is conflicting with gofumpt and gosec -- can't make all three happy simultaneously :)

I believe this utility should allow inline comments on import statements. From the Got/Expected output, it seems this linter is eating the imported package name and trying to sort based on the inline'd comment...

nick-jones pushed a commit to utilitywarehouse/impi that referenced this issue May 11, 2020
This should be more reliable than stripping out unwanted parts of
the import line. Most notably it resolves pavius#9

Note that I've not been able to verify this on an exhaustive set of
examples. Also note that there are still potential gotchas around
mutli line comments.. debatable whether or not those are worth
addressing (and definitely not wanting to cover in this PR, given
it has immediate benefits).
pavius pushed a commit that referenced this issue May 23, 2020
* Use go/scanner to extract import path

This should be more reliable than stripping out unwanted parts of
the import line. Most notably it resolves #9

Note that I've not been able to verify this on an exhaustive set of
examples. Also note that there are still potential gotchas around
mutli line comments.. debatable whether or not those are worth
addressing (and definitely not wanting to cover in this PR, given
it has immediate benefits).

* Improve error line; ensure a string is printed
@bgehman
Copy link
Author

bgehman commented May 24, 2020

Appreciate the fix @nick-jones 👍

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 a pull request may close this issue.

1 participant