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

Metadata collection monster searching for Clippy's configuration options #7214

Merged
merged 5 commits into from
May 16, 2021

Conversation

xFrednet
Copy link
Member

@xFrednet xFrednet commented May 12, 2021

This PR teaches our lovely metadata collection monster which configurations are available inside Clippy. It then adds a new Configuration section to the lint documentation.


The implementation uses the define_Conf! macro to create a vector of metadata during compilation. This enables easy collection and parsing without the need of searching for the struct during a lint-pass (and it's quite elegant IMO). The information is then parsed into an intermediate struct called ClippyConfiguration which will be saved inside the MetadataCollector struct itself. It is currently only used to generate the Configuration section in the lint documentation, but I'm thinking about adding an overview of available configurations to the website. Saving them in this intermediate state without formatting them right away enables this in the future.

The new parsing will also allow us to have a documentation that spans over multiple lines in the future. For example, this will be valid when the old script has been removed:

/// Lint: BLACKLISTED_NAME.
/// The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
(blacklisted_names: Vec<String> = ["foo", "baz", "quux"].iter().map(ToString::to_string).collect())

The deprecation reason is also currently being collected but not used any further and that's basically it.


See: #7172 for the full metadata collection to-do list or to suggest a new feature in connection to it 🙃


changelog: none

r? @flip1995
cc @camsteffen It would be great if you could also review this PR as you have recently worked on Clippy's define_Conf! macro.

Copy link
Contributor

@camsteffen camsteffen left a comment

Choose a reason for hiding this comment

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

Just some ignorable comments.

@xFrednet xFrednet force-pushed the 7197-collecting-configuration branch 2 times, most recently from 8948ed9 to f810c11 Compare May 15, 2021 17:09
@xFrednet
Copy link
Member Author

I've addressed @camsteffen's suggestions which were excellent! I'm happy with this version, but I was sadly unable to fully test it with my current setup. I'll be able to do so on Thursday. However, I strongly believe that this works and can therefor at least be reviewed if not merged :)

bors added a commit that referenced this pull request May 16, 2021
…r=flip1995

Add `cargo collect-metadata` as an cargo alias for the metadata collection lint

This PR adds a new alias to run the metadata collection monster on `clippy_lints`. I'm currently using it to create the `metadata_collection.json` file and I plan to use it in the `deply.sh` script. Having it as a new alias enables us to simply use:

```sh
cargo collect-metadata
```

It sometimes requires running `cargo clean` before collecting the metadata due to caching. I'm still debating if I should include a cargo clean as part of the `run_metadata_collection_lint` test or not. Input on this would be greatly appreciated 🙃

That's it, just a small change that can be reviewed and merged in parallel to #7214.

---

See: #7172 for the full metadata collection to-do list or to suggest a new feature in connection to it.

---

changelog: none

r? `@flip1995` btw. feel free to pass these PRs one to other team members as well if you want.
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

The new parsing will also allow us to have a documentation that spans over multiple lines in the future. For example, this will be valid when the old script has been removed:

That would be really neat, but I think the macro definition would have to be changed to allow multi-lint doc comments:

error: no rules expected the token `doc`
   --> clippy_lints/src/utils/conf.rs:126:5
    |
27  | macro_rules! define_Conf {
    | ------------------------ when calling this macro
...
126 |     /// FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no rules expected this token in macro call

LGTM. Works great for me locally. Just a NIT.

}

impl MetadataCollector {
pub fn new() -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this trigger our new_without_default lint?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the first time that I've heard of that lint... so, I guess not 🤔. Unless it got merged after this branch was crated from master. I would also expect it not to trigger as new() does more than just assign default values but that might be just my opinion 🙃 .

It didn't trigger during testing. We'll see if bors complains about it 🙃

@flip1995
Copy link
Member

However, I strongly believe that this works and can therefor at least be reviewed if not merged

I'm good with merging this. Feel free to approve this with r=flip1995, if you're also happy with this PR @xFrednet

@bors delegate+

@bors
Copy link
Contributor

bors commented May 16, 2021

✌️ @xFrednet can now approve this pull request

@xFrednet
Copy link
Member Author

The new parsing will also allow us to have a documentation that spans over multiple lines in the future. For example, this will be valid when the old script has been removed:

That would be really neat, but I think the macro definition would have to be changed to allow multi-lint doc comments:

That's true and done on purpose for now. The change is pretty simple but it would not be supported by our current python script. I therefore decided to leave the macro definition to be restrictive until we fully switched over. The parsing itself is already setup for it :)

I'm happy with merging this, and it also brings us one step closer to switching over. Thank you for the fast reviews on these PRs! @flip1995

@bors r=flip1995,camsteffen

The bors syntax should be correct this time to add you as a reviewer, I've also added @camsteffen as he reviewed it as well 🙃

@bors
Copy link
Contributor

bors commented May 16, 2021

📌 Commit f810c11 has been approved by flip1995,camsteffen

@bors
Copy link
Contributor

bors commented May 16, 2021

⌛ Testing commit f810c11 with merge 48dad26...

@bors
Copy link
Contributor

bors commented May 16, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995,camsteffen
Pushing 48dad26 to master...

@bors bors merged commit 48dad26 into rust-lang:master May 16, 2021
@xFrednet xFrednet deleted the 7197-collecting-configuration branch July 28, 2021 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants