-
Notifications
You must be signed in to change notification settings - Fork 10
Force assertion description rule #200
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
analyzer.go
Outdated
| AllowHaveLen0: false, | ||
| ForceExpectTo: false, | ||
| ForceSucceedForFuncs: false, | ||
| ForceOptionalDescription: false, |
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 find force-optional a bit confusing. I mean, if we're forcing it, it's not optional anymore. WDYT about something like "ForceAseertionDescription", or similar??
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.
yep, that's better name, will change it
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.
@bootuz - thank you so much for this PR. It helps a lot. It looks good in general. I added several minor inline comments.
As a general comment, I think we can come with better naming than optional description. I would go with something like assertion description or something like that. This comment is about naming in general, e.g. variable, type and file names.
Another comment is maybe for the future. We had a request, long time ago, from @pohly , about forcing BeTrue/BeFalse ==> BeTrueBecause/BeFalseBecause. This is very similar to this PR. It's a bit more complicated to implement, though.
And last thing, this PR reminds me about checking the case of using fmt.Sprinf in the description, while the assertion description mechanism already supports it; e.g.
Expect(x).To(Equal(y), fmt.Sprintf("%v must be equal to %v", x, y))Should be
Expect(x).To(Equal(y), "%v must be equal to %v", x, y)We can add a new rule to force it. Not in this PR, of course.
|
@bootuz , please also update the README.md file with the new rule, as well as the cli documentation (the cli documentation is in doc.go file in the project root). |
Does that still apply format checking, as in I don't think the normal linter for format strings does it because it cannot detect that the Without it, I am reluctant to discourage the use of |
The formatting linter (not sure about the name) does not recognizes issues here, as you said. But maybe they expose a function(s) we can use. Worth to check it. |
|
@bootuz, few more things. Did you go over the checklist in the description? Only one task is marked as done. Spiking abput the pr description, please edit it to set issue number (#199), in order to link between the issue and the implementation. It will also auto close the issue when the pr will be mereged. As said above, we still need to add a not-dot-import test file to the testdata. And finally, the devision to commits seems random. Please either squash them into one commit, or let each commit do specific part of the change. No need to see the working process here, for example, renaming a file that was added in earlier commit within the same pr. Instead, I would expect that the file will be added in one commit, with the final name. |
ef63513 to
de1bcdb
Compare
to enforce assertion descriptions
This commit implements a new linting rule that
enforces the use of assertion descriptions in
Ginkgo/Gomega tests when enabled via the
--force-assertion-description flag.
Changes:
- Add AssertionDescriptionRule to detect missing
assertion descriptions
- Support both sync (Expect) and async (Eventually,
Consistently) assertions.
- Comprehensive test coverage including dot imports,
named imports, and mixed cases.
- Documentation updates in README.md and doc.go
- Rule is disabled by default, enabled via CLI.
|
@nunnatsa Thanks for your swift responses. I think I fixed all the comments. If there's anything else, just let me know! |
|
Looks great. Thanks again. I just noticed that the pr description text is from the template - anf includes the instructions for the contributor ... Please remove it (2 or 3 places) and add a short explanation of what this pr does (maybe copy parts of the doc?) |
|
@nunnatsa one more question. |
3 steps: first, I'll need to release a new version of the linter, then golangci-lint will automatically adopt it (I'll maybe also need to add the new flag there). After this change is merged in golangci-lint repo, we'll have to wait for the next version release. |
|
@bootuz - just released v0.20.0 |
Description
This PR implements a new linting rule that enforces the use of assertion descriptions in Ginkgo/Gomega tests when enabled via the
--force-assertion-descriptionflag.Changes:
Fixes #199
Type of change
How Has This Been Tested?
Checklist:
make goimports@nunnatsa