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

One macro to include lints #204

Merged
merged 6 commits into from
Dec 10, 2022

Conversation

tonowak
Copy link
Collaborator

@tonowak tonowak commented Dec 3, 2022

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 in src/query.rs:tests:query_execution_tests!(). This PR replaces the query_execution_tests macro with a macro add_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.

@tonowak tonowak requested a review from obi1kenobi December 3, 2022 13:43
src/query.rs Outdated
Comment on lines 263 to 266
#[test]
fn $name() {
tests::check_query_execution(stringify!($name))
}
Copy link
Owner

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.

Copy link
Collaborator Author

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.

Copy link
Owner

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.

Copy link
Collaborator Author

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.

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 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.

src/query.rs Outdated Show resolved Hide resolved
@tonowak
Copy link
Collaborator Author

tonowak commented Dec 9, 2022

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.

@obi1kenobi
Copy link
Owner

If you can resolve the merge conflict, this is good to go 🚀

@tonowak
Copy link
Collaborator Author

tonowak commented Dec 9, 2022

Here you go: 345ea94
I tried to make the changes so that a merge conflict wouldn't happen, but I failed, sorry.

CONTRIBUTING.md Outdated Show resolved Hide resolved
@obi1kenobi obi1kenobi enabled auto-merge (squash) December 10, 2022 05:27
@obi1kenobi obi1kenobi merged commit 1bdbdc7 into obi1kenobi:main Dec 10, 2022
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