-
Notifications
You must be signed in to change notification settings - Fork 298
fix(#1363): package-comments ignores //nolint directives #1366
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
Conversation
…ss, factors out common code from testRule and testRuleOnDir
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of changes 😱
Yes... I think I hit a bug in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say OK, but I cannot swear I reviewed everything
Thanks! The PR seems "complicated" but it does very few things:
|
Thanks for the details, I assumed it was something like that, yes If you plan to squash your commits into one, what you wrote could be used as a good commit message |
rule/package_comments.go
Outdated
return true | ||
} | ||
|
||
return commentGroup.Text() == "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be one-liner:
return commentGroup.Text() == "" | |
return commentGroup == nil || commentGroup.Text() == "" |
@@ -0,0 +1,17 @@ | |||
package test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Tests for
package-comments
is inside thetestdata/golint
directory. - I assume we can add simply
testdata/golint/package_doc7.go
instead of modifying test suite:
//nolint:dupl
package foo
Before the fix:
$ go test ./...
? github.com/mgechev/revive [no test files]
ok github.com/mgechev/revive/cli 0.504s
ok github.com/mgechev/revive/config 1.181s
ok github.com/mgechev/revive/formatter 0.855s
? github.com/mgechev/revive/internal/astutils [no test files]
? github.com/mgechev/revive/internal/ifelse [no test files]
? github.com/mgechev/revive/internal/typeparams [no test files]
ok github.com/mgechev/revive/lint 0.674s
ok github.com/mgechev/revive/logging 0.315s
ok github.com/mgechev/revive/revivelib 1.050s
ok github.com/mgechev/revive/rule 1.498s
--- FAIL: TestAll (0.90s)
--- FAIL: TestAll/package_doc7.go (0.00s)
golint_test.go:71: Unexpected problem at package_doc7.go:1: package comment should be of the form "Package foo ..."
FAIL
FAIL github.com/mgechev/revive/test 2.314s
FAIL
After applying the fix:
$ go test ./...
? github.com/mgechev/revive [no test files]
ok github.com/mgechev/revive/cli (cached)
ok github.com/mgechev/revive/config (cached)
ok github.com/mgechev/revive/formatter (cached)
? github.com/mgechev/revive/internal/astutils [no test files]
? github.com/mgechev/revive/internal/ifelse [no test files]
? github.com/mgechev/revive/internal/typeparams [no test files]
ok github.com/mgechev/revive/lint (cached)
ok github.com/mgechev/revive/logging (cached)
ok github.com/mgechev/revive/revivelib 0.326s
ok github.com/mgechev/revive/rule (cached)
ok github.com/mgechev/revive/test 1.407s
See my example in #1371
Closes #1363
Root cause of the bug: when checking package comments, the rule doesn't skip directive-comments at the right place.