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

implement struct_now_doc_hidden lint #587

Merged
merged 15 commits into from
Nov 28, 2023

Conversation

u9g
Copy link
Contributor

@u9g u9g commented Nov 25, 2023

Implements a lint to catch structs that are public and have just had #[doc(hidden)] added to them.

checks the first checkmark on #578 (comment)

@u9g u9g force-pushed the struct-now-hidden-lint branch from b7d1ec5 to 16b9a81 Compare November 25, 2023 04:53
@u9g u9g force-pushed the struct-now-hidden-lint branch from 16b9a81 to 4810db7 Compare November 25, 2023 04:53
Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

As always, good work! Will be happy to merge it.

I made a few minor suggestions and pointed out a few opportunities for improvement, if you're interested in making the code even better. Better tests don't seem that valuable when you're writing them, but they pay off massively by speeding up future development.

src/lints/struct_now_doc_hidden.ron Outdated Show resolved Hide resolved
src/lints/struct_now_doc_hidden.ron Outdated Show resolved Hide resolved
src/lints/struct_now_doc_hidden.ron Outdated Show resolved Hide resolved
src/lints/struct_now_doc_hidden.ron Outdated Show resolved Hide resolved
test_outputs/struct_now_doc_hidden.output.ron Outdated Show resolved Hide resolved
test_crates/struct_now_doc_hidden/old/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

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

These test cases are fine, but please do try to think of some more edge cases to test for. Simple lints like this are great for practicing those skills!

One trick to help you think of test cases that is called "mutation testing." Take the correct lint you've implemented, and intentionally introduce a bug into it: for example, delete a filter clause, change a filter operator, or add an unnecessary filter or edge traversal somewhere. Then run the tests and see if they catch the bug.

You know you have good test coverage when no matter what bug you introduce, the tests always catch it.

After some practice, you'll be able to run this process "in your head" without actually modifying the lint, and you'll be able to directly write sufficient test cases to catch most reasonable bugs. At the moment, I think there are several plausible ways to accidentally mis-implement this lint that I don't think our test suite as a whole will catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really good point, I went ahead and tried to get rid of some lines in the lint which actually ended up being optional entirely :)

In terms of tests, I added a bunch more tests that should make it a lot harder to mis-implement this rule.

@u9g u9g marked this pull request as draft November 28, 2023 05:00
@u9g u9g marked this pull request as ready for review November 28, 2023 05:17
@u9g u9g force-pushed the struct-now-hidden-lint branch from 541896c to ed0424e Compare November 28, 2023 05:20
}
}

#[doc(hide)] // shouldn't flag, it should be #[doc(hidden)] not #[doc(hide)]
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is a legal attribute, and it might break in the future. Here's the list of things the doc attribute supports and we probably should stick to it: https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html

I'd probably pick one of the other existing doc commands instead of using one that doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, I replaced it with a few valid doc attribute values.

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

Looks great, let's ship it 🚀

@obi1kenobi obi1kenobi merged commit 438f6d8 into obi1kenobi:main Nov 28, 2023
32 checks passed
@u9g u9g deleted the struct-now-hidden-lint branch November 28, 2023 19:03
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.

2 participants