-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Support defining enabled and disabled lints in a configuration file #5034
Comments
I am strongly in favor. We should also probably specify that unknown lints should be a warning, not an error, for the purposes of backwards compatibility. |
Forgot to mention: I'm also interested in contributing code for the implementation, if there is consensus on what should happen. Also do Cargo changes, such as this, go through the RFC process? |
This seems potentially worthy of an RFC, but I could see it going either way. There doesn't seem to be much design space. @alexcrichton can probably say more. |
This seems plausible to me! I think it'd be fine to add this to |
Do we have a chance for As Is this a thing? |
I'm not sure if these should be in the Cargo.toml, as we many want to be able to specify them globally for a group of projects. |
rustc already reports whether something was
so we just add another variant for config file there. |
I'm really interested in this, too.
It could be |
This Rollup PR from rust demonstrates how rust itself could benefit from a shared lint config, too: rust-lang/rust#52268 (note all the 'deny bare trait object' PRs; and there's a few more) |
I'd like to start working on this, unless @phansch or @Rantanen started on this already. Seems like the
A |
I'd prefer that we centralize this into Cargo.toml rather than adding an additional file, but that can likely be decided in further detail at a later point in time. |
The argument against |
@detrumi I didn't start any work on this, and won't have that much time either. From my side, feel free to start 👍 |
@oli-obk Right, which is what workspaces are for IMO. I'd prefer to avoid "one more" file in every Rust directory. |
That would mean that companies need one enormous workspace for all the crates in their company if they want to have a consistent lint setup. This is the very use case that started the discussion about lint configuration files. A company-wide uniform linting experience. Maybe specializeable for crates, but they can already do that via |
Why not use |
Alright, placing it in
Hierarchical |
@oli-obk, @Mark-Simulacrum: My company has one enormous workspace indeed. And we are highly in need of DRY linting/warnings/etc. configuration with local exceptions (preferably down to the statement-level). So if industrial use cases/productivity are the motivation, perhaps we can survey a bit to come up with requirements in a more deliberate process? |
that part is no problem, you can configure lints in source code just fine. And if you have one enormous workspace, then the |
Suppose we settle on configuring this in |
I started writing up a RFC with the MVP @joshtriplett suggests. I never got to finishing it due to limited time. I plan to work on this in the near future though. However, I'm aware about the feature freeze of |
if If that is the case I think # [PROJECT_DIR]/Cargo.toml
[workspace.lints]
allow = [ "allow_unused", "non_snake_case" ] # [PROGJCT_DIR]/bar/Cargo.toml
[lints]
workspace = true
deny = [ "allow_unused" ] I would have to think more about how it would fit with |
cargo cranky (https://github.com/ericseppanen/cargo-cranky) is a new tool that passes lints specified in a Cranky.toml to cargo clippy. This is a possible solution to rust-lang/cargo#5034
* Use cargo cranky instead of cargo clippy cargo cranky (https://github.com/ericseppanen/cargo-cranky) is a new tool that passes lints specified in a Cranky.toml to cargo clippy. This is a possible solution to rust-lang/cargo#5034 * Remove `-W clippy::all` from `check.sh` (rely on `Cranky.toml` instead)
cargo cranky (https://github.com/ericseppanen/cargo-cranky) is a new tool that passes lints specified in a Cranky.toml to cargo clippy. This is a possible solution to rust-lang/cargo#5034
* Use cargo cranky cargo cranky (https://github.com/ericseppanen/cargo-cranky) is a new tool that passes lints specified in a Cranky.toml to cargo clippy. This is a possible solution to rust-lang/cargo#5034 * Use pinned version of wasm-bindgen-cli * Add bacon.toml for https://github.com/Canop/bacon
I don't know if this has been brought up before, but what about something a little more general like Python's |
Hey @flip1995, you mentioned you started on an RFC? I'd be more than happy to help, or pickup the work if you've become too busy? |
Yes, I started one some time ago, but can't find it anymore. 🤦 There is this attempt at an RFC: https://hackmd.io/@flip1995/HJteAAPgO But it is really sparse and not at a point where I would continue with it, but rather start fresh. |
For anyone looking for a workaround for this issue, I have been using |
I'm also wondering if at this point clippy should just support it in clippy.toml. We can then do fancy stuff like "disable lints that were introduced in version foo" (or "enable all lints up to version foo"). Ideally this can be done with an additional state for Rust's lint emission UI where it mentions that the lint level comes from a file instead. |
I've created an RFC for this: rust-lang/rfcs#3389 |
Since #12115 is merged, I'm closing this as resolved. |
This issue started its life in clippy (rust-lang/rust-clippy#1313). Once it was realized this should apply to built-in lints as well, it migrated to rust (rust-lang/rust#45832). There @kennytm suggested that it should be Cargo's responsibility to pass the
-D
/-W
/-A
flags to rustc.Motivation
Currently project-wide lint configuration needs to be included in the crate sources. This is okay when the project consists of a single crate, but gets more cumbersome when the project is a workspace with dozen crates.
Being able to define the lints in an external file that will be used when building the crates would have several benefits:
Proposal
lints.toml
(or[lints]
inCargo.toml
?) file that specifies the lints.Also... unlike what @oli-obk suggested in the rust issue, personally I'd prefer the following format:
While this is more verbose than
allow = [ "allow_unused", "non_snake_case" ]
, I think the diff benefits and the ability for the user to group logically similar lints together even if some of them aredeny
and someallow
outweighs the increased verbosity.Also if Cargo/rustc ever support lint configurations, this would be more future proof:
Example configuration
The feature syntax is lifted from Cargo's dependency syntax - at least that was the intention. Personally I'm not a fan of it, but I guess that's a limitation of toml. Don't really have a better proposal for it, given I don't really know what's available int he toml syntax. :<
The text was updated successfully, but these errors were encountered: