Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport defining enabled and disabled lints in a configuration file #5034
Comments
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
This seems plausible to me! I think it'd be fine to add this to |
This comment has been minimized.
This comment has been minimized.
|
Do we have a chance for As Is this a thing? |
This comment has been minimized.
This comment has been minimized.
|
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. |
oli-obk
referenced this issue
Jul 6, 2018
Closed
Add a file allowing cross-crate configuration of lints #45832
This comment has been minimized.
This comment has been minimized.
rustc already reports whether something was
so we just add another variant for config file there. |
This comment has been minimized.
This comment has been minimized.
|
I'm really interested in this, too.
It could be |
petrochenkov
referenced this issue
Jul 10, 2018
Merged
Deny bare trait objects in src/bootstrap #52220
This comment has been minimized.
This comment has been minimized.
|
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) |
This comment has been minimized.
This comment has been minimized.
detrumi
commented
Jul 12, 2018
|
I'd like to start working on this, unless @phansch or @Rantanen started on this already. Seems like the
A |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
The argument against |
This comment has been minimized.
This comment has been minimized.
|
@detrumi I didn't start any work on this, and won't have that much time either. From my side, feel free to start |
This comment has been minimized.
This comment has been minimized.
|
@oli-obk Right, which is what workspaces are for IMO. I'd prefer to avoid "one more" file in every Rust directory. |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
Luthaf
commented
Jul 12, 2018
|
Why not use |
This comment has been minimized.
This comment has been minimized.
detrumi
commented
Jul 12, 2018
|
Alright, placing it in
Hierarchical |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Jul 13, 2018
•
|
@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? |
This comment has been minimized.
This comment has been minimized.
that part is no problem, you can configure lints in source code just fine. And if you have one enormous workspace, then the |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Jul 13, 2018
•
|
Suppose we settle on configuring this in |
ehuss
added
the
A-lints
label
Feb 21, 2019
This comment has been minimized.
This comment has been minimized.
marrub--
commented
Mar 2, 2019
|
Is this dead currently? For projects with a hierarchical structure and lots of lints this is a fairly vital feature. Hoping to see this gain activity soon! |
This comment has been minimized.
This comment has been minimized.
|
@marrub-- A more detailed proposal was posted at https://internals.rust-lang.org/t/proposal-cargo-lint-configuration/9135. |
This comment has been minimized.
This comment has been minimized.
|
I very much don't want to see this go into a separate configuration file. I've worked with C and similar for decades, where warning options live in the build system rather than in source code, and that leads to quite a bit of skew where source code doesn't have the information needed to build. I definitely think this information should not be in |
This comment has been minimized.
This comment has been minimized.
dbeckwith
commented
Mar 20, 2019
|
The main thing I'm hoping to avoid is the repetition of lints in every crate in a workspace. I don't much care about it being in a config file vs. source code as long as there's some way to inherit/include the list of lints from some source. |
This comment has been minimized.
This comment has been minimized.
|
Maybe we could come up with a scheme where you can import the lint configuration from another crate? So making it a language feature where you can define a crate that does nothing but set lint flags, and then you have another crate depend on it and import these flags into its own scope. |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Mar 21, 2019
|
@joshtriplett: I do not understand your argument. The proposal is not to remove static analysis configuration from Rust source files, but to also support setting this configuration in an external file. You mention being able to build from source alone, rather than source complemented with packaging metadata. Presently, Rust source code in the open source ecosystem of crates.io often cannot be built from source alone. The configuration in |
This comment has been minimized.
This comment has been minimized.
dbeckwith
commented
Mar 21, 2019
|
@sanmai-NL I think part of his argument was that some of those configuration files don't end up being published with the crate, especially if you're in a workspace. So having the lints live in a top-level |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Mar 21, 2019
|
@dbeckwith: But even if the configuration isn't being included in the source distribution via crates.io, builds won't fail because of it. Clippy does not break builds when run as standalone tool. In the past there was a compiler plugin, but I do not see documentation about it in the current README.md. Now suppose there is some possibility that Clippy is used within The use case for this feature request is of course within a context of Clippy being run separately, during a build pipeline (Continuous X). Also, |
This comment has been minimized.
This comment has been minimized.
dbeckwith
commented
Mar 21, 2019
|
@sanmai-NL What about |
This comment has been minimized.
This comment has been minimized.
sanmai-NL
commented
Mar 21, 2019
|
Suppose the scenario @joshtriplett tries to get at happens: the external config hasn't been distributed together with the source code.
So what @dbeckwith describes isn't a valid failure scenario. The only valid failure scenario I can think of is the following. There are There are, however, no default Now let's concede the following conditions: the maintainership of some software solution in Rust has enabled the I find this wildly far-fetched and at so many steps the maintainers and consumers would be going against best practices, that I find it hard to see @joshtriplett reservation as warranted. Not to mention, by making one or more simple design decisions we can defuse the scenario. As I wrote in my previous comment: Clippy could be designed to not accept out-of-source configuration under some conditions, for example when there is Clippy configuration within the source code already. |
This comment has been minimized.
This comment has been minimized.
|
On March 21, 2019 6:02:09 AM PDT, Sander Maijers ***@***.***> wrote:
@dbeckwith: But even if the configuration isn't being included in the
source distribution via crates.io, builds won't fail because of it.
Clippy does not break builds when run as standalone tool. In the past
there was a compiler plugin, but I do not see documentation about it in
the current
[README.md](https://github.com/rust-lang/rust-clippy/blob/c7d444508655eab132f0d24d81f9cdc08b848056/README.md).
Now suppose there is some possibility that Clippy is used within
`rustc`'s compilation pipeline and that the configuration to it is the
only way to unbreak this pipeline. Only then, for under those
conditions, Clippy could be designed to not accept out-of-source
configuration. That would solve the problem.
The use case for this feature request is of course within a context of
Clippy being run separately, during a build pipeline (Continuous X).
Also, [`clippy.toml` already
exists](https://github.com/rust-lang/rust-clippy/tree/c7d444508655eab132f0d24d81f9cdc08b848056#configuration)
as a configuration mechanism. So @joshtriplett's concern is not
specific to the proposal here.
Note that this isn't just about clippy, it's also about compiler lints.
|
This comment has been minimized.
This comment has been minimized.
|
To clarify something: I can live with lint configuration in the |
Rantanen commentedFeb 12, 2018
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/-Aflags 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 aredenyand someallowoutweighs 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. :<