-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix(toml): deprecate hyphen lint names and error on duplicates #17051
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
Open
raushan728
wants to merge
4
commits into
rust-lang:master
Choose a base branch
from
raushan728:fix/lint-hyphen-deprecation-and-duplicate-detection
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−7
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
88a8dab
test(toml): add baseline tests for hyphenated and duplicate lint names
raushan728 38527bb
fix(toml): warn on hyphen lint names
raushan728 4bb4f1b
fix(toml): error on duplicate normalized lint names
raushan728 0f44606
refactor(toml): normalize lint names before passing to rustc flags
raushan728 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2690,7 +2690,23 @@ supported tools: {}", | |
| if tool == "cargo" && !gctx.cli_unstable().cargo_lints { | ||
| warn_for_cargo_lint_feature(gctx, warnings); | ||
| } | ||
| let mut seen_normalized: HashMap<String, String> = HashMap::new(); | ||
| for (name, config) in lints { | ||
| let normalized = name.replace('-', "_"); | ||
| if name.contains('-') { | ||
| warnings.push(format!( | ||
| "`lints.{tool}.{name}` is deprecated in favor of \ | ||
| `lints.{tool}.{normalized}` and will not work in a \ | ||
| future edition" | ||
| )); | ||
| } | ||
| if let Some(existing) = seen_normalized.get(&normalized) { | ||
| anyhow::bail!( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we generate an error or push an error? |
||
| "duplicate lint `{existing}` in `[lints.{tool}]`, \ | ||
| conflicts with `{name}`" | ||
| ); | ||
| } | ||
| seen_normalized.insert(normalized.clone(), name.to_string()); | ||
| if let Some((prefix, suffix)) = name.split_once("::") { | ||
| if tool == prefix { | ||
| anyhow::bail!( | ||
|
|
@@ -2772,10 +2788,11 @@ fn lints_to_rustflags(lints: &manifest::TomlLints) -> CargoResult<Vec<String>> { | |
| manifest::TomlLintLevel::Allow => "--allow", | ||
| }; | ||
|
|
||
| let normalized_name = name.replace('-', "_"); | ||
| let option = if tool == "rust" { | ||
| format!("{flag}={name}") | ||
| format!("{flag}={normalized_name}") | ||
| } else { | ||
| format!("{flag}={tool}::{name}") | ||
| format!("{flag}={tool}::{normalized_name}") | ||
| }; | ||
| ( | ||
| config.priority(), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a commit has "and" in it, it is a good sign it isn't atomic. This is a separate change.
This is also a breaking change. We either need to start as a future incompat warning or deprecate and error in the next edition.
View changes since the review
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially had edition-gated error for both but it broke existing crates on 2024 edition.Changed hyphen names to
warnings.pushonly. For duplicates, keptbail!should this follow the same pattern as hyphen nameswarnings.pushfor now, error in future edition?