-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
One macro to include lints #204
One macro to include lints #204
Conversation
src/query.rs
Outdated
#[test] | ||
fn $name() { | ||
tests::check_query_execution(stringify!($name)) | ||
} |
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.
Doesn't this put this test function outside of mod tests
and into the regular module that always gets compiled, even in non-test builds?
I like the general idea of having one place to add lints, but I don't think we want to add test-only code that needs to be compiled in non-test builds too.
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.
Oh ok, I didn't know what the #[cfg(test)]
does.
But then, I don't know how to write this code in the #[cfg(test)] mod tests
module. Rust doesn't allow redefining/extending a mod
.
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'm not sure either. It might be worth looking at other bigger and more established crates (e.g. clippy) to see if they have any tricks that might help here as well.
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 solved this somehow in d94cc7b.
If you like this solution, please resolve the conversation.
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.
Looks good! One question for you to consider, and otherwise I think this is fine to merge.
Oh, it might be a good idea to update CONTRIBUTING.md
as well, since I think some of its instructions will be outdated after this PR merges.
Ups, I didn't know about the existence of this file. My recent PR already made some changes that made this markdown file not up-to-date. I'll create a PR to solve that. |
If you can resolve the merge conflict, this is good to go 🚀 |
Here you go: 345ea94 |
This PR removes a duplicated list of lints in the source code of the project.
Previously, there was a list of paths to lints in
src/query.rs:SemverQuery:all_queries()
and a list of lint names insrc/query.rs:tests:query_execution_tests!()
. This PR replaces thequery_execution_tests
macro with a macroadd_lints
to generate the tests (just like the previous macro) and to generate a function that returns the list of queries' contents.The reasoning behind doing this change is that it will be a bit easier to add a new lint (and less room for a mistake). The ideal solution (in my opinion) would be to have a file listing all the lint names in the
src/lints/
directory and then have a macro that reads the file and generates the tests etc, but I don't know how to do it with my limited Rust knowledge.@obi1kenobi please comment whether you like the idea behind this PR and whether you have any ideas about how to do the above mentioned macro.