EmbarkStudios / rust-ecosystem

Rust wants & tracking for Embark 🦀
http://embark.rs
Apache License 2.0
886 stars 18 forks source link

Embark's standard lints #59

Open repi opened 3 years ago

repi commented 3 years ago

Background

This issue tracks which Rust and Clippy lints we currently use as default for all of our internal and external crates. We have a common base of lints that we configure the same everywhere that is more opinionated than the Rust and Clippy defaults and geared towards how we prefer to (currently) write & maintain Rust code.

Individual crates are able to, and often do override some of these defaults, either on a crate level, or for specific modules or functions. But we still find it helpful to have a standard across everything to keep the code high quality and generally working the same way.

Lint configuration

We currently have two ways to enable our configured lints:

  1. Through copy'n'pasting https://github.com/EmbarkStudios/rust-ecosystem/blob/main/lints.rs into every crate
  2. Through a .cargo/config.toml section: https://github.com/EmbarkStudios/rust-ecosystem/blob/main/lints.toml

Traditionally we've used option 1, but are testing and converting more to option 2 as it is much easier to just have a single configuration file with everything.

We hope to later in 2021 have proper first-class support for a lints.toml or [lints] section in Cargo and switch to that, but progress for it has been slow. Tracked in:

Lints of interests

Testing / being discussed

Blocked

List of Clippy lints we are interested in using, but that have issues or are not mature / specific enough yet for inclusion.

repi commented 3 years ago

Filed https://github.com/EmbarkStudios/opensource/issues/35 to start using the template in all of our current open source repos

repi commented 3 years ago

60 is a PR draft and discussion about potential additions and removals for v0.3

repi commented 3 years ago

We have a v0.3 of the lints now also that adds the following ones that we've verified across multiple of our codebases 🎉

repi commented 3 years ago

We've released v0.4 with significant amount of smaller pedantic lints added, and a couple removals. Details in PR #66

Jake-Shadle commented 2 years ago

I think we should remove disallowed_type(s) and disallowed_method(s) from the lint list, these lints only apply if they are actually configured for the repo, which a majority don't do, and it's also complicated because they were renamed in 1.59.0 to be plural, which means updating the list could make running clippy on older versions fail and require an update to all users of the lints since the renamed lints are now a warning.

MarijnS95 commented 2 years ago

@Jake-Shadle There was a similar Rust 1.55+ requirement for v5, seems like we can do the same for a v6 release?

In any case, I fixed these in https://github.com/EmbarkStudios/rust-ecosystem/pull/73, we at traverse are actively using this setup. Looking at it again I'll remove them in that PR, as they're already warn-by-default and thus provide no extra benefit being configured explicit (if they weren't, clippy.toml config would be a useless no-op...).

Jake-Shadle commented 2 years ago

Yes, since they are warn by default I don't think it makes sense to keep them in the list at all, technically it's a breaking change to keep them in the list due to the clippy change, but it will be fine to do that in a 0.6 version, I just wanted to post here for when that does happen because I'm in the process of removing them from all of the crates I maintain.

repi commented 2 years ago

Oh they are warn-by-default now, that's great and yes then we shall simply remove them. Will do a v6 release now soon requires 1.59 with them removed. And follow up with another release soon with new additional lints that we've been using and testing.

repi commented 2 years ago

Released v6 now with the renamed warn-by-default lints removed. (#74)

MarijnS95 commented 2 years ago

Well, guess I am too late to update that PR :grimacing:

Any other lints in the list that are now default-warn?

With additional lints pending, shall we submit some of ours again too (after deduplicating with what Embark has been testing with)? We've been finding some interesting new flags as well.

repi commented 2 years ago

@MarijnS95 just wanted to get out v6 quickly to unblock Rust 1.59 clippy compile errors.

created #75 to discuss v7 additions and removals and good idea also to go through and see if there are more warn-by-default lints we can remove. and great if you have any other lints that you've been testing with and that works well, so let's discuss in that!

epage commented 1 year ago

I've created an RFC for package-level lint configuration: https://github.com/rust-lang/rfcs/pull/3389

epage commented 1 year ago

I feel like the above RFC has shaped up quite well. As Embark has a large lint configuration that gets copied from project to project, I'm curious how well you feel the current design works out from the "large user" perspective.

In particular

(I think that covered all the more controversial items)

epage commented 1 year ago

@repi there is one particular point the cargo team is hoping Embark can spare some time to provide feedback on regarding your experience with your lints lists.

Problem: RUSTFLAGS has baked in an ordering so users can have lints override groups. We are exploring how to support this within the [lints] table. A particularly challenging point is that there are no guarantees today around lint groups, e.g. two rustc lint groups intersect which makes it so we can't perfectly order lint groups on the users behalf.

We are particularly concerned about the experience managing large lists of lints, not just that some experts can maintain it but with an eye of empathy towards what problems other users may have.

In a recent post, I've laid out the options we are considering. "large lists of lints" came up in two parts of the conversation within the cargo team